{"record":{"id":"b27c13f02cef8955","repo":"abi/screenshot-to-code","slug":"prompt-file-must-contain-a-json-array","errorCode":null,"errorMessage":"Prompt file must contain a JSON array.","messagePattern":"Prompt file must contain a JSON array\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/run_image_generation_evals.py","lineNumber":63,"sourceCode":"MODEL_PATHS: dict[ReplicateEvalModel, str] = {\n    \"flux_2_klein\": FLUX_2_KLEIN_MODEL_PATH,\n    \"z_image_turbo\": Z_IMAGE_TURBO_MODEL_PATH,\n}\n\nDEFAULT_PROMPT_FILE = Path(\"image_generation/eval_sets/recent_assets_20_prompts.json\")\nDEFAULT_OUTPUT_ROOT = Path(\"image_generation/eval_results\")\n\n\ndef slugify(text: str) -> str:\n    text = text.lower()\n    text = re.sub(r\"[^a-z0-9]+\", \"-\", text).strip(\"-\")\n    return text[:60] or \"prompt\"\n\n\ndef 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\")","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/abi/screenshot-to-code/blob/d026163f586dfa8c5c10d28c36edd59a9d3b0e88/backend/run_image_generation_evals.py#L45-L81","documentation":"ValueError(\"Prompt file must contain a JSON array.\") raised by load_prompts() in run_image_generation_evals.py when json.loads succeeds but the top-level value is not a list (it is a dict, string, number, etc.). The eval script only accepts an array of prompt items, so any object-wrapped format like {\"prompts\": [...]} aborts the run before any image is generated.","triggerScenarios":"Running `poetry run python run_image_generation_evals.py --prompt-file prompts.json` where prompts.json is an object (e.g. {\"prompts\": [...], \"version\": 2}) or a bare JSON string/number.","commonSituations":"Prompt files authored by hand or exported from tools that wrap arrays in an envelope object; reusing a config-style JSON file instead of a prompt list.","solutions":["Rewrite the prompt file so the top level is an array: [\"a prompt\", {\"id\": \"p1\", \"prompt\": \"...\", \"category\": \"...\"}]","If the wrapper is intentional, extend load_prompts to unwrap a known key such as raw[\"prompts\"] before the isinstance check","Validate the file shape before the run: python -c \"import json;assert isinstance(json.load(open('prompts.json')),list)\""],"exampleFix":"// before prompts.json\n{\"prompts\": [\"a cat\", \"a dog\"]}\n\n// after prompts.json\n[\"a cat\", \"a dog\"]","handlingStrategy":"validation","validationCode":"import json\n\ndef validate_prompt_file(path: str) -> list:\n    raw = json.loads(open(path, encoding=\"utf-8\").read())\n    if not isinstance(raw, list):\n        raise ValueError(f\"Top level is {type(raw).__name__}, expected a JSON array\")\n    return raw","typeGuard":"from typing import Any, TypeGuard\n\ndef is_prompt_array(raw: Any) -> TypeGuard[list[Any]]:\n    return isinstance(raw, list)","tryCatchPattern":"try:\n    prompts = load_prompts(prompt_file)\nexcept ValueError as e:\n    if \"must contain a JSON array\" in str(e):\n        fix_prompt_file_shape(prompt_file)  # unwrap envelope / re-export as array\n    raise","preventionTips":["Author prompt files as a top-level JSON array; avoid envelope objects","Add a schema check to CI for committed prompt files","If tools export wrapped formats, unwrap in a preprocessing step before the eval run"],"tags":["python","json","validation","cli","evals"],"backgroundTag":null,"analyzedSha":"d026163f586dfa8c5c10d28c36edd59a9d3b0e88","analyzedAt":"2026-08-14T22:02:06.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}