{"record":{"id":"e86ba091678dda93","repo":"rohitg00/ai-engineering-from-scratch","slug":"benchmark-root-must-be-an-object","errorCode":null,"errorMessage":"benchmark root must be an object","messagePattern":"benchmark root must be an object","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/02-model-selection-and-token-economics/code/main.py","lineNumber":313,"sourceCode":"\ndef _nonempty_strings(value: Any) -> bool:\n    return isinstance(value, list) and bool(value) and all(isinstance(item, str) and item.strip() for item in value)\n\n\ndef _iso_date(value: Any) -> bool:\n    if not isinstance(value, str):\n        return False\n    try:\n        date.fromisoformat(value)\n        return True\n    except ValueError:\n        return False\n\n\ndef load_benchmark(path: Path) -> dict[str, Any]:\n    value = json.loads(path.read_text(encoding=\"utf-8\"))\n    if not isinstance(value, dict):\n        raise ValueError(\"benchmark root must be an object\")\n    return value\n\n\ndef load_mode_trials(path: Path) -> dict[str, Any]:\n    value = json.loads(path.read_text(encoding=\"utf-8\"))\n    if not isinstance(value, dict):\n        raise ValueError(\"mode-trials root must be an object\")\n    return value\n\n\nif __name__ == \"__main__\":\n    outputs = Path(__file__).parents[1] / \"outputs\"\n    benchmark = load_benchmark(outputs / \"model-routing-benchmark.json\")\n    mode_trials = load_mode_trials(outputs / \"mode-trials.json\")\n    errors = validate_benchmark(benchmark) + validate_mode_trials(mode_trials)\n    print(\n        json.dumps(\n            {","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/02-model-selection-and-token-economics/code/main.py#L295-L331","documentation":"Loader guard for the benchmark file: json.loads succeeded, but the parsed document is not a JSON object (likely a top-level array or a bare string/number), so field lookups like get('cases') would be meaningless. It fires immediately after reading the file, before any validation.","triggerScenarios":"Thrown at certifications/claude/lessons/02-model-selection-and-token-economics/code/main.py:313 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Make the benchmark file a top-level JSON object with the expected keys","Check the loader points at benchmark.json and not an exported array or log file","Include the parsed root type in the error to make the mismatch obvious"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}