ATH-MaaS/Pixelle-Video · error · ValueError

Batch prompt count mismatch (attempt / ): Expected: prompts…

Error message

Batch {batch_idx} prompt count mismatch (attempt {attempt}/{max_retries}):
  Expected: {len(batch_narrations)} prompts
  Got: {len(batch_prompts)} prompts

What it means

After parsing the LLM response, generate_image_prompts validates that the 'image_prompts' array has exactly as many entries as the batch's narrations. On mismatch it warns and retries; once max_retries is exhausted it raises ValueError with expected vs got counts. It means the model returned too few or too many image prompts for the batch.

Solutions

  1. Reduce the batch size (fewer narrations per LLM call) so counts stay aligned.
  2. Raise max_retries to give the corrective retry loop more attempts.
  3. Strengthen the prompt: instruct one prompt per narration, in order, matching the count exactly.
  4. Post-process defensively: pad by splitting prompts or truncate to len(batch_narrations) instead of failing.
  5. Use structured/JSON-mode output which enforces array length via a schema.

Example fix

// before
raise ValueError(error_msg)
// after
if len(batch_prompts) > len(batch_narrations):
    batch_prompts = batch_prompts[:len(batch_narrations)]  # tolerate extra prompts
else:
    raise ValueError(error_msg)
Defensive patterns

Strategy: retry

Validate before calling

def batch_counts_match(result: dict, narrations: list) -> bool:
    prompts = result.get("image_prompts") if isinstance(result, dict) else None
    return isinstance(prompts, list) and len(prompts) == len(narrations)

Type guard

def is_valid_prompt_batch(obj: object, expected: int) -> bool:
    return (isinstance(obj, dict) and isinstance(obj.get("image_prompts"), list)
            and len(obj["image_prompts"]) == expected)

Try / catch

try:
    prompts = generator.generate_image_prompts(narrations)
except ValueError as e:
    if "prompt count mismatch" in str(e):
        prompts = generator.generate_image_prompts(narrations, max_retries=max_retries + 2)
    else:
        raise

Prevention

When it happens

Trigger: generate_image_prompts called (directly, via generate_image_prompt, __call__, or plan_visuals) where for every retry attempt len(result['image_prompts']) != len(batch_narrations), e.g. model merges or skips narrations, or the batch is too large for the model to enumerate faithfully.

Common situations: Long narration lists per batch; model summarizing multiple scenes into one prompt; off-by-one when the model numbers items but drops one; low-context models truncating long JSON arrays.

Related errors


AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30). Data as JSON: /api/errors/d6f8645052ea2093. Report an issue: GitHub.

Appendix: source

Thrown at pixelle_video/utils/content_generators.py:346

                if "image_prompts" not in result:
                    raise KeyError("Invalid response format: missing 'image_prompts'")
                
                batch_prompts = result["image_prompts"]
                
                # Validate count
                if len(batch_prompts) != len(batch_narrations):
                    error_msg = (
                        f"Batch {batch_idx} prompt count mismatch (attempt {attempt}/{max_retries}):\n"
                        f"  Expected: {len(batch_narrations)} prompts\n"
                        f"  Got: {len(batch_prompts)} prompts"
                    )
                    logger.warning(error_msg)
                    
                    if attempt < max_retries:
                        logger.info(f"Retrying batch {batch_idx}...")
                        continue
                    else:
                        raise ValueError(error_msg)
                
                # Success!
                logger.info(f"✅ Batch {batch_idx} completed successfully ({len(batch_prompts)} prompts)")
                all_prompts.extend(batch_prompts)
                
                # Report progress
                if progress_callback:
                    progress_callback(
                        len(all_prompts),
                        len(narrations),
                        f"Batch {batch_idx}/{len(batches)} completed"
                    )
                
                break
                
            except json.JSONDecodeError as e:
                logger.error(f"Batch {batch_idx} JSON parse error (attempt {attempt}/{max_retries}): {e}")
                if attempt >= max_retries:

View on GitHub (pinned to 848b054e4f)