Constrained decoding forces a model to emit text that fits a grammar. At each step, the engine masks every token that would break the grammar, then samples from what is left. That gives you valid shape every time, but not correct content, so you still need tests.
Most teams first meet structured output as a prompt that says "reply in JSON." It works most of the time. Then one reply in a few hundred has a stray comment, a missing brace, or a key spelled wrong, and a parser crashes at 2 a.m.
Constrained decoding fixes the shape problem at the source. It does not ask the model to behave. It removes the option to misbehave, one token at a time. This guide explains how that works, where it stops helping, and how to test it.
If you are deciding between a schema in the response format and a tool call, read our guide to structured outputs vs function calling first. That page covers the lifecycle choice. This page covers the engine under the hood: masks, state machines, grammars, limits, and failure modes.
What constrained decoding means
Constrained decoding is a change to the sampling loop. At each step, the engine finds the tokens that would keep the output valid under a grammar. It blocks all other tokens. The model then samples from the tokens that are left.
A normal LLM picks each token from its whole vocabulary. Most of the time it picks a token that fits your format, because it was trained on lots of JSON. But "most of the time" is not "every time." A prompt only shifts the odds. A mask sets the odds of bad tokens to zero.
The rules can take several forms. You can give a fixed list of choices, a regular expression, a JSON Schema, or a full context free grammar. All of them reduce to the same question at each step: given what has been written so far, which next tokens are still legal?
Key terms
- Token: a chunk of text the model emits in one step. It can be a full word, part of a word, or a run of symbols like
":". - Logits: the raw scores the model gives each token before sampling.
- Mask: a filter that sets the score of banned tokens to minus infinity, so they can never be picked.
- Grammar: a formal set of rules that says which strings are valid.
- JSON Schema: a standard way to describe the keys, types, and limits of a JSON document. The current version is 2020-12, and the spec is split into Core and Validation parts.
The mask and sample loop, with a worked example
The loop has four moves per token. Read the grammar state, compute the mask, apply the mask to the logits, and sample. Then update the state with the token you picked.
Here is the loop in plain steps:
- Start in the grammar's first state.
- Ask the model for logits over the whole vocabulary.
- Ask the grammar which tokens are legal from this state.
- Set the logit of every other token to minus infinity.
- Sample a token from what is left, using your normal temperature and top p.
- Move the grammar to its next state using that token.
- Stop when the grammar reaches an end state, or when the token limit hits.
A small worked example
Suppose your schema allows only this: an object with one key, "status", whose value is one of "ok", "retry", or "fail". The output must look like {"status":"ok"} or one of the other two.
At step one, the only legal first piece is {. Even if the model gives 90 percent odds to the word "Sure" (an illustrative number, not a measured one), that token is masked. Only tokens that start with { survive. If the vocabulary has a token for {" as one piece, that one is legal too.
Later, after {"status":", the legal set is small. Only tokens that are a prefix of ok", retry", or fail" survive. Suppose, as illustrative arithmetic, the model scores them like this before the mask: "ok" at 0.50, "retry" at 0.20, "fail" at 0.10, and all other tokens at 0.20 in total. After the mask, the 0.20 for other tokens is gone. The engine renormalizes the rest: 0.50 / 0.80 = 0.625 for ok, 0.20 / 0.80 = 0.25 for retry, and 0.10 / 0.80 = 0.125 for fail.
Two things follow from this arithmetic. First, the model's own ranking among legal options is kept. Second, the shape is now certain, because the illegal mass went to zero. What the mask cannot do is make "ok" the right answer. It only makes sure the answer is one of the three.
Why tokens make this hard
The grammar speaks in characters. The model speaks in tokens. A single token can hold several characters, like ":" or "},{". So for each token the engine must ask: if I append these characters, does the result still fit the grammar?
Done naively, that means checking every token in a vocabulary of tens of thousands, at every step. That is slow. The rest of the field is mostly about making this check cheap.
Finite state machines for regex and JSON Schema
For a regular expression, the legal next tokens depend only on the current state of a finite state machine. That lets you build an index ahead of time, so each step is a lookup instead of a scan.
The Outlines paper by Willard and Louf, Efficient Guided Generation for Large Language Models, framed this clearly. It showed that the problem of neural text generation can be recast in terms of transitions between the states of a finite state machine. That framing allows the construction of an index over a language model's vocabulary.
The idea is simple once you see it. A regex compiles to a finite state machine with a fixed set of states. For each state, you can work out ahead of time which tokens lead to a valid next state. Store that as a map from state to allowed tokens. At run time, you look up the current state and get the mask at once.
The paper says the approach is model agnostic and adds little overhead to the token sequence generation process. Model agnostic matters in practice. The same index works with any model that shares the tokenizer, so you build it once per schema and tokenizer pair.
How JSON Schema fits in
A JSON Schema with fixed keys, simple types, enums, and bounded strings can be turned into a regular expression. That regex then becomes a state machine. This is why tools in this family can enforce a schema at low cost per token.
The limits show up with nesting and recursion. A regex cannot count open brackets to any depth. A schema that allows a tree of nodes, each with children of the same type, needs more than a finite state machine. That is where context free grammars come in.
Cost of building the index
The index is built before the first token. For a small schema, that build is quick. For a large schema with many keys and enums, the build can take real time, and you pay it on the first call.
This is a practical design point. Cache the compiled index by schema hash and tokenizer. Warm the cache at deploy time for the schemas you know about. Then the first user request does not pay the build cost.
Context free grammars and fast grammar engines
A context free grammar can describe nested and recursive shapes that a regex cannot. The cost is that the engine must track a stack, and the legal token set can depend on that stack, which makes masks harder to precompute.
GBNF in llama.cpp
llama.cpp has its own grammar format. Its grammar guide says GBNF (GGML BNF) is a format for defining formal grammars to constrain model outputs in llama.cpp. You write rules like root ::= ... and pass the file with a grammar flag.
GBNF looks like classic BNF with some regex style extras. You name rules, list options with a pipe, and use ?, *, and + for repeats. You can write a grammar for JSON, for SQL, for a chess move list, or for a tiny command language.
The same guide warns about a speed trap. Writing x? x? x? many times to allow up to N repeats may result in extremely slow sampling. Instead, you can write x{0,N}. Small grammar style choices like this can change speed a lot.
llama.cpp also supports converting a subset of JSON Schema to GBNF. That is handy, but read the fine print. The guide states that unsupported features are skipped silently. So a schema keyword you rely on may simply vanish from the grammar, and you will not get an error. The guide advises using the Python converter to see warnings and testing the grammar against sample strings.
XGrammar and the precheck trick
The XGrammar paper targets the cost of grammar checks. It notes that executing a context free grammar requires going through several stack states over all tokens in the vocabulary during runtime, which brings non-negligible overhead.
XGrammar's key move is to split the vocabulary in two. Context independent tokens can be prechecked, because their legality does not depend on the stack. Context dependent tokens need to be interpreted during runtime. In a typical grammar, most tokens fall in the first group, so most of the mask is ready before decoding starts.
The paper adds a fast persistent stack for the runtime checks. It also co-designs the grammar engine with the inference engine, so grammar work overlaps with GPU work. The authors report up to 100x speedup over existing solutions in their tests. Treat that as their reported result on their setup, not a number you will see on yours.
Where the cost shows up
Grammar cost shows up in three places. There is compile time per schema, mask time per token, and any stall while the GPU waits for the mask. A fast engine cuts the second and hides the third behind GPU work.
For you, this means two things. Cache compiled grammars. And measure time per output token with and without the grammar on your own model and hardware, because the overhead depends on schema shape.
Benchmark evidence from JSONSchemaBench
This benchmark is the best public look at how engines behave on real schemas. It shows that "supports JSON Schema" means different things in different engines, so you should test your own schemas.
The JSONSchemaBench paper notes that constrained decoding frameworks have standardized around JSON Schema as a structured data format. It also says there was poor understanding of how well these methods work in practice. To fix that, the authors built a benchmark of 10K real-world JSON schemas.
They evaluate six frameworks: Guidance, Outlines, Llamacpp, XGrammar, OpenAI, and Gemini. They score them on three critical dimensions: efficiency in generating constraint compliant outputs, coverage of diverse constraint types, and quality of the generated outputs. They also pair the set with the official JSON Schema Test Suite.
What to take from it
The lesson is not "engine X wins." Rankings depend on the schema mix, the version of each engine, and your hardware. The lesson is that coverage, speed, and quality are separate axes. An engine can be fast and still skip a keyword. Another can cover more keywords and be slower to compile.
So build your own small bench. Collect the real schemas your product uses. Run each through every engine you might deploy. Record three things for each: did it compile, how long did it take, and did the output pass a strict validator. That is the same shape as JSONSchemaBench, at the scale of your product.
JSON mode versus strict structured outputs in the OpenAI API
JSON mode promises valid JSON. Strict structured outputs promise JSON that matches your schema. OpenAI's own guide recommends the strict form when the model supports it.
The OpenAI Structured Outputs guide puts it plainly: while both ensure valid JSON is produced, only Structured Outputs ensure schema adherence. JSON mode will not guarantee the output matches any specific schema, only that it is valid and parses without errors.
JSON mode has a trap of its own. You must tell the model to produce JSON in a message. If you do not, the guide says the model may generate an unending stream of whitespace until it reaches the token limit. The API will throw an error if the string "JSON" does not appear somewhere in the context.
For prompt tactics with plain chat models, see how to get JSON output from ChatGPT. That guide is about prompts. Strict mode is about the decoder.
The supported schema subset
Strict mode supports only a subset of JSON Schema. These rules come from the OpenAI guide, and they shape how you write schemas:
additionalProperties: falsemust always be set in objects.- All fields must be listed as required. To make a field optional, use a union type with
null. - The root of the schema must be an object, and must not use
anyOf. - A schema may have up to 5000 object properties total, with up to 10 levels of nesting.
- A schema may have up to 1000 enum values across all enum properties.
- Some keywords are not yet supported, such as
allOf,not,dependentRequired, anddependentSchemas.
The optional field rule surprises people. In strict mode, every key appears in the output. A missing value is a null, not a missing key. Your parser and your database layer should expect that.
Key order also matters. The guide says outputs are produced in the same order as the keys in the schema. That fact is the basis of the reasoning fix later in this guide.
Refusals
A model can still refuse a request in strict mode. When it does, the output does not follow your schema. Instead, the API response includes a separate refusal field.
The guide says Structured Outputs constrains completed, non refusal model output to your schema. Your application still needs to handle refusals, incomplete responses, and API errors. So your code needs a branch for refusals: check the field, show or log the message, and do not try to parse it as your object.
Truncation at max tokens
Truncation is the quiet failure. If the output runs out of tokens before the last closing brace, the JSON will not parse. Strict mode cannot help here, because the decoder was stopped from outside.
The OpenAI example code checks for this. It looks for a response status of incomplete with the reason max_output_tokens and raises an error. Copy that pattern. Check status first, then parse.
Here is illustrative arithmetic for sizing the limit. Suppose a record with 12 fields averages 18 tokens per field, plus 30 tokens of braces and keys. That is 12 × 18 + 30 = 246 tokens. If you also have a reasoning field that averages 300 tokens, you need about 546. A cap of 512 would cut off a share of replies. Set the cap from the tail of your measured lengths, not the mean.
First call latency
The guide notes one more cost. For fine tuned models, the first request with any new schema has extra latency while the API processes the schema. Later calls with the same schema do not. If you use fine tuned models, warm each schema once before real traffic.
Format limits and reasoning quality
Strict formats can make models reason worse. The usual fix is to give the model a free text field for reasoning and put it before the answer field, so the model thinks before it commits.
The study Let Me Speak Freely? tested this directly. It compared answers under structured formats with free form answers across common tasks. The authors report a significant decline in reasoning abilities under format restrictions. They also found that stricter format constraints generally lead to greater degradation in reasoning tasks.
Why might that happen? One plausible reading is about order. If the schema makes the model write "answer": ... first, the model must commit before it has worked through the problem. Another is that a tight format pulls the model's output away from the style it learned during training. The paper reports the effect. The exact cause is still a matter of study.
The field order fix
Because strict mode writes keys in schema order, you control what the model writes first. Put a reasoning field at the top and the answer at the bottom:
{
"type": "object",
"properties": {
"reasoning": { "type": "string" },
"answer": { "type": "string", "enum": ["approve", "reject", "escalate"] }
},
"required": ["reasoning", "answer"],
"additionalProperties": false
}
Now the model writes its working first, as free text inside a string. Then it fills the enum. The answer is still constrained, but it is no longer forced out before the thinking.
This is not free. A reasoning field adds tokens, which adds cost and time. It also raises the risk of truncation, as the arithmetic above shows. So test both orders on your own task. Measure accuracy and tokens for answer first versus reasoning first, and keep the one that earns its cost.
Two step as an option
Another option is two calls. The first call is free form and lets the model reason. The second call uses a strict schema to extract the answer from the first call's text. That costs an extra call, but it keeps the reasoning step free of any format limit.
A two step flow pairs well with a cascade. A small local model can do the cheap extraction step, while a larger model does the reasoning only when needed. Our guide to LLM cascades with local models and frontier escalation covers that routing pattern.
Valid shape is not correct content
A schema checks shape. It does not check truth. Constrained decoding guarantees the first and says nothing about the second.
OpenAI's guide says it directly: Structured Outputs can still contain mistakes. The mask makes sure a price field holds a number. It does not make sure the number is the price on the invoice. It makes sure a date matches a pattern. It does not make sure the date is real or the right one.
In fact, a mask can hide a problem. Without a mask, a confused model might write "I could not find a total." That is a clear signal. With a strict schema that needs a number, the same model must write some number. The schema turned a visible failure into a quiet wrong value.
Design schemas that leave room for "unknown"
Give the model a legal way to say it does not know. Make a field nullable. Add an enum value like "not_found". Add a confidence field or a flag that the input was off topic. These are cheap, and they stop the schema from forcing a guess.
Check meaning in code
After parsing, run checks the schema cannot express:
- Cross field rules, such as the line items summing to the total.
- Lookups, such as the customer ID existing in your database.
- Source checks, such as the quoted text actually appearing in the input.
- Range checks tied to context, such as a ship date after the order date.
For more on catching wrong but well formed answers, see our page on structured output from LLMs and our guide to grounding prompts to reduce hallucination.
Schemas change over time
Your schema will change. A new field, a renamed enum, a stricter type. Each change can break old consumers or shift model behavior. Treat the schema as a versioned contract and test each change. Our guide to testing AI output when schemas change walks through that process.
Self hosted options in vLLM and llama.cpp
If you run your own models, vLLM and llama.cpp both offer constrained decoding. vLLM exposes it through its OpenAI style API with several modes. llama.cpp uses GBNF grammars and a JSON Schema converter.
vLLM
The vLLM structured outputs docs say vLLM supports structured outputs using xgrammar or guidance as backends. Through the Completions and Chat APIs, it accepts these options as extra parameters:
choice: the output will be exactly one of the choices.regex: the output will follow the regex pattern.json: the output will follow the JSON schema.grammar: the output will follow the context free grammar.
Pick the narrowest mode that fits. A label task should use choice, not a JSON object with one enum key. A phone number or ID should use regex. Use json for records and grammar for small languages like a query syntax.
vLLM also has settings for reasoning models. By default, the structure applies to the final output. The docs show a server flag, --structured-outputs-config.enable_in_reasoning=True, for enforcing structure inside the reasoning part too. Most teams will want the default, which leaves the thinking free and constrains the answer. That lines up with the reasoning first advice above.
llama.cpp
For llama.cpp, you can pass a GBNF file, or pass a JSON Schema and let it convert. The server takes a schema through a json_schema field on completion endpoints, or inside response_format for chat completions.
Mind the gaps listed in the guide. Unsupported features are skipped silently. The guide also lists items like nested refs, some string formats, and patternProperties as broken or missing. Run the Python converter, read its warnings, and test the grammar on known good and bad strings before you trust it.
Same schema, different engines
A schema that works in one engine may fail or be weakened in another. That is the main lesson from JSONSchemaBench, and it matters most when you mix providers. If you run a local model for cheap calls and a hosted model for hard ones, keep a schema subset that every engine in your stack handles the same way.
A decision table for picking a method
Pick the lightest method that meets your need for shape, given where the model runs. Use prompt only for drafts, JSON mode for old models, strict schema for hosted production, and a local grammar when you run the model yourself.
| Method | Shape guarantee | Best for | Main risk | Extra work |
|---|---|---|---|---|
| Prompt only ("reply in JSON") | None. Odds only. | Drafts, quick tests, human readers | Parse errors in a small share of replies | Parser with retries |
| JSON mode | Valid JSON, no schema | Older models without strict support | Wrong keys or types; whitespace runs if "JSON" is missing from the prompt | Validator plus retries |
| Strict schema (hosted) | Matches the supported schema subset | Production extraction and classification on hosted APIs | Refusals, truncation, unsupported keywords, wrong values | Refusal and status checks, business rule checks |
| Local grammar (GBNF, vLLM, Outlines, XGrammar) | Matches your grammar, within engine coverage | Self hosted models, custom formats, regex and choice tasks | Silent skipping of keywords, compile cost, speed traps | Grammar tests, caching, timing |
Rules of thumb
- If a human reads the output, prompt only is often fine.
- If code reads the output and the model supports it, use a strict schema.
- If the task is a single label, use a choice or enum, not a free string.
- If the task needs reasoning, put the reasoning field first or split into two calls.
- If you mix engines, test the same schema on each one.
If your prompts are compiled or tuned with a tool, the schema becomes part of what you tune against. Our guide to prompt compilation with DSPy shows how typed signatures and metrics fit with structured outputs.
Implementation and test procedure
Treat the schema as code. Write it once, check it against each engine, warm the cache, wire up refusal and truncation checks, and keep a test set that runs on every change.
Step by step
- Define the schema in one place. Use a typed model in your language, like Pydantic or Zod, and generate the JSON Schema from it. This keeps code and schema in sync.
- Fit the schema to the engine subset. Set
additionalPropertiesto false. Mark all fields required and use null unions for optional ones. Keep nesting shallow. Avoid keywords your engine skips. - Order the keys on purpose. Put reasoning or evidence fields first and the final decision last.
- Leave room for unknown. Add nullable fields or an explicit "not found" value.
- Pick the narrowest mode. Choice for labels, regex for IDs, schema for records, grammar for custom languages.
- Set the token cap from data. Measure output length on a sample and set the cap above the high tail.
- Handle every exit path. Check for refusal, check for incomplete status, catch API errors, then parse.
- Validate again after parsing. Run a strict JSON Schema validator in your own code. It catches engine gaps and silent skips.
- Run business rule checks. Cross field sums, lookups, and source checks.
- Log and count. Record refusals, truncations, validator fails, and rule fails per schema version.
Building the test set
Collect 50 to 200 real inputs per schema. Include easy cases, edge cases, and inputs that should produce "unknown" or a refusal. Write the expected output for each, or at least the expected values for key fields.
Run the set on each engine and model you might use. For each run, record five numbers: compile success, time per output token, schema pass rate under an outside validator, field accuracy against your labels, and truncation count. Compare constrained runs with unconstrained runs on the same inputs. That tells you what the mask buys and what it costs on your task.
Here is an illustrative way to read the results. Suppose the prompt only run gives 194 parseable outputs out of 200, and the strict run gives 200. Suppose field accuracy is 176 of 200 for prompt only and 171 of 200 for strict with answer first. In that made up case, strict fixed shape but cost some accuracy, which is the pattern the format restriction study warns about. The next test would be strict with reasoning first.
Regression on change
Rerun the test set on every schema change, prompt change, model change, and engine upgrade. Engines change their coverage between versions. A keyword that was skipped may start to work, or the reverse. Pin engine versions in production and upgrade on purpose.
Failure modes and how to detect them
Most failures fall into a short list. Each one has a clear signal you can log. Watch these and you will catch nearly every structured output problem before users do.
Truncation
What happens: the output stops before the JSON closes. How to detect: the response status is incomplete with a max token reason, or the parser fails at the end of the string. Fix: raise the cap, shorten the reasoning field, or split the task.
Refusal
What happens: the model declines and the output does not follow your schema. How to detect: the refusal field is set. Fix: route to a fallback path, show a safe message, and log the input for review.
Silent schema weakening
What happens: the engine drops a keyword it does not support, so the output passes the engine but breaks your rules. How to detect: run a full validator in your own code after parsing. Fix: rewrite the schema in the supported subset, or enforce the rule in code.
Forced guesses
What happens: the schema has no way to say "unknown," so the model fills a value anyway. How to detect: spot checks show confident values on inputs that lack the data. Fix: add nullable fields or a "not found" enum value.
Reasoning loss
What happens: accuracy drops when you add a strict format. How to detect: compare field accuracy with and without the format on the same test set. Fix: reasoning field first, or a two step flow.
Whitespace runs in JSON mode
What happens: the model emits whitespace until the limit. How to detect: long outputs with no content and high token counts. Fix: say "JSON" in the prompt, or move to strict mode.
Slow grammars
What happens: time per token jumps with a certain grammar. How to detect: time per output token by schema. Fix: rewrite repeats as bounded ranges like x{0,N}, cache compiled grammars, or switch to a faster backend.
Tokenizer drift
What happens: a compiled index built for one tokenizer is reused with another model. How to detect: odd masks, compile errors, or output that stalls. Fix: key the grammar cache by schema hash and tokenizer, never by schema alone.
Checklist before you ship
Run through this list for each schema before it goes to production. It takes minutes and covers the failures that cost the most.
- The schema lives in one typed source and is generated, not hand copied.
additionalPropertiesis false and every field is required, with null unions for optional data.- Nesting depth and enum counts are inside your engine's limits.
- No keyword your engine skips is carrying a business rule.
- Reasoning or evidence fields come before the final answer field.
- There is a legal way to say "unknown" or "not found."
- The narrowest mode is used: choice, regex, schema, or grammar.
- The token cap is set from measured lengths, with room for the tail.
- Code checks refusal and incomplete status before parsing.
- A strict validator runs after parsing, in your own code.
- Business rules run after validation.
- A test set of real inputs runs on every schema, prompt, model, or engine change.
- Compiled grammars are cached by schema and tokenizer, and warmed at deploy.
- Logs count refusals, truncations, validator fails, and rule fails per schema version.
Constrained decoding is one of the few tools in LLM work that turns a "usually" into an "always." Use it for shape. Then spend the time you saved on parse errors where it matters more: checking that the values are right.
Frequently asked questions
What is constrained decoding in an LLM?
Constrained decoding is a way to make a model follow a set of rules while it writes. Before each token is picked, the engine checks which tokens would still fit the grammar or JSON Schema. It blocks the rest by setting their odds to zero. The model then samples only from the allowed tokens. The result always fits the shape you asked for.
How does JSON mode compare with strict schema enforcement?
JSON mode only promises that the output is valid JSON that parses. It does not check your keys, types, or enums. Strict structured outputs bind the output to the JSON Schema you send, so required keys and enum values are kept. OpenAI's own guide says both give valid JSON, but only Structured Outputs ensure schema adherence. JSON mode also needs the word JSON in your prompt.
Does forcing JSON output make the model reason worse?
It can. A 2024 study called Let Me Speak Freely found a clear drop in reasoning when models had to answer in strict formats, and the drop grew as the format got stricter. A common fix is to put a free text reasoning field first in the schema and the final answer field last. The model then thinks before it commits to the answer.
Is schema-valid output the same as correct output?
No. A schema checks shape: keys, types, enums, and some ranges. It cannot tell if a price is the real price, if a date is the right date, or if a name exists in your database. OpenAI's guide states that structured outputs can still contain mistakes. You still need checks in code for business rules and facts that the schema does not express.
What happens when a structured output hits the max token limit?
The output is cut off before the closing braces, so it will not parse, even with strict mode on. In the OpenAI Responses API the response status is incomplete and the reason is max_output_tokens. Your code should check that status before parsing, then either retry with a higher limit or a smaller task, and log the event so you can tune limits.
Which engines do constrained decoding for local models?
llama.cpp uses GBNF grammars and can turn a subset of JSON Schema into GBNF. vLLM offers structured outputs through xgrammar or guidance backends, with choice, regex, json, and grammar options. Outlines builds finite state machine indexes over the vocabulary. XGrammar is a fast engine for context free grammars that prechecks most tokens ahead of time.
Why do some JSON Schema features fail with constrained decoding?
Each engine supports only part of JSON Schema. OpenAI requires additionalProperties false, a root object, and caps nesting at 10 levels. llama.cpp skips unsupported features without an error. OpenAI's docs list composition keywords it does not yet support: allOf, not, dependentRequired, dependentSchemas, if, then, and else. For fine-tuned models it also drops minLength, maxLength, pattern, format, minimum, maximum, multipleOf, patternProperties, minItems, and maxItems. JSONSchemaBench was built to measure this kind of coverage gap across six engines with real schemas.
Sources
- OpenAI Structured Outputs guide: JSON mode versus Structured Outputs, supported schema subset, limits, refusals, and incomplete responses.
- Efficient Guided Generation for Large Language Models (Outlines): Recasts guided generation as finite state machine moves with a vocabulary index.
- XGrammar: Flexible and Efficient Structured Generation Engine: Splits tokens into prechecked and runtime sets to speed up context free grammars.
- Let Me Speak Freely? Format Restrictions and LLM Performance: Reports reasoning loss under strict output formats.
- JSONSchemaBench: A Rigorous Benchmark of Structured Outputs: 10K real world schemas used to test six constrained decoding frameworks.
- vLLM Structured Outputs docs: Backends, choice, regex, json, and grammar options, and reasoning settings.
- llama.cpp GBNF grammar guide: GBNF syntax, JSON Schema conversion, and known gaps.
- JSON Schema specification: Current version 2020-12, split into Core and Validation.
sinc-LLM