{"record":{"id":"40f3be6f9ca74737","repo":"rohitg00/ai-engineering-from-scratch","slug":"mode-trials-root-must-be-an-object","errorCode":null,"errorMessage":"mode-trials root must be an object","messagePattern":"mode-trials 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":320,"sourceCode":"        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            {\n                \"valid\": not errors,\n                \"summary\": summarize(benchmark),\n                \"modeTrials\": summarize_mode_trials(mode_trials),\n            },\n            indent=2,\n        )\n    )","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/02-model-selection-and-token-economics/code/main.py#L302-L338","documentation":"Loader guard for the mode-trials file: the JSON parsed successfully but the root value is not an object (an array or scalar), so nested access to trials and decision would fail. It fires right after read, before schema checks.","triggerScenarios":"Thrown at certifications/claude/lessons/02-model-selection-and-token-economics/code/main.py:320 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a top-level object wrapping the trials list and decision","Confirm the path points at the mode-trials JSON, not a raw results array","Load and shape-check all input files once in setUp so failures name the offending file"],"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"}