Structured Output Doesn't Validate LLMs. It Resamples Them
TL;DR — Constrained decoding for structured output (JSON mode, grammar-based function calling) doesn't just check a model's answer — it rewrites the model's token-by-token probability distribution in real time. That reshaping can force a model into low-probability paths it never 'wanted' to take, and once it's off-distribution, errors compound through the rest of the generation. Schema design is…
Structured output, such as JSON mode or grammar-based function calling, does not simply validate a model's answer; it actively rewrites the model's token-by-token probability distribution in real-time. This reshaping can steer a model towards low-probability paths it never intended to take, and once it strays from the distribution, errors can compound throughout the entire generation process.
Schema design is an intervention in the sampling process, not a validation layer, and treating it as free output hygiene can result in silent correctness regressions. When a model generates text under a JSON schema or grammar, it does not allow the model to freely choose at each step. Instead, at every token position, it computes the full probability distribution over the vocabulary, masks out invalid tokens, renormalizes, and samples from the remaining options.
This guarantees syntactic validity but says nothing about whether the model's desired token was part of the surviving set. If the model's top candidates are all invalid according to the grammar, it discards them all and samples from the tail of the distribution, resulting in a syntactically perfect value that the model only assigned a small probability to.
This reveals the misconception that structured output is merely a validation layer. It is actually a real-time intervention, shaping what the model says rather than just determining if it is well-formed. Most teams overlook this mechanism, leading to silent correctness regressions. Furthermore, schema order can dictate the order in which the model commits to its answers, forcing them to make decisions prematurely.
This rigid sequence prevents the model from reasoning through intermediate steps, which is crucial for extended reasoning and accurate results. The ordering in a schema acts as a prompt-engineering decision disguised as data-modeling, dictating the model's internal generation sequence. Compounding mistakes occur inside a single generation as autoregressive generation conditions every future token on everything generated so far.
If the decoder pushes the model into a low-probability value at a certain token, subsequent tokens are generated based on this forced context, not the model's original train of thought. This results in the model rationalizing around the forced commitment, making the output appear consistent but actually reflecting the branch the model was pushed into, not the one it would have chosen.
Grammar constraints and fine-tuned JSON mode are different failure modes. Hard grammar constraints guarantee syntax but can force low-probability content, while fine-tuned JSON mode prefers valid JSON but degrades gracefully in content. These failure modes require different analysis, yet most logging setups fail to capture the distinction, treating "the JSON was valid but wrong" as a single issue.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.