Structured and schema-constrained generation.

Free text goes in. A record that always fits the shape comes out. Here is the field that makes a model speak data, not just prose.

A language model writes one word at a time, in prose. That is wonderful for talking to a person and a problem for talking to software. Structured generation is how the field closes that gap: it constrains what the model is allowed to say next, so the output is guaranteed to fit a required shape. We walk it the way the field is built: what it is, why it is hard, how it works, what it unlocks, and where it is going. The papers behind each idea are linked, so you can read the source yourself.

From a sentence to a record
“Northwind, forty thousand. It hasn’t been approved yet.”
Required fieldsText · number · boolean
{
  "company": "Northwind",
  "amount": 40000,
  "approved": false
}
✓ The fields and value types match the schema
A defined schema gives software a predictable record to read. Correct structure is separate from checking whether the facts are right.

Making a model's output fit a required shape on purpose.

Not by luck and not by asking nicely. The shape is named up front as a schema or grammar, and the output is held to it.

A model writes prose for people. Software needs fields. Structured generation is the bridge that turns "writes for a human" into "returns data a program can read." You hand it a schema, a description of the valid form: these fields, these types, this layout. As the model writes, anything that would break the schema is simply not allowed.

Keep two jobs separate, because the rest of the page leans on the distinction. The shape is enforced by the system. The content, the actual values, is still the model's judgment. The constraint comes in degrees, from loose to strict: a regular expression is a pattern, a JSON schema names fields and types, a context-free grammar (Geng et al., 2023) can describe a whole formal language such as SQL. Across this page we follow one running example: pulling a clean record out of a messy sales call. The model reads the transcript. The schema guarantees the record comes back in a fixed, readable shape.

A schema constrains shape, not factual truth

Schema

amount: number
currency: string
due_date: string or null

Output

{
  "amount": 40000,
  "currency": "USD",
  "due_date": null
}
A structurally valid record still needs evidence for its values. Null can express a missing value when the schema permits it.

"Sounds right" and "parses" are not the same thing.

A fluent sentence is easy for the model and unusable for a program that expects exact fields. Closing that gap reliably is the whole problem.

Prose is not data

A program needs exact fields.

"The deal is worth about forty thousand and closes next month" is fine for a person and useless to software. The receiving program needs a name, an amount, and a date, in an exact shape, or it breaks.

Prompting is not a guarantee

"Please reply in JSON" raises the odds, no more.

Asking for a format does not ensure it. One stray word, a trailing comma, an unclosed bracket, and the parser fails. At scale, "usually valid" still means a steady stream of breakages.

Shape is not truth

A record can be well-formed and still wrong.

Structure enforcement fixes the shape, not the truth of the values. Valid JSON does not mean a correct answer. We keep these as two separate guarantees so the page never overclaims.

Real targets are rich

More than checking brackets.

A JSON schema can require enums, nested objects, and required fields. A grammar can describe a whole formal language. Enforcing those exactly, token by token, is real work.

Enforcement can cost speed

Checking the rules at every step adds up.

Validating each next token against the schema can add overhead unless the work is precomputed. This is a real engineering axis, not a footnote, and the field measures it.

Constraining can shift behavior

A format can change the answer.

A growing body of work, including Tam et al. (2024), reports that how a format is imposed can affect reasoning quality on some tasks. Honest pages name this.

It all hangs on one choke point.

A model writes one token at a time, scoring every option in its vocabulary. Control what is allowed at each step, and you control the output's shape.

  1. 01Score

    Model predicts candidate tokens.

  2. 02Constrain

    Exclude invalid continuations.

  3. 03Select

    Choose a valid token.

  4. 04Advance

    Update the parser state and repeat.

Constrained decoding is a filter on the next word: block what breaks the shape, let the model choose the rest.

1The next-word filter

Hide the options that would break the shape.

Before the model picks, the system masks out every option that would violate the schema, setting those scores to effectively zero so they cannot be chosen. The model samples only from the survivors. The output stays valid by construction, not by hope.

A worked example. After the model has written {"amount": and the schema says amount is a number, the filter allows digit tokens and blocks letters, quotes, and brackets. The model still decides which number. The shape is not up for negotiation. That is the clean early lesson of PICARD (Scholak et al., 2021): constrain the decoder, not just the prompt.

Restrict the next token to valid continuations
{"amount":

Allowed in this simplified numeric state

407-

Blocked in this state

forty]
The decoder masks tokens that cannot extend the current output into a valid structure. Real token vocabularies contain more than single characters.

2How the shape is described

From a pattern to a whole language.

The constraint comes in degrees. A regular expression captures a simple pattern, a date or a phone number. A JSON schema names fields and types. A context-free grammar describes a full language such as SQL or a programming language. The richer the description, the richer the structure you can guarantee.

The unifying view from Geng et al. (2023): a wide range of structured tasks, extraction, disambiguation, parsing, can be expressed as "generate something that fits this grammar." That makes structure a single, reusable framework rather than a one-off trick per task.

Choose the right formal description
ConstraintWhat it describes
PatternA limited string shape, such as a date-like format.
JSON SchemaObject fields, types, and other supported constraints.
GrammarAllowed syntactic structures of a language.
Syntactic validity has limits: matching a date pattern does not prove that the date exists or is correct.

3Turning a grammar into a fast filter

Valid output is a path through a set of states.

The reframing that made this practical: treat valid output as a path through a state machine. Willard and Louf (2023), the work behind the Outlines library, showed you can compile a regular expression or grammar into a finite-state machine and build an index over the model's vocabulary ahead of time. So at each step, the set of allowed tokens is a quick lookup rather than a fresh computation. Knowing the current state tells you exactly what is allowed next.

A careful filter aims to allow every valid continuation and block every invalid one. SynCode (Ugare et al., 2024) frames this directly: keep all tokens consistent with the grammar, drop the rest, so the result is both correct and not needlessly restrictive.

Track the current parse state
{"amount":number}
Current state: numeric value

Allow valid numeric continuations or the permitted delimiter.

A grammar-aware decoder tracks which continuations remain possible after the generated prefix.

4Parsing as you go, and keeping it fast

Reject a wrong turn before it is taken.

For formal targets like SQL, an incremental parser can reject any token that could not begin a valid completion. PICARD did this for text-to-SQL, checking each step against the grammar so the model could not wander into code that would not run.

Making it fast enough to ship is its own line of work. Newer engines push the overhead down by splitting the vocabulary into tokens that can be checked ahead of time and the few that must be checked live, and by overlapping that work with the model's own computation. XGrammar (Dong et al., 2024) reports large speedups on this exact problem. That speedup is an industry finding from that paper, not a figure about any system described elsewhere on this site.

Move predictable checks out of the hot path

Prepare ahead

Work
Compile grammar state and reusable token checks.

Check per step

Work
Resolve state-dependent token validity as generation proceeds.
Efficient constraint engines cache or precompute reusable work while preserving the required grammar checks.

5A reliable tool call

A decision becomes a call a system can run.

When a model calls a tool, the call has to name the tool and fill its fields exactly. Structured generation is how "the model decided to look up an account" becomes a well-formed call a system can actually execute. The tool name and the field types are the schema. The constraint guarantees the call is shaped to run, the model still decides which account.

This is the backbone of assistants that do things, not just talk. The same machinery that returns clean JSON returns a clean function call.

Validate a structured call before execution
{
  "tool": "lookup_account",
  "arguments": {
    "company": "Northwind"
  }
}
  1. Validate

    Check tool name and argument types.

  2. Authorize

    Check whether this request may use the tool and data.

  3. Execute

    Run the approved call and return its result.

Well-formed arguments are only the first gate. Permissions and business rules still apply.

Output software can read on the first try.

At the field level: clean records and rows, reliable tool and function calls, clean extraction from messy input, fewer retries, and interfaces a team can build on.

This family of techniques is how the industry gets dependable, machine-readable output out of a model that otherwise speaks in prose. For a sales co-pilot, the bridge is at the outcome level: here is what that reliability looks like as an everyday outcome for a seller. The deep mechanism stays on this educational page.

A call turns into clean fields.

The schema does the shaping and the model does the reading, so a transcript becomes named fields in the right places, not a wall of notes. See Clean CRM.

What lands in your tools is consistent.

A guaranteed shape is a contract. Records come back in a fixed layout, consistent enough to build a process on. See After-meeting notes.

Actions are real, not guesses.

When an assistant takes an action, it is a real, well-formed action, not a guess that fails halfway. Reliable tool calls are what make that possible.

Fewer retries, simpler plumbing.

When validity is guaranteed at generation time, you remove a whole layer of "parse, fail, ask again." That is less code and fewer failure modes downstream.

This explainer covers published research. To see how AI REV Voice helps with sales conversations, explore Prism.

Guaranteeing the shape is solved. Doing it without nudging the answer is the live work.

We describe the direction the field is heading, not a roadmap of our own.

Near-zero overhead

Strict structure, essentially free.

The frontier is making guaranteed shape cost almost nothing at serving time, so there is no speed penalty for enforcing it. XGrammar and the surrounding engine work are the current direction.

Honest accounting of quality

Shape the result without bending the answer.

Studies such as Tam et al. (2024) report that how a format is imposed can affect reasoning quality. The response is constraints that let the model reason freely first and shape only the final result.

Richer targets

From flat JSON to whole languages.

From flat records toward deeply nested schemas, full grammars, and domain-specific languages, all enforced exactly, token by token.

Standard benchmarks

Measure it, do not assume it.

Work like JSONSchemaBench (Geng et al., 2025) measures conformance, overhead, and quality on real schemas, turning "it usually works" into something you can test and compare.

Shape plus correctness

Well-formed and more likely right.

The open frontier pairs guaranteed shape with checks on the content itself. Two separate guarantees: the structure is enforced, the truth of the values is a different question.

Check structure and evidence separately
CheckExample
Schema validityamount is a number
GroundingThe amount appears in the source quote
Business validationThe currency and approval rules are satisfied
Constrained generation can enforce supported structural rules. It does not establish whether a value is true or an action is appropriate.

The papers behind this page.

Keep reading.

Sibling explainers in the Research section.

Talk. Done.

That is the whole field in one promise: you talk, and clean, complete records are waiting in the right places. See it on a real call.

No app required. Just your phone number.