Structured Output
Structured output returns data in an agreed shape for programmatic consumption. It addresses format contracts, not factual accuracy or authorization.
Levels of constraint
| Method | Intended constraint | Not established |
|---|---|---|
| Prompt asks for JSON | Instruction-based formatting | Always parseable JSON |
| JSON mode | Valid JSON, implementation dependent | A particular schema |
| Schema-constrained output | Supported fields and types | Truth, evidence, authorization |
| Strict tool arguments | Parameter structure | Successful execution |
JSON Schema describes structure; complex semantic relationships may require application validation.
Check completion status
Consult documentation for the model and supported schema subset. Claude structured-output documentation describes refusals and token-limit truncation that may break schema compliance. Check completion state before parsing and validating; HTTP success alone is insufficient.
Engineering recommendations
For invoice extraction, define invoice_number, currency, total, and source_page. Permit null for missing evidence and represent incomplete extraction explicitly.
Validate amounts, currencies, relationships, and source locations. Check authorization before database writes. Version the schema and input, log validation failures, and bound retries.
See JSON mode, function calling, hallucination, and prompt injection.