Structured outputs
For engineers
Getting machine-readable output with JSON Schema, choosing the right mechanism, validating results and repairing failures
110 questions across four stages: Understand, Apply, Solve and Judge.
Try 5 questions
Practice items, not counted towards your mastery. No account needed.
Check yourself · 1 of 5
Your code reads a status field that must be one of three known values. How should the schema describe it?
Check yourself · 2 of 5
A model is set to JSON mode and returns {"category": "billing"} when your code also needs priority. What does this show?
Check yourself · 3 of 5
A reply passes the schema and contains order_id: "ORD-48213". What must your code still do before refunding?
Check yourself · 4 of 5
A reply fails validation because priority is "high". What should the retry message contain?
Check yourself · 5 of 5
Your schema uses minLength and pattern, and the provider does not enforce them. What is the safe approach?
Topics
- Defining model output with JSON Schema4 min read · Required fields, enums, descriptions and nullable values written as JSON Schema, Pydantic or Zod models
- Strict schemas versus JSON mode versus forced tools4 min read · When to use strict structured outputs, plain JSON mode or a forced tool call, and what each one guarantees
- Validating structured output before you use it4 min read · Why schema-valid output can still be wrong: invented ids, out-of-range values, empty strings and refusals
- Repairing invalid output with targeted retries4 min read · Sending the validation error back to the model, bounding attempts and falling back when repair fails
- Where constrained decoding hits its limits4 min read · Unsupported schema keywords, nesting and size limits, first-request latency and quality loss when answers skip reasoning
Start here
- Structured outputs (Claude docs) (opens in a new tab)DocsFree
How Claude constrains output to a JSON schema, which schema features are supported and what the limits are.
- Structured model outputs (OpenAI API docs) (opens in a new tab)DocsFree
Strict schema mode versus JSON mode, supported keywords and how refusals appear in a structured response.
- Structured output (Gemini API docs) (opens in a new tab)DocsFree
How Gemini takes a response schema and which schema subset it accepts.
Helps to know first
110 questions · last verified 2026-12