ATH-MaaS/Pixelle-Video · error · ValueError

Prompt count mismatch: expected {len(batch_narrations)}, got

Error message

Prompt count mismatch: expected {len(batch_narrations)}, got {len(batch_prompts)}

What it means

generate_video_prompts checks each batch so the number of returned video prompts equals the number of narrations; on mismatch it raises ValueError with expected and got counts. There is no retry-with-continue path here (unlike the image generator), so the first count mismatch aborts the call.

Source

Thrown at pixelle_video/utils/content_generators.py:438

                response = await llm_service(
                    prompt=prompt,
                    temperature=0.7,
                    max_tokens=8192
                )
                
                logger.debug(f"Batch {batch_idx} attempt {attempt}: LLM response length: {len(response)} chars")
                
                # Parse JSON
                result = _parse_json(response)
                
                if "video_prompts" not in result:
                    raise KeyError("Invalid response format: missing 'video_prompts'")
                
                batch_prompts = result["video_prompts"]
                
                # Validate batch result
                if len(batch_prompts) != len(batch_narrations):
                    raise ValueError(
                        f"Prompt count mismatch: expected {len(batch_narrations)}, got {len(batch_prompts)}"
                    )
                
                # Success - add to all_prompts
                all_prompts.extend(batch_prompts)
                logger.info(f"✓ Batch {batch_idx} completed: {len(batch_prompts)} video prompts")
                
                # Report progress
                if progress_callback:
                    completed = len(all_prompts)
                    total = len(narrations)
                    progress_callback(completed, total, f"Batch {batch_idx}/{len(batches)} completed")
                
                break  # Success, move to next batch
            
            except Exception as e:
                logger.warning(f"✗ Batch {batch_idx} attempt {attempt} failed: {e}")
                if attempt >= max_retries:

View on GitHub (pinned to 848b054e4f)

Solutions

  1. Shrink batch size so the model reliably emits one prompt per narration.
  2. Add retry logic (wrap the batch call like generate_image_prompts does) to regenerate mismatched batches.
  3. Make the prompt state the exact expected count explicitly before the narrations.
  4. Truncate/pad the array to len(batch_narrations) instead of raising, if approximate output is acceptable.
  5. Use schema-constrained output with minItems/maxItems equal to the batch size.

Example fix

// before
if len(batch_prompts) != len(batch_narrations):
    raise ValueError(f"Prompt count mismatch: expected {len(batch_narrations)}, got {len(batch_prompts)}")
// after
if len(batch_prompts) > len(batch_narrations):
    batch_prompts = batch_prompts[:len(batch_narrations)]
elif len(batch_prompts) < len(batch_narrations):
    batch_prompts += [batch_prompts[-1]] * (len(batch_narrations) - len(batch_prompts))
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

try:
    prompts = generator.generate_video_prompts(narrations)
except ValueError as e:
    if "count mismatch" in str(e):
        for size in (4, 2, 1):  # shrink batch until model complies
            prompts = generator.generate_video_prompts(narrations, batch_size=size)
            break
    else:
        raise

Prevention

When it happens

Trigger: Any generate_video_prompts invocation where len(result['video_prompts']) != len(batch_narrations) for a batch — model omits entries, merges scenes, or adds extras.

Common situations: Large batches exceeding model reliability; narration text containing scene breaks the model splits; JSON arrays truncated by max-token limits; few-shot examples in the prompt showing a different count.

Related errors


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