{"record":{"id":"52c650353eb5588e","repo":"ATH-MaaS/Pixelle-Video","slug":"invalid-response-format-missing-video-prompts","errorCode":null,"errorMessage":"Invalid response format: missing 'video_prompts'","messagePattern":"Invalid response format: missing 'video_prompts'","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"pixelle_video/utils/content_generators.py","lineNumber":432,"sourceCode":"                prompt = build_video_prompt_prompt(\n                    narrations=batch_narrations,\n                    min_words=min_words,\n                    max_words=max_words\n                )\n                \n                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\")","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/ATH-MaaS/Pixelle-Video/blob/848b054e4fae40dabc62ec58e960b573e83793ac/pixelle_video/utils/content_generators.py#L414-L450","documentation":"generate_video_prompts expects the LLM to answer each batch with JSON containing a 'video_prompts' key. If the parsed JSON lacks that key, a KeyError('Invalid response format: missing 'video_prompts'') is raised. Unlike the image variant it is raised immediately per attempt (no graceful count-retry messaging), so the exception surfaces whenever the model ignores the required schema.","triggerScenarios":"Calling generate_video_prompts where _parse_json(response) yields a dict without 'video_prompts' — model returns prompts under another key, returns prose, or returns a top-level array.","commonSituations":"Model producing motion-caption-style text instead of JSON; schema instructions lost when customizing the prompt; provider switching to a model that resists JSON formatting; responses truncated so JSON parsed to an empty/partial object.","solutions":["Retry the batch generation — model nondeterminism often produces valid JSON on a later attempt.","Log/inspect the raw response and tighten the prompt to require the exact key \"video_prompts\".","Enable provider JSON mode or a response schema forcing the key.","Accept a top-level array as fallback before raising.","Use a stronger model for video prompt generation."],"exampleFix":"// before\nresult = _parse_json(response)\nif \"video_prompts\" not in result:\n    raise KeyError(\"Invalid response format: missing 'video_prompts'\")\n// after\nresult = _parse_json(response)\nif \"video_prompts\" not in result:\n    if isinstance(result, list):\n        result = {\"video_prompts\": result}\n    else:\n        raise KeyError(\"Invalid response format: missing 'video_prompts'\")","handlingStrategy":"validation","validationCode":"def looks_like_video_prompt_response(payload) -> bool:\n    return isinstance(payload, dict) and isinstance(payload.get(\"video_prompts\"), list) and len(payload[\"video_prompts\"]) > 0","typeGuard":"def has_video_prompts(obj: object) -> bool:\n    return isinstance(obj, dict) and isinstance(obj.get(\"video_prompts\"), list) and all(isinstance(p, str) for p in obj[\"video_prompts\"])","tryCatchPattern":"try:\n    prompts = generator.generate_video_prompts(narrations)\nexcept KeyError as e:\n    if \"video_prompts\" in str(e):\n        logger.warning(\"LLM returned unexpected shape; retrying\")\n        prompts = generator.generate_video_prompts(narrations)\n    else:\n        raise","preventionTips":["Enable JSON/structured output mode on the LLM client","Include a literal output example with the \"video_prompts\" key in the prompt","Retry failed batches automatically","Pin to a model version that reliably follows JSON instructions"],"tags":["llm","json-parsing","schema-validation"],"backgroundTag":"llm-response-schema-mismatch","analyzedSha":"848b054e4fae40dabc62ec58e960b573e83793ac","analyzedAt":"2026-08-30T03:24:41.468Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}