Robots Atlas>ROBOTS ATLAS
Inference

Structured Outputs

2023ActivePublished: 10 September 2026Updated: 10 September 2026Published
Key innovation
Enforces conformance of the model output to a supplied JSON Schema at decode time (constrained decoding), instead of hoping the model formats the answer correctly and validating only after the fact.
Category
Inference
Abstraction level
Pattern
Operation level
InferenceToolingApplication
Use cases
Data extraction from free-form textClassification with a fixed set of categoriesGenerating API-ready responsesTool and function callingAgentic workflows requiring reliable outputsFeeding ETL pipelines and databases

How it works

Step by step: 1) The application passes a JSON Schema describing the desired output structure. 2) The schema is compiled into a formal grammar (context-free grammar / finite-state machine); compilation is typically one-time and cached (in Claude, for 24 hours). 3) During autoregressive decoding, at each generation step a logit mask is computed: only tokens leading to a grammar-valid state are allowed, all others are set to zero probability. 4) The model samples the next token exclusively from the allowed set, so every partial output stays schema-conformant. 5) The finished output is deterministically parseable; SDK libraries additionally validate it against the original schema (including constraints not natively enforced by the grammar). The same mechanism applies to tool-call arguments (strict tool use), guaranteeing correct tool names and input fields.

Problem solved

Freely generated LLM text is often inconsistent with the expected format: fields are missing, types are wrong, out-of-vocabulary enum values appear, or the JSON is syntactically invalid. This forces expensive error-handling parsers, retries, and application-side validation. Structured Outputs removes this problem by guaranteeing the output satisfies the schema, which simplifies machine-to-machine integrations, tool calls, and agentic workflows.

Components

JSON SchemaInput contract defining the allowed output format.

A declarative description of the desired output structure (types, required fields, enums, nesting).

INStandard JSON Schema with a restricted subset of features.
OUTInput to the grammar compiler.
Grammar compilerProduces the artifact that steers decoding; the result is cached.

Transforms the JSON Schema into a context-free grammar or finite-state machine plus an index over the model vocabulary.

INInput schema.
OUTCompiled grammar used for masking.

Official

Constrained decoderEnforces schema conformance during sampling.

At each generation step applies a mask to the logits, zeroing tokens that would violate the grammar.

INDistribution over the vocabulary and the current automaton state.
OUTThe selected schema-valid token.
Validator / parserSafety layer and mapping to application types (e.g. Pydantic, Zod).

On the SDK side deserializes the output and validates it against the original schema, including constraints not enforced by the grammar.

INTextual model output.
OUTA validated, ready-to-use object.

Official

Implementation

Implementation pitfalls
Schema-forced hallucinationsMedium

When the input does not match the schema, the model may fabricate values to fill required fields.

Fix:Add optional fields or an “unknown”/refusal field; validate data plausibility on the application side.
Truncation at the token limitHigh

Hitting max_tokens stops generation, yielding incomplete JSON despite the constraints.

Fix:Set a sufficiently high token limit and handle the length-stop case.
Unsupported schema featuresMedium

Numeric constraints (minimum/maximum), string lengths, regex patterns, recursive schemas, and external $ref are typically dropped or rejected.

Fix:Enforce these constraints in client-side validation (SDKs do this automatically).
Grammar compilation latencyLow

The first request with a new schema incurs extra grammar compilation cost.

Fix:Rely on the grammar cache (e.g. 24h in Claude) and keep schemas stable.
Prompt cache invalidationLow

Changing the output format can invalidate the prompt cache for a thread, raising cost.

Fix:Avoid changing the format within the same thread unnecessarily.
Over-constraining vs reasoning qualityMedium

An overly rigid schema can degrade answer quality by removing room for step-by-step reasoning.

Fix:Add a reasoning/rationale field or separate the reasoning step from the formatting step.

Evolution

Original paper · 2023 · arXiv 2023 · Brandon T. Willard
Efficient Guided Generation for Large Language Models
Brandon T. Willard, Rémi Louf
2023
GBNF grammars in llama.cpp

Open implementation of grammar-constrained sampling for open-weight models.

2023
Guided-generation paper published (Outlines)
Inflection point

Willard and Louf formalize guided generation as finite-state machine transitions with an index over the vocabulary, enabling efficient constrained decoding.

2024
OpenAI introduces Structured Outputs in the API
Inflection point

On 6 August 2024 OpenAI ships Structured Outputs for gpt-4o-2024-08-06 with a strict: true option and a json_schema format, guaranteeing schema conformance.

2025
Anthropic adds Structured Outputs in Claude

Claude exposes JSON outputs (output_config.format) and strict tool use, with grammar compilation cached for 24 hours.

Hyperparameters (configurable axes)

Strict mode (strict)Critical

Enables guaranteed schema validation (e.g. for tool calls).

trueEnforces schema conformance.
falseBest-effort behavior without guarantees.
Additional propertiesHigh

Must be set to false to forbid fields outside the schema.

falseRequired by most implementations.
Required fieldsHigh

List of fields whose presence is guaranteed in the output.

["name","email"]All listed fields will appear in the result.
Output format typeMedium

Selection of the structured output mode (e.g. json_schema).

json_schemaOutput conforming to the provided JSON Schema.

Computational complexity

Time complexity: O(1) na token (amortyzowane, z prekompilowanym indeksem FSM). Space complexity: O(|Q| · |V|).

Compute bottleneck

Grammar compilation and logit masking

The first request incurs grammar compilation cost; every decoding step adds computing and applying the logit mask.

Depends on
Złożoność schematuRozmiar słownika

Execution paradigm

Primary mode
Conditional

A decoding-time technique layered on an existing model; it does not change model weights or architecture.

Activation pattern
Input dependent
Additional modes
Dense
Routing mechanism

No expert routing; the “conditional” aspect refers to schema- and prefix-dependent token masking.

Parallelism

Parallelism level
Sequential

Grammar compilation and index construction can be parallelized offline.

Scope
InferenceAcross tokens
Constraints
!A token’s mask depends on the already-generated prefix, so decoding steps are inherently sequential.

Hardware requirements

Primary

Constrained decoding is a layer over any inference engine; it works regardless of the accelerator type.

Good fit

In practice it works alongside GPU LLM inference; efficient backends (e.g. XGrammar) minimize masking overhead.