{"record":{"id":"ee0690c3d9bd41fb","repo":"abi/screenshot-to-code","slug":"prompt-item-index-is-missing-a-prompt-string","errorCode":null,"errorMessage":"Prompt item {index} is missing a prompt string.","messagePattern":"Prompt item (.+?) is missing a prompt string\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/run_image_generation_evals.py","lineNumber":83,"sourceCode":"    prompts: list[PromptItem] = []\n    for index, item in enumerate(cast(list[Any], raw), start=1):\n        if isinstance(item, str):\n            prompts.append(\n                {\n                    \"id\": f\"{index:03d}\",\n                    \"category\": \"Prompt\",\n                    \"prompt\": item,\n                }\n            )\n            continue\n\n        if not isinstance(item, dict):\n            raise ValueError(f\"Prompt item {index} must be a string or object.\")\n\n        item_dict = cast(dict[str, Any], item)\n        prompt = item_dict.get(\"prompt\")\n        if not isinstance(prompt, str) or not prompt.strip():\n            raise ValueError(f\"Prompt item {index} is missing a prompt string.\")\n\n        prompt_id = item_dict.get(\"id\")\n        category = item_dict.get(\"category\")\n        prompts.append(\n            {\n                \"id\": prompt_id if isinstance(prompt_id, str) else f\"{index:03d}\",\n                \"category\": category if isinstance(category, str) else \"Prompt\",\n                \"prompt\": prompt,\n            }\n        )\n\n    return prompts\n\n\ndef build_replicate_input(\n    model: ReplicateEvalModel, prompt: str\n) -> dict[str, str | int | float | bool]:\n    if model == \"flux_2_klein\":","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/abi/screenshot-to-code/blob/d026163f586dfa8c5c10d28c36edd59a9d3b0e88/backend/run_image_generation_evals.py#L65-L101","documentation":"ValueError(\"Prompt item {index} is missing a prompt string.\") raised by load_prompts() when an array element is a dict but its \"prompt\" key is absent, not a string, or a blank/whitespace-only string. The check is isinstance(prompt, str) and prompt.strip(), so empty prompts are rejected too. Aborts the eval run at load time.","triggerScenarios":"Array elements like {\"id\": \"p1\", \"category\": \"Landscape\"} (no prompt key), {\"prompt\": 123}, or {\"prompt\": \"   \"}.","commonSituations":"Prompt objects built from spreadsheets/CSV where the prompt column is empty for some rows; typo'd key such as \"text\" or \"Prompt\" instead of \"prompt\" (keys are case-sensitive).","solutions":["At the reported index, ensure the object has \"prompt\": \"<non-empty text>\" spelled exactly lowercase","If the key was typo'd (\"text\"/\"Prompt\"), rename it to \"prompt\"","Drop or fill empty-prompt rows before exporting the file"],"exampleFix":"// before\n[{\"id\": \"p1\", \"text\": \"a cat\"}]\n\n// after\n[{\"id\": \"p1\", \"prompt\": \"a cat\"}]","handlingStrategy":"validation","validationCode":"def validate_prompt_objects(items: list) -> list[int]:\n    bad = []\n    for i, item in enumerate(items, start=1):\n        if isinstance(item, dict):\n            p = item.get(\"prompt\")\n            if not isinstance(p, str) or not p.strip():\n                bad.append(i)\n    return bad","typeGuard":"from typing import Any, TypeGuard\n\ndef has_valid_prompt(item: dict[str, Any]) -> TypeGuard[dict[str, Any]]:\n    p = item.get(\"prompt\")\n    return isinstance(p, str) and bool(p.strip())","tryCatchPattern":"try:\n    load_prompts(prompt_file)\nexcept ValueError as e:\n    if \"missing a prompt string\" in str(e):\n        idx = int(str(e).split()[2])\n        fill_or_drop_prompt(prompt_file, idx)","preventionTips":["Use exactly the lowercase key \"prompt\"; the loader is case-sensitive","Reject empty/whitespace prompt cells when exporting from spreadsheets","Prefer plain-string array elements unless you need id/category metadata"],"tags":["python","json","validation","evals","schema"],"backgroundTag":null,"analyzedSha":"d026163f586dfa8c5c10d28c36edd59a9d3b0e88","analyzedAt":"2026-08-14T22:02:06.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}