Advanced
Open
Pro
Designing a Structured-Output Migration-Risk Extractor
You're building a Python service on the Agent SDK that scans a repo before a migration and returns a risk assessment:
schema = {
"type": "object",
"properties": {
"risk_level": {"type": "string", "enum": ["low", "medium", "high"]},
"affected_files": {"type": "array", "items": {"type": "string"}},
},
"required": ["risk_level", "affected_files"],
}
passed via output_format={"type": "json_schema", "schema": schema}.
- Claude's first attempt returns
risk_level: "moderate"(not one of the enum values). What does the SDK do next, and what would a naive implementation that just checkedmessage.structured_output is not Noneget wrong in this specific failure? - Give one concrete reason a
ResultMessagecould havesubtype == "success"but nostructured_outputat all, distinct from a schema-validation failure. - Your team is deciding between this SDK approach and
claude -p --output-format json --json-schema '<schema>'invoked as a subprocess for the same task. Name one capability difference between the two that specifically affects how often this "moderate" mistake would make it into your database.
Share this question