How to get reliable JSON from Claude
Asking for JSON in the prompt isn't a contract. Structured outputs and strict tool use are, and you still need to check stop_reason and the values.

This is Day 5 of Claude Architect in 30 Days. Day 4 ended with the output format as the fifth part of a prompt. When that output is read by code rather than a person, "please reply in JSON" stops being good enough. Today is about the guarantee that replaces it.
Who this is for: a developer whose code parses Claude's replies, and who has seen, or is about to see, a parse error in production.
Why "reply in JSON" fails
A prompt that says "reply with JSON in this format" usually works. That is the problem: it passes every test, then one day the reply starts with "Here's the JSON you asked for:", or leaves out a field, or adds one, and the parser throws. The usual patch is retry logic around the parse, which hides the failure and adds cost and delay.
Give Claude a schema
Structured outputs move the format from a request into a constraint. You attach a JSON schema to the call, and Claude's reply is held to it:
"output_config": {
"format": {
"type": "json_schema",
"schema": {
"type": "object",
"properties": {
"name": { "type": "string" },
"email": { "type": "string" },
"plan": { "type": "string" }
},
"required": ["name", "email", "plan"],
"additionalProperties": false
}
}
}The reply then parses every time, with the fields you required and nothing extra. Anthropic's SDKs add a helper that validates the result against your schema type for you, so your code receives a typed object rather than a string.
For tools: strict: true
When Claude calls one of your tools (Day 1 introduced them), it fills in the tool's inputs. Setting strict: true on the tool definition makes those inputs match the tool's input schema exactly, so your function never receives an argument of the wrong type or a missing required field.
Valid JSON can still be wrong
A schema guarantees shape, not truth. The JSON will parse and the plan field will be a string, but it might be the wrong plan. For anything your code acts on, such as an amount, an ID or a date, check the value as you would any other input: against your database, a list of allowed values, or a sensible range.
Check stop_reason before you parse
As Day 2 covered, stop_reason says why the reply ended. A refusal means there is no answer to parse. A max_tokens stop means the reply was cut off. Neither is the answer you asked for, so handle both before handing the content to your parser.
The old trick no longer works
A common workaround used to be prefilling: writing the first characters of Claude's reply yourself, such as an opening brace, so it would continue in JSON. Current Claude models reject a prefilled assistant turn with an error. If you're moving older code onto a newer model, this is one of the first things to replace, and a schema is the replacement.
Try this today
Find one place where your code parses Claude's text by hand: a regular expression, a "find the first brace" helper, a retry on bad JSON. Replace it with a schema, then delete the retry code around it. Tomorrow, Day 6 is about what belongs in Claude's context window. If you're wiring Claude into systems where a malformed reply would cause real damage, that's work I do in AI agents and automation.
Prefer slides? Download today's carousel as a PDF.