A downstream service crashes when a field in Claude's JSON is missing. You want the response to match a schema. What should you use?
Why A is the answer
Structured outputs with a JSON schema
Structured outputs put the schema in output_config.format, and Claude returns JSON matching it in the text block. Prefill is rejected on current models. You should still handle cases such as refusals, where output may not match.
In detail
- Structured outputs put a JSON schema in output_config.format.
- Claude returns JSON matching it in the text block.
- Still handle cases such as refusals, where the output may not match.
- Keep the schema in version control with the code that reads it.
Use case
An illustrative scenario, not a real incident.
A pricing service crashes when "currency" is missing from a reply. Structured outputs with a schema give it the expected fields. It still checks for refusals.
See it in different ways
stateDiagram-v2 [*] --> Response Response --> Complete: end_turn Response --> RunTool: tool_use Response --> CutOff: max_tokens Response --> Blocked: refusal Response --> Continue: pause_turn Continue --> Response: send content back
flowchart LR S0["Define JSON schema"] --> S1["Send in output_config.format"] --> S2["JSON in the text block"] --> S3["Service reads fields"]
Key point: Use a schema when a program reads the reply.
Why the other options are wrong
- B. A higher temperature setting
- Higher temperature adds variety, which is the opposite of what you need.
- C. A prefilled assistant message that opens the JSON object for the model
- Prefill is rejected on current models.
- D. Ask nicely in the system prompt
- A request in the prompt is not a guarantee.

