{"record":{"id":"252995ae0f904749","repo":"rohitg00/ai-engineering-from-scratch","slug":"unexpected-messages-api-response-contract","errorCode":null,"errorMessage":"unexpected Messages API response contract","messagePattern":"unexpected Messages API response contract","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/30-developer-application-capstone/code/main.py","lineNumber":102,"sourceCode":"                \"name\": \"lookup_order\",\n                \"description\": \"Read one visible order status. Never changes order state.\",\n                \"input_schema\": {\n                    \"type\": \"object\",\n                    \"properties\": {\"order_id\": {\"type\": \"string\", \"pattern\": \"^[A-Z]-[0-9]{2,6}$\"}},\n                    \"required\": [\"order_id\"],\n                    \"additionalProperties\": False,\n                },\n            }\n        ],\n    }\n\n\ndef run_live_wire(transport: MessagesTransport, request: str, model: str) -> dict[str, Any]:\n    \"\"\"Exercise the real serialization boundary and return only safe metadata.\"\"\"\n    response = transport.create_message(build_live_order_request(request, model))\n    content = response.get(\"content\")\n    if response.get(\"type\") != \"message\" or response.get(\"role\") != \"assistant\" or not isinstance(content, list):\n        raise ValueError(\"unexpected Messages API response contract\")\n    content_types = [block.get(\"type\") for block in content if isinstance(block, dict)]\n    return {\n        \"type\": response[\"type\"],\n        \"role\": response[\"role\"],\n        \"stop_reason\": response.get(\"stop_reason\"),\n        \"content_types\": content_types,\n        \"message_id_present\": isinstance(response.get(\"id\"), str),\n    }\n\n\n@dataclass(frozen=True)\nclass TraceEvent:\n    type: str\n    detail: dict[str, Any]\n\n\n@dataclass(frozen=True)\nclass SupportResult:","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/30-developer-application-capstone/code/main.py#L84-L120","documentation":"Error \"unexpected Messages API response contract\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at certifications/claude/lessons/30-developer-application-capstone/code/main.py:102 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}