{"record":{"id":"2c291efcf47b4d11","repo":"abi/screenshot-to-code","slug":"prompt-item-index-must-be-a-string-or-object","errorCode":null,"errorMessage":"Prompt item {index} must be a string or object.","messagePattern":"Prompt item (.+?) must be a string or object\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/run_image_generation_evals.py","lineNumber":78,"sourceCode":"def load_prompts(prompt_file: Path) -> list[PromptItem]:\n    raw: Any = json.loads(prompt_file.read_text())\n    if not isinstance(raw, list):\n        raise ValueError(\"Prompt file must contain a JSON array.\")\n\n    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","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/abi/screenshot-to-code/blob/d026163f586dfa8c5c10d28c36edd59a9d3b0e88/backend/run_image_generation_evals.py#L60-L96","documentation":"ValueError(\"Prompt item {index} must be a string or object.\") raised by load_prompts() when an element of the prompt array is neither a str nor a dict — i.e. a JSON number, boolean, or null. The 1-based index in the message identifies the offending element. It aborts the eval run at load time.","triggerScenarios":"A prompts.json array like [\"a cat\", 42] or [\"a cat\", null] — element 2 fails isinstance checks for both str and dict and raises with index 2.","commonSituations":"Hand-edited prompt lists with a typo (missing quotes around a prompt); trailing null from a bad merge; numbers pasted where prompt text was intended.","solutions":["Open the prompt file, jump to the reported 1-based index, and make that element a string or an object with a \"prompt\" key","Quote bare numeric prompts: 42 -> \"42\"","Remove stray null/boolean entries left by merges or templating"],"exampleFix":"// before\n[\n  \"a cat\",\n  7\n]\n\n// after\n[\n  \"a cat\",\n  \"7 dogs\"\n]","handlingStrategy":"type-guard","validationCode":"def validate_prompt_items(items: list) -> list[int]:\n    return [i for i, item in enumerate(items, start=1) if not isinstance(item, (str, dict))]","typeGuard":"from typing import Any, TypeGuard\n\ndef is_prompt_item(item: Any) -> TypeGuard[str | dict[str, Any]]:\n    return isinstance(item, (str, dict))","tryCatchPattern":"try:\n    load_prompts(prompt_file)\nexcept ValueError as e:\n    if \"must be a string or object\" in str(e):\n        idx = int(str(e).split()[2])  # 'Prompt item {index} must be...'\n        fix_item_at(prompt_file, idx)","preventionTips":["Quote every prompt as a string or wrap it in an object; never leave bare numbers/booleans","Clean null entries after merging prompt files","Run a lint pass over prompt JSON before long eval runs"],"tags":["python","json","validation","evals"],"backgroundTag":null,"analyzedSha":"d026163f586dfa8c5c10d28c36edd59a9d3b0e88","analyzedAt":"2026-08-14T22:02:06.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}