{"record":{"id":"bd621f82fb9ba993","repo":"abi/screenshot-to-code","slug":"video-mode-requires-a-video-to-be-provided","errorCode":null,"errorMessage":"Video mode requires a video to be provided","messagePattern":"Video mode requires a video to be provided","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/prompts/create/__init__.py","lineNumber":36,"sourceCode":"        text_prompt = prompt.get(\"text\", \"\")\n        return build_image_prompt_messages(\n            image_data_urls=image_urls,\n            stack=stack,\n            text_prompt=text_prompt,\n            image_generation_enabled=image_generation_enabled,\n            design_system=design_system,\n        )\n    if input_mode == \"text\":\n        return build_text_prompt_messages(\n            text_prompt=prompt[\"text\"],\n            stack=stack,\n            image_generation_enabled=image_generation_enabled,\n            design_system=design_system,\n        )\n    if input_mode == \"video\":\n        video_urls = prompt.get(\"videos\", [])\n        if not video_urls:\n            raise ValueError(\"Video mode requires a video to be provided\")\n        video_url = video_urls[0]\n        return build_video_prompt_messages(\n            video_data_url=video_url,\n            stack=stack,\n            text_prompt=prompt.get(\"text\", \"\"),\n            image_generation_enabled=image_generation_enabled,\n            design_system=design_system,\n        )\n    raise ValueError(f\"Unsupported input mode: {input_mode}\")\n\n\n__all__ = [\"build_create_prompt_from_input\"]\n","sourceCodeStart":18,"sourceCodeEnd":49,"githubUrl":"https://github.com/abi/screenshot-to-code/blob/d026163f586dfa8c5c10d28c36edd59a9d3b0e88/backend/prompts/create/__init__.py#L18-L49","documentation":"Raised in build_create_prompt_from_input when input_mode == \"video\" but prompt[\"videos\"] is missing or an empty list. Video-mode prompt construction needs at least one video data URL as its primary input; with none, there is nothing to build the prompt around, so it fails fast with a plain ValueError.","triggerScenarios":"Calling build_create_prompt_from_input(prompt, input_mode=\"video\", ...) where prompt has no \"videos\" key, or videos: []. Typical producer: the WebSocket generation route receiving {kind:\"create\", inputMode:\"video\"} without video data — e.g. the frontend sent the video as an attachment that failed to attach.","commonSituations":"Frontend sends inputMode \"video\" while the video upload/attachment silently failed; UI state desync where the mode toggle changed but the video array wasn't populated; API clients hand-crafting the prompt payload and forgetting the videos field.","solutions":["Ensure the request payload includes a non-empty `videos` array (first entry is used) before submitting.","On the frontend, disable the generate button until a video is attached in video mode.","In the route handler, validate the payload before calling the prompt builder and return a 400 with a clearer message.","If videos are optional for your flow, use input_mode \"image\" or \"text\" instead."],"exampleFix":"# before\nbuild_create_prompt_from_input({\"text\": \"...\"}, input_mode=\"video\", stack=stack)\n\n# after\nbuild_create_prompt_from_input({\"text\": \"...\", \"videos\": [data_url]}, input_mode=\"video\", stack=stack)","handlingStrategy":"validation","validationCode":"def can_build_video_prompt(prompt: dict) -> bool:\n    return bool(prompt.get(\"videos\"))","typeGuard":"def is_ready_video_request(prompt: dict, input_mode: str) -> bool:\n    \"\"\"True when the prompt payload satisfies video-mode requirements.\"\"\"\n    if input_mode != \"video\":\n        return True\n    videos = prompt.get(\"videos\")\n    return isinstance(videos, list) and len(videos) > 0","tryCatchPattern":"try:\n    messages = build_create_prompt_from_input(prompt, input_mode, stack)\nexcept ValueError as e:\n    if \"requires a video\" in str(e):\n        return error_response(\"Attach a video before generating in video mode\", 400)\n    raise","preventionTips":["Disable the generate action in video mode until a video is attached","Validate inputMode + its required payload fields at the WebSocket/route boundary","Write e2e tests for each input mode so mode/payload mismatches fail in CI"],"tags":["prompts","validation","video","input-mode"],"backgroundTag":null,"analyzedSha":"d026163f586dfa8c5c10d28c36edd59a9d3b0e88","analyzedAt":"2026-08-14T22:02:06.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}