Skip to main content

Claude API structured outputs — guarantee output with a JSON schema

"Answer in JSON" sometimes breaks. Structured outputs guarantee a schema via two modes (JSON output, strict tools), constrained decoding, plus incompatibilities and pitfalls — per the official docs.

ByUpdated

Even when you prompt "answer only in JSON," the model can wrap output in markdown or add commentary that breaks parsing. Structured outputs constrain the response to a defined schema, guaranteeing directly parseable output. This guide covers the two modes, how it works, and pitfalls, grounded in the official docs. (Official: platform.claude.com/docs · as of September 2026, re-checked against the structured-outputs docs)

🟢 Current lineup (September 2026): Claude Opus 5.5 / Claude Sonnet 5 / Claude Haiku 4.5 (higher tier: Claude Fable 5.1). · model notice · Fable subscription
🔵 Current lineup (September 2026): Claude Opus 5.5 / Claude Sonnet 5 / Claude Haiku 4.5 (higher tier: Claude Fable 5.1). Parts of this article may still describe an earlier model.

Fable 5 and 5.1 subscription (updated September 7, 2026): Claude Fable 5.1, released September 1, 2026, is the current Fable model and Fable 5 is now legacy. Plan terms are the same for both — Max and Team Premium plans include Fable at up to 50% of the weekly usage limit; Pro and Team Standard use usage credits (

🔵 Current lineup (September 2026): Claude Opus 5.5 / Claude Sonnet 5 / Claude Haiku 4.5 (higher tier: Claude Fable 5.1). Parts of this article may still describe an earlier model.
0/M input, $50/M output tokens). The one-time
🔵 Current lineup (September 2026): Claude Opus 5.5 / Claude Sonnet 5 / Claude Haiku 4.5 (higher tier: Claude Fable 5.1). Parts of this article may still describe an earlier model.
00 credit applied only to the Fable 5 transition and is not offered for 5.1. Some coding and debugging requests may be answered by an Opus model due to a security classifier (both models). See the Fable 5.1 guide and the Fable 5 availability guide for details.

"Answer in JSON" vs guaranteed schemaAsking via prompt· sometimes wrapped in markdown· chatter/explanations creep in· schema violations -> parse failsStructured outputs· follows your defined schema· directly parseable JSON· no retries / regex parsingSchema compliance as a guarantee, not a request · as of 2026.6

Why you need it

Forcing JSON with prompt engineering alone leaves problems:

  • responses wrapped in markdown code blocks or padded with chatter
  • regex parsing breaks the moment the format shifts
  • schema violations require error handling and retries

Structured outputs turn this from a "request" into a "guarantee." The official docs recommend this feature over prompt techniques when you always need valid JSON.

Two modes

  • JSON output (output_config.format) — get the whole response in a specified JSON shape. Good for data extraction and structured replies.
  • Strict tool use (strict: true) — guarantee that tool names and inputs follow the schema. Good for complex tools and agentic workflows.

You can use them independently or together in one request.

How it is guaranteed

Structured outputs compile your JSON schema into a grammar, then constrain generation so no token can violate those rules (constrained decoding). The model simply cannot produce schema-violating output. More complex schemas take longer to compile, so very large schemas should be simplified.

How to use it

Define the data shape you want as a JSON schema and pass it in.

# Define the desired output shape as a schema
schema = {
  "type": "object",
  "properties": {
    "name": {"type": "string"},
    "price": {"type": "number"},
    "in_stock": {"type": "boolean"}
  },
  "required": ["name", "price"]
}
# Pass this schema via output_config.format (official docs, September 2026; no beta header needed).
# msg = client.messages.create(model="claude-sonnet-5", max_tokens=1024,
#     output_config={"format": {"type": "json_schema", "schema": schema}},
#     messages=[...])
# The old beta output_format field and beta header are accepted only for a transition period;
# the Python SDK (1.0+) raises a TypeError if you pass output_format to the beta create().

SDKs make it easier: define schemas with Pydantic (Python) or Zod (TypeScript), and the SDK auto-simplifies unsupported constraints (min/max, etc.), reflecting them in descriptions (your code still enforces them).

Two modes · how it is guaranteedJSON output (output_format)data extraction, structured repliesStrict tools (strict: true)validate tool name & input schemaJSON schemadefine the shapecompile to grammarturn into rulesconstrain outputno violating tokensConstrained-decoding concept · params/status may change · as of 2026.6

Things to watch

  • Availability/status — as of September 2026 the feature is generally available and beta headers are no longer required. Supported models include Opus 5, Sonnet 5, Fable 5.1, Opus 4.6–4.8, Sonnet 4.6, Sonnet 4.5, Opus 4.5, and Haiku 4.5 (Bedrock: the 4.5/4.6 families only). The parameter moved from output_format to output_config.format, so don't reuse old samples verbatim (only the messages.parse() helper still accepts output_format= for convenience). Supported models can change, so the official docs are the source of truth.
  • Incompatibilities — Citations and message prefilling can't be combined (using citations with it returns a 400).
  • Trade-off with extended thinking — if reasoning matters more, extended thinking may fit better. Grammar constraints don't apply to the thinking region.
  • Simplify schemas — break overly complex schemas into smaller, simpler ones.

For how tool use works, see the Tool Use guide; for the first call, see getting started; for errors/limits, see handling errors and rate limits.

Structured-outputs parameters, beta headers, supported models, and GA status may change; verify the latest in the official docs (platform.claude.com/docs). This site is not an official Anthropic site.

To receive tables, lists, or JSON in chat without writing code, see specifying Claude's output format.

See also: Tool use best practices

Was this helpful?

Keep reading