ATH-MaaS/Pixelle-Video · error · KeyError
Invalid response format: missing 'image_prompts'
Error message
Invalid response format: missing 'image_prompts'
What it means
generate_image_prompts batches narrations and asks an LLM to return JSON containing an 'image_prompts' key. When the parsed LLM response lacks that key, a KeyError('Invalid response format: missing 'image_prompts'') is raised so the retry loop can regenerate the batch. It indicates the model deviated from the required JSON schema or the JSON parse produced an object without the field.
Solutions
- Retry the call — generate_image_prompts already loops max_retries times; transient model drift usually resolves on retry.
- Inspect the raw LLM response (logged at debug level) to see the actual JSON shape and adjust the prompt to explicitly demand {"image_prompts": [...]}.
- Reduce batch size so the model reliably emits one prompt per narration.
- Switch to a model/provider that follows structured output or use JSON-mode/forced-schema output.
- Patch _parse_json/callers to accept alternative key names or a top-level array.
Example fix
// before
result = _parse_json(response)
if "image_prompts" not in result:
raise KeyError("Invalid response format: missing 'image_prompts'")
// after
result = _parse_json(response)
if "image_prompts" not in result:
if isinstance(result, list): # model returned a bare array
result = {"image_prompts": result}
else:
raise KeyError("Invalid response format: missing 'image_prompts'") Defensive patterns
Strategy: validation
Validate before calling
def looks_like_image_prompt_response(payload) -> bool:
return isinstance(payload, dict) and isinstance(payload.get("image_prompts"), list) and len(payload["image_prompts"]) > 0
# call after _parse_json, before consuming result Type guard
def has_image_prompts(obj: object) -> bool:
return isinstance(obj, dict) and isinstance(obj.get("image_prompts"), list) and all(isinstance(p, str) for p in obj["image_prompts"]) Try / catch
try:
prompts = generator.generate_image_prompt(narrations)
except KeyError as e:
if "image_prompts" in str(e):
logger.warning("LLM ignored schema, retrying with smaller batch")
prompts = generator.generate_image_prompt(narrations[: len(narrations) // 2])
else:
raise Prevention
- Use a provider JSON mode / response schema when available
- Keep batches small so the model reliably follows the schema
- Log raw LLM responses at debug level for post-mortems
- Prefer models known for structured-output compliance
When it happens
Trigger: The LLM returns valid JSON but without an 'image_prompts' array — e.g. the model wrapped output in prose, returned prompts under a different key, returned a bare array, or a retry consumed a malformed response after _parse_json salvaged a partial object.
Common situations: Weaker/cheaper LLM models ignoring the JSON schema instruction; prompts asking for many narrations in one batch causing truncated or restructured output; model updates changing output shape; custom system prompts overriding the format instructions.
Related errors
- Invalid response format: missing 'narrations' key
- Invalid response format: missing 'video_prompts'
- Failed to parse LLM response as
- Batch prompt count mismatch (attempt / ): Expected: prompts…
- DashScope failed after attempts due to network error
AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30).
Data as JSON: /api/errors/649f72ed5b223a29.
Report an issue: GitHub.
Appendix: source
Thrown at pixelle_video/utils/content_generators.py:329
prompt = build_image_prompt_prompt(
narrations=batch_narrations,
min_words=min_words,
max_words=max_words
)
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 "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)
View on GitHub (pinned to 848b054e4f)