abi/screenshot-to-code · error · ValueError

Video mode requires a video to be provided

Error message

Video mode requires a video to be provided

What it means

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.

Source

Thrown at backend/prompts/create/__init__.py:36

        text_prompt = prompt.get("text", "")
        return build_image_prompt_messages(
            image_data_urls=image_urls,
            stack=stack,
            text_prompt=text_prompt,
            image_generation_enabled=image_generation_enabled,
            design_system=design_system,
        )
    if input_mode == "text":
        return build_text_prompt_messages(
            text_prompt=prompt["text"],
            stack=stack,
            image_generation_enabled=image_generation_enabled,
            design_system=design_system,
        )
    if input_mode == "video":
        video_urls = prompt.get("videos", [])
        if not video_urls:
            raise ValueError("Video mode requires a video to be provided")
        video_url = video_urls[0]
        return build_video_prompt_messages(
            video_data_url=video_url,
            stack=stack,
            text_prompt=prompt.get("text", ""),
            image_generation_enabled=image_generation_enabled,
            design_system=design_system,
        )
    raise ValueError(f"Unsupported input mode: {input_mode}")


__all__ = ["build_create_prompt_from_input"]

View on GitHub (pinned to d026163f58)

Solutions

  1. Ensure the request payload includes a non-empty `videos` array (first entry is used) before submitting.
  2. On the frontend, disable the generate button until a video is attached in video mode.
  3. In the route handler, validate the payload before calling the prompt builder and return a 400 with a clearer message.
  4. If videos are optional for your flow, use input_mode "image" or "text" instead.

Example fix

# before
build_create_prompt_from_input({"text": "..."}, input_mode="video", stack=stack)

# after
build_create_prompt_from_input({"text": "...", "videos": [data_url]}, input_mode="video", stack=stack)
Defensive patterns

Strategy: validation

Validate before calling

def can_build_video_prompt(prompt: dict) -> bool:
    return bool(prompt.get("videos"))

Type guard

def is_ready_video_request(prompt: dict, input_mode: str) -> bool:
    """True when the prompt payload satisfies video-mode requirements."""
    if input_mode != "video":
        return True
    videos = prompt.get("videos")
    return isinstance(videos, list) and len(videos) > 0

Try / catch

try:
    messages = build_create_prompt_from_input(prompt, input_mode, stack)
except ValueError as e:
    if "requires a video" in str(e):
        return error_response("Attach a video before generating in video mode", 400)
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of abi/screenshot-to-code@d026163f58 (2026-08-14). Data as JSON: /api/errors/bd621f82fb9ba993. Report an issue: GitHub.