{"record":{"id":"a74bb67ffc23ee99","repo":"rohitg00/ai-engineering-from-scratch","slug":"packet-root-must-be-an-object","errorCode":null,"errorMessage":"packet root must be an object","messagePattern":"packet root must be an object","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/03-prompting-and-task-decomposition/code/main.py","lineNumber":72,"sourceCode":"            errors.append(\"every evaluation case needs an expected behavior\")\n    return errors\n\n\ndef score_packet(packet: dict[str, Any]) -> dict[str, Any]:\n    errors = validate_packet(packet)\n    return {\n        \"passed\": not errors,\n        \"errors\": errors,\n        \"contractFields\": len(set(packet.get(\"contract\", {})) & CONTRACT_FIELDS) if isinstance(packet.get(\"contract\"), dict) else 0,\n        \"caseCoverage\": sorted({case.get(\"type\") for case in packet.get(\"evaluationCases\", []) if isinstance(case, dict)}),\n        \"stageCount\": len(packet.get(\"stages\", [])) if isinstance(packet.get(\"stages\"), list) else 0,\n    }\n\n\ndef load_packet(path: Path) -> dict[str, Any]:\n    value = json.loads(path.read_text(encoding=\"utf-8\"))\n    if not isinstance(value, dict):\n        raise ValueError(\"packet root must be an object\")\n    return value\n\n\nif __name__ == \"__main__\":\n    path = Path(__file__).parents[1] / \"outputs\" / \"prompt-contract-packet.json\"\n    print(json.dumps(score_packet(load_packet(path)), indent=2))\n","sourceCodeStart":54,"sourceCodeEnd":79,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/03-prompting-and-task-decomposition/code/main.py#L54-L79","documentation":"Loader guard for the prompt-packet file: the parsed JSON root is not an object, so downstream accesses like packet.get('contract') could not work. The file most likely holds an array or scalar at the top level.","triggerScenarios":"Thrown at certifications/claude/lessons/03-prompting-and-task-decomposition/code/main.py:72 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Wrap the packet content in a top-level JSON object with contract, stages, and evaluationCases","Verify the file path — an exported list is the usual culprit","Fail at load time with the actual root type included in the message"],"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"}