What this thread does
As of November 2026, use output_config.format for Claude JSON output and strict: true for tool inputs, then validate before use. Do first: choose the SDK parse helper and handle refusal, truncation and string-enum capitalization exceptions (structured outputs).
The problem
You want the Claude API to return JSON that always matches your schema, without regex cleanup or retry loops, and your first attempt returns a 400 error or a cut-off object.
What the docs say
Anthropic's structured outputs page describes two features that can be used separately or together:
- JSON outputs: put
output_config.formatwithtype: "json_schema"and aschemaon the request. This controls what Claude says. - Strict tool use:
strict: trueon a tool validates tool names and inputs.
The availability section lists all models and all supported cloud platforms for the Messages API; Managed Agents is unavailable. The older output_format parameter and its beta header are deprecated in favour of output_config.format.
Schema limits (a request that uses them returns 400): recursive schemas, external $ref, numerical constraints (minimum, maximum, multipleOf), string length constraints, array constraints beyond minItems of 0 or 1, and additionalProperties set to anything but false (it must be false on objects). enum, const, anyOf, allOf, internal $ref and some string formats are supported (allOf with two or more schemas is unsupported when one directly contains $ref, anyOf or allOf); regex backreferences and lookaround are not.
It can still go wrong: with stop_reason: "refusal" you get HTTP 200, billed tokens and output that may not match the schema; with stop_reason: "max_tokens" the object may be cut off, so retry with a higher limit. The first request with a new schema is slower because the grammar compiles; compiled grammars are cached for 24 hours since last use, and changing the schema structure or the tool set invalidates that cache (changing only names or descriptions does not). Changing output_config.format also invalidates the prompt cache for that conversation. Per-request limits are 20 strict tools, 24 optional parameters and 16 union-type parameters; the latter two totals span strict tool schemas and JSON output schemas. Compilation can also fail on combined complexity or a 180-second timeout (limits).
Capitalization exception: string enum and const values may differ in capitalization, with a normal completion and no special stop reason. Avoid values distinguished only by case; normalize only where your application allows it, then validate (invalid outputs).
SDK helpers: in Python pass a Pydantic model as output_format to client.messages.parse() and read parsed_output; in TypeScript wrap a Zod schema in zodOutputFormat(). The helpers move unsupported constraints into field descriptions and still enforce the original constraints when validating the response. jsonSchemaOutputFormat() takes a plain schema but does not validate by default.
How to describe it to your agent
Use Claude structured outputs for this extraction: build the schema from our Pydantic model and call client.messages.parse(). Check stop_reason before using the result: handle refusal and retry max_tokens with a higher limit. Keep constraints like min/max in the Pydantic model (the SDK validates them) rather than in the raw schema. Do not change the schema between requests unless needed; it invalidates the grammar cache.
Mistakes to check
- Putting
minimumormaxLengthin a raw schema (400); use the SDK helper or validate yourself. - Forgetting that a guaranteed shape is not guaranteed correct content: validate meaning too.
- Using
output_formaton Python SDK v1.0+client.beta.messages.create()orcount_tokens(): it raisesTypeError; useoutput_config. Theoutput_formathelper argument toclient.messages.parse()remains supported (migration).
Limits
Constrained shape does not guarantee correct content. Unsupported raw-schema constraints return HTTP 400; SDK helpers can transform the schema and apply the original validation locally.
Sources
Started from a post by @Anthropic, packaged by the editor. Original post