Want JSON that fits your schema from Claude? Use structured outputs
Structured outputs in the Claude API make the response follow a JSON Schema you give it in most cases, except when Claude refuses or stops at max_tokens. Put the schema in output_config.format, or strict: true on a tool.

You asked Claude to pull a name and an email out of a message and return them as JSON, and once the response came back with an extra sentence, so JSON.parse failed. This article gives Claude the schema itself, and Claude follows it.
What are structured outputs?
Structured outputs are a Claude API feature that makes Claude's response follow a JSON Schema you give it, so in most cases the response can be read by the code that comes next.
According to the structured outputs documentation, there are two features:
Feature | Where it goes | What it guarantees |
|---|---|---|
JSON outputs |
| The shape of Claude's own response |
Strict tool use |
| Tool name and inputs follow the schema |
What exactly does it guarantee?
Structured outputs guarantee three things according to the docs: the response is always valid JSON with no parsing errors, field types and required fields are there, and you do not need retries because a response broke the schema.
The docs say this guarantee comes from constrained decoding.
But the same docs say the guarantee holds "in most cases", and there are two cases where the response might not match the schema:
When Claude refuses the request for safety reasons: the response has
stop_reason: "refusal", and the refusal message takes precedence over the schema constraints.When the response is cut off at the
max_tokenslimit: the response hasstop_reason: "max_tokens", and it might be incomplete. The fix is to retry with a highermax_tokensvalue.
How do you request it?
You put the schema in the request under output_config.format, with type: "json_schema". This is part of the request body, based on the docs example that pulls information out of an email:
{
"output_config": {
"format": {
"type": "json_schema",
"schema": {
"type": "object",
"properties": {
"name": { "type": "string" },
"email": { "type": "string" },
"plan_interest": { "type": "string" },
"demo_requested": { "type": "boolean" }
},
"required": ["name", "email", "plan_interest", "demo_requested"],
"additionalProperties": false
}
}
}
}The response arrives as JSON text that follows this schema. Before you run JSON.parse on it, check the stop_reason: if it is "refusal" or "max_tokens", do not treat it as complete JSON. If you want Claude to call a tool, set strict: true on the tool definition.
What JSON Schema features are not accepted?
Not every JSON Schema is accepted. The docs list unsupported features, and the most relevant for daily work are:
Recursive schemas.
Numerical constraints like
minimumandmaximum.String constraints like
minLengthandmaxLength.additionalPropertiesset to anything other thanfalse.
If you use an unsupported feature, the request returns a 400 error with details. So if you want an age between two limits, or a name under a certain length, the schema guarantees the type only, and you check the limit in your own code.
Where do you start now?
The lesson for us as developers: when the response goes to code and not to a person, the shape belongs in the schema, not in a "return JSON only" line in the prompt.
Search your code for every
JSON.parseon a Claude response with a try or a retry around it.Write the schema and put it in
output_config.format, withadditionalProperties: false.Remove the unsupported constraints from the schema, and check them in your code.
Check the
stop_reasonbefore you read the response, and handle"refusal"and"max_tokens"on their own.
If the response gets cut off midway, the cause is often the token limit: the max_tokens article. Before you send a large request, you can count its tokens with the token counting article. And if you work with coding agents, see AI skills.
Where in your project is there a JSON.parse on a model response that could fail?
FAQ
What happens if I put minimum or maxLength in the schema?
These constraints are not supported according to the docs, and a request with an unsupported feature returns a 400 error with details. Check those limits in your code after the response arrives.
What is the difference between JSON outputs and strict tool use?
JSON outputs set the shape of Claude's own response. Strict tool use guarantees that the tool name and the inputs Claude sends to it follow the tool's schema.
Can I use a recursive schema?
No. Recursive schemas are on the list of features the docs say are not supported.


