Category · Models and how they work
What is structured output?
Structured output means forcing the model to follow a JSON (JavaScript Object Notation) schema exactly. At each token, the provider blocks anything that would break the schema, so the format is always valid. The code only has to check the meaning.
By Laurent Poupet, Claude trainer and artificial intelligence architect · Updated
How it works
- Constrained decoding removes, at each token, the choices that would violate the schema. The model can therefore only produce a valid document, which removes retries for invalid formats.
- Strict mode requires every field to be mandatory and forbids extra properties. An optional field is then expressed as an allowed null value.
- On Azure OpenAI, this mode does not work with parallel tool calls, which must be turned off. Schemas also have limits on size and nesting depth.
The trap to avoid
The trap is the refusal. If the model refuses to answer for safety reasons, the response carries a refusal field instead of the expected document, and the code must plan for it.
Related terms
- TokenModels and how they work
- TemperatureModels and how they work
- PromptModels and how they work
Where this is taught
Track 3 · Skills, agents and connectors
Advanced hooks — Deterministic automationlesson 2 · 1 hour
Lesson content (step-by-step instructions, exercises with solutions, quizzes) is for students only, with an access code received after the first lesson.