Loading patterns…
Structured Outputs(SO)
Guarantee that model output conforms to a schema by constraining decoding. A JSON Schema, regex, or grammar is compiled into a finite-state machine, and at every decode step the tokens that would violate the schema are masked out so only valid continuations can be sampled. In strict mode this makes malformed JSON and invalid tool arguments impossible. It is available natively at OpenAI, Google, and Anthropic and in open libraries such as Outlines and vLLM.
In 30 seconds
- What
- Compiles a schema into a finite-state machine and masks invalid tokens at each decode step, guaranteeing output conforms to the schema.
- When to use
- Extracting structured data, calling tools, or generating JSON where parse errors or invalid values would break downstream code.
- Watch out
- Schema constraints can force the model to emit technically valid but semantically nonsensical values when the true answer falls outside allowed options.
Ask the AI expert about this pattern
Opens the assistant with your question prefilled. You review it before sending.
Structured Outputs: Overview
Guarantee that model output conforms to a schema by constraining decoding. A JSON Schema, regex, or grammar is compiled into a finite-state machine, and at every decode step the tokens that would violate the schema are masked out so only valid continuations can be sampled. In strict mode this makes malformed JSON and invalid tool arguments impossible. It is available natively at OpenAI, Google, and Anthropic and in open libraries such as Outlines and vLLM.
- Constrained decoding driven by JSON Schema, regex, or grammar
- Schema compiled to a finite-state machine and per-step token mask
- Invalid tokens masked at every decode step in strict mode
- Schema-conforming output guaranteed, not merely requested
- Eliminates JSON parse errors and invalid tool-call arguments
- Native provider support plus Outlines and vLLM
The Agent Architect
One pattern, one tradeoff, one production failure story. A short weekly briefing for people building agentic systems.
Weekly email, one-click unsubscribe. We only use your address to send the briefing.
References
The papers, specifications, and repositories this pattern is based on.
From the engineer behind this catalog
Get your agent architecture reviewed
This page documents one pattern. Your system runs dozens, and most failures live in how they fit together. Have the whole design reviewed against the 288 patterns in this catalog: architecture, reliability, evaluation and cost, every finding mapped to the pattern that fixes it.
€750 instead of €1,500, one week, written report and walkthrough call, until 30 September