ATH-MaaS/Pixelle-Video · error · ValueError

Expected {n_scenes} narrations, got only {len(narrations)}

Error message

Expected {n_scenes} narrations, got only {len(narrations)}

What it means

generate_narrations_from_topic validates narration count against n_scenes: extra narrations are truncated with a warning, but fewer than requested raises ValueError. One narration per scene is required downstream, so a short LLM response is treated as a hard failure rather than silently padded.

Source

Thrown at pixelle_video/utils/content_generators.py:147

        max_tokens=2000
    )
    
    logger.debug(f"LLM response: {response[:200]}...")
    
    # Parse JSON
    result = _parse_json(response)
    
    if "narrations" not in result:
        raise ValueError("Invalid response format: missing 'narrations' key")
    
    narrations = result["narrations"]
    
    # Validate count
    if len(narrations) > n_scenes:
        logger.warning(f"Got {len(narrations)} narrations, taking first {n_scenes}")
        narrations = narrations[:n_scenes]
    elif len(narrations) < n_scenes:
        raise ValueError(f"Expected {n_scenes} narrations, got only {len(narrations)}")
    
    logger.info(f"Generated {len(narrations)} narrations successfully")
    return narrations


async def generate_narrations_from_content(
    llm_service,
    content: str,
    n_scenes: int = 5,
    min_words: int = 5,
    max_words: int = 20
) -> List[str]:
    """
    Generate narrations from user-provided content using LLM
    
    Args:
        llm_service: LLM service instance
        content: User-provided content

View on GitHub (pinned to 848b054e4f)

Solutions

  1. Retry the generation — LLM undercounting is often transient
  2. Increase the model's max output tokens so all n_scenes items fit
  3. Reduce n_scenes or split generation into batches of scenes
  4. Add an explicit instruction: 'return exactly N narrations, one per scene'

Example fix

// before
desc = await generate_narration(topic, n_scenes=30)  # model returns 12
// after
desc = await generate_narration(topic, n_scenes=30, max_tokens=4096)  # or batch in chunks of 10
Defensive patterns

Strategy: retry

Validate before calling

def narrations_complete(result, n_scenes: int) -> bool:
    return isinstance(result, dict) and len(result.get('narrations', [])) >= n_scenes

Try / catch

for attempt in range(3):
    try:
        return await generate_narrations_from_topic(topic, n_scenes=n)
    except ValueError as e:
        if 'got only' in str(e) and attempt < 2:
            continue
        raise

Prevention

When it happens

Trigger: The LLM returns a valid {"narrations": [...]} array with len < n_scenes — the model merged scenes, stopped early, or hit a max-token limit mid-generation.

Common situations: High scene counts (long videos) exceeding the model's output token budget; the model combining adjacent scenes into one narration; responses truncated by API max_tokens settings.

Related errors


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