{"record":{"id":"715c50e75b1e3802","repo":"ATH-MaaS/Pixelle-Video","slug":"prompt-count-mismatch-expected-len-batch-narrati","errorCode":null,"errorMessage":"Prompt count mismatch: expected {len(batch_narrations)}, got {len(batch_prompts)}","messagePattern":"Prompt count mismatch: expected (.+?), got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pixelle_video/utils/content_generators.py","lineNumber":438,"sourceCode":"                response = await llm_service(\n                    prompt=prompt,\n                    temperature=0.7,\n                    max_tokens=8192\n                )\n                \n                logger.debug(f\"Batch {batch_idx} attempt {attempt}: LLM response length: {len(response)} chars\")\n                \n                # Parse JSON\n                result = _parse_json(response)\n                \n                if \"video_prompts\" not in result:\n                    raise KeyError(\"Invalid response format: missing 'video_prompts'\")\n                \n                batch_prompts = result[\"video_prompts\"]\n                \n                # Validate batch result\n                if len(batch_prompts) != len(batch_narrations):\n                    raise ValueError(\n                        f\"Prompt count mismatch: expected {len(batch_narrations)}, got {len(batch_prompts)}\"\n                    )\n                \n                # Success - add to all_prompts\n                all_prompts.extend(batch_prompts)\n                logger.info(f\"✓ Batch {batch_idx} completed: {len(batch_prompts)} video prompts\")\n                \n                # Report progress\n                if progress_callback:\n                    completed = len(all_prompts)\n                    total = len(narrations)\n                    progress_callback(completed, total, f\"Batch {batch_idx}/{len(batches)} completed\")\n                \n                break  # Success, move to next batch\n            \n            except Exception as e:\n                logger.warning(f\"✗ Batch {batch_idx} attempt {attempt} failed: {e}\")\n                if attempt >= max_retries:","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/ATH-MaaS/Pixelle-Video/blob/848b054e4fae40dabc62ec58e960b573e83793ac/pixelle_video/utils/content_generators.py#L420-L456","documentation":"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.","triggerScenarios":"Any generate_video_prompts invocation where len(result['video_prompts']) != len(batch_narrations) for a batch — model omits entries, merges scenes, or adds extras.","commonSituations":"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.","solutions":["Shrink batch size so the model reliably emits one prompt per narration.","Add retry logic (wrap the batch call like generate_image_prompts does) to regenerate mismatched batches.","Make the prompt state the exact expected count explicitly before the narrations.","Truncate/pad the array to len(batch_narrations) instead of raising, if approximate output is acceptable.","Use schema-constrained output with minItems/maxItems equal to the batch size."],"exampleFix":"// before\nif len(batch_prompts) != len(batch_narrations):\n    raise ValueError(f\"Prompt count mismatch: expected {len(batch_narrations)}, got {len(batch_prompts)}\")\n// after\nif len(batch_prompts) > len(batch_narrations):\n    batch_prompts = batch_prompts[:len(batch_narrations)]\nelif len(batch_prompts) < len(batch_narrations):\n    batch_prompts += [batch_prompts[-1]] * (len(batch_narrations) - len(batch_prompts))","handlingStrategy":"validation","validationCode":"def validate_video_batch(result: dict, narrations: list) -> bool:\n    prompts = result.get(\"video_prompts\") if isinstance(result, dict) else None\n    return isinstance(prompts, list) and len(prompts) == len(narrations)","typeGuard":"def is_valid_video_batch(obj: object, expected: int) -> bool:\n    return (isinstance(obj, dict) and isinstance(obj.get(\"video_prompts\"), list)\n            and len(obj[\"video_prompts\"]) == expected)","tryCatchPattern":"try:\n    prompts = generator.generate_video_prompts(narrations)\nexcept ValueError as e:\n    if \"count mismatch\" in str(e):\n        for size in (4, 2, 1):  # shrink batch until model complies\n            prompts = generator.generate_video_prompts(narrations, batch_size=size)\n            break\n    else:\n        raise","preventionTips":["Pass small batches so count alignment is trivial for the model","Explicitly number narrations in the prompt and require one prompt per number","Set max_tokens high enough that the JSON array is never truncated","Validate counts per batch immediately and regenerate only the failing batch"],"tags":["llm","validation","count-mismatch"],"backgroundTag":"llm-output-count-mismatch","analyzedSha":"848b054e4fae40dabc62ec58e960b573e83793ac","analyzedAt":"2026-08-30T03:24:41.468Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}