When a language model fills a JSON function call, a SQL query, or an extraction record from retrieved documents, very few of its output tokens are real choices. Brackets, quotes, keys, and keywords are fixed by the schema. Most of the field values are copied verbatim from the context. The model's large vocabulary, often more than 128,000 possible next tokens, behaves in practice like a small menu: the next token the grammar forces, or one of a few candidate spans in the documents. We propose to build the decoder around that menu. A drafter with no learned parameters proposes grammar-forced runs and copyable context spans as a branching tree of guesses. The large model checks the whole tree in one parallel forward pass, and the standard accept-or-reject rule of speculative decoding keeps the output distribution exactly that of the grammar-constrained model. Speculative decoding means a cheap proposer guesses several tokens ahead and the large model verifies them all at once.
The same menu turns contextual distraction from a diffuse attention problem into something we can count and fix. Contextual distraction is the drop in accuracy when irrelevant passages share the prompt. If structured outputs fail under noise mainly because the model copies the right kind of value from the wrong passage, and not because it breaks syntax, then the errors sit at a handful of "decision points" where candidate spans compete. At those points every candidate has a known source passage, so it can be re-scored. Our thesis is that one structural fact makes structured generation from noisy context both faster and easier to correct, and that this fact is invisible to methods that treat each subword token as an independent action. The fact is that the effective action space at each step is grammar-forced tokens plus context spans.
Core Claim
Write an output of length $L$ as $L = F + C + G$, where $F$ counts tokens forced by the grammar given the prefix, $C$ counts tokens inside spans copied from the context, and $G$ counts the remaining freely generated tokens. A drafter that proposes forced runs and context spans can, if acceptance is high, finish one forced run and one copied span per verification pass. Wall-clock speedup is then bounded by roughly $L / (G + n_{\text{dec}})$, where $n_{\text{dec}}$ is the number of decision points at which a span must be chosen. The bound comes from counting one target-model pass per free token and one per decision point.
We claim three things. First, for function calling, text-to-SQL, and evidence-grounded extraction, $G$ is small relative to $L$. Second, acceptance of grammar-and-context drafts stays high as distractor passages are added. A small draft language model, by contrast, loses acceptance as noise grows; the file's account of speculative decoding notes that draft models "diverge rapidly" from the target under heavy prompt noise and grammar constraints. Third, distractor-induced errors in structured outputs concentrate at decision points as wrong-source copies. That last claim answers the open question in the research file of whether noise breaks syntax or corrupts values. It also predicts that re-scoring only the enumerated candidates at those points recovers most of the accuracy lost to noise, at a fraction of the cost of processing the whole context.
The closest existing work is Constrained Decoding with Speculative Lookaheads (CDSL). CDSL drafts flat token lookaheads with a small language model, checks constraints with an external reward, and is tested only on short, clean prompts. We differ in three ways. Our drafter is the grammar automaton plus the context itself, with no second model and no tokenizer-alignment requirement. Our drafts are trees of whole spans. Our evaluation is built around distractor density.
Relation to Prior Work
The vocabulary-as-action-space literature motivates the reframing. An Actor-Critic Algorithm for Sequence Prediction and Efficient (Soft) Q-Learning for Text Generation with Limited Good Data show that treating each of tens of thousands of tokens as an action gives high-variance, sample-inefficient learning. Controlling Large Language Model with Latent Action (CoLA) responds by learning a 64-action codebook and a fine-tuned "language world model" that decodes those actions into tokens. We take the same lesson, that the effective action space is small, but get the small space for free from the grammar and the prompt rather than learning it. Doing so keeps exactness with respect to the base model, which a learned latent space cannot promise. CoLA also never touches inference latency.
The structured-decoding literature supplies the method and its constraints. Grammar masking parses the schema into an automaton and zeroes out illegal tokens at each step. Flexible and Efficient Grammar-Constrained Decoding (GREATGRAMMA) composes the tokenizer with the grammar lexer so that masks are cheap and token boundaries line up with grammar terminals. We reuse it to enumerate forced runs and to mask drafted tree nodes. Two papers constrain the design. Grammar-Aligned Decoding shows that greedy masking distorts the model's distribution. Mitigating Bias in Locally Constrained Decoding via Tractable Proposals shows that local masking can wander into dead ends. Our verification is exact with respect to the masked distribution, so we inherit that distortion rather than fix it, and we say so. Adaptive Constraint Propagation speeds up the constraint checks themselves and reports that this is orthogonal to speculative drafting. It is complementary to our work, not a competitor.
Speculative decoding supplies the verification machinery. Tree verification from Multi-Candidate Speculative Decoding and Traversal Verification for Speculative Tree Decoding, together with the exactness argument of A Theoretical Perspective for Speculative Decoding Algorithm, is what we build on. Graph-Structured Speculative Decoding finds that over 70% of tokens drafted across tree branches are duplicates. That observation fits a span drafter naturally: candidate spans share the grammar-forced prefix and suffix around a value slot. Cactus relaxes exactness for speed. We stay exact for the speed claim and keep any deliberate distribution change confined to the separate noise intervention.
The distraction literature motivates the decision-point hypothesis and supplies the scoring signal. Improving Zero-shot Reader by Reducing Distractions from Irrelevant Documents scores each document by how likely it is to generate the query and penalizes poorly matched ones (its method is called DAS). Superposition Prompting processes documents on parallel branches and prunes the irrelevant ones before answering. Aligning Extraction and Generation for Robust Retrieval-Augmented Generation (Ext2Gen) and Long-Document QA with Chain-of-Structured-Thought (LiteCoST) train models to extract evidence into an intermediate structure first. All four operate on whole passages or add output tokens. We apply the DAS-style passage score only to the source passages of competing candidate spans, only at decision points, and without generating any extra text.
Research Program
The first component is the drafter. At each step, the GREATGRAMMA automaton reports whether the next tokens are forced. If they are, the drafter emits the whole forced run. When the grammar reaches a value slot, such as a string field, an SQL literal, or a column name, the drafter indexes the context's token sequence by suffix match on the last few generated tokens and on the slot's type constraint. It then proposes the top-$k$ matching spans, each extended to the next grammar terminal. Forced runs and spans are assembled into a draft tree that is deduplicated as a directed acyclic graph in the manner of GSD and unmerged into a tree for verification. The target model verifies the tree with tree attention. Grammar masks for drafted nodes are computed on the CPU while the GPU pass runs. Acceptance follows standard speculative sampling against the masked target distribution. The result is exact under greedy decoding and exact in distribution under sampling. When no span matches, the drafter falls back to ordinary one-token decoding, so it never does worse than grammar-constrained decoding by more than its drafting overhead.
The second component is diagnosis. On each benchmark we label every output token as forced, copied, or free, and record the target model's entropy and the source passage of every copied span. We inject distractor passages at increasing density, from zero up to the 100-document regime DAS studies. For each density we separately measure syntax and schema violations, wrong values copied from distractor passages, wrong values not copied from anywhere, and draft acceptance length. This directly tests whether noise produces syntax collapse or value corruption.
The third component is the decision-point intervention. At each decision point the candidate spans and their source passages are already enumerated. We re-score each candidate by adding the log-probability of the query given its source passage, in the style of DAS, weighted by a single coefficient tuned on development data. This intervention is deliberately lossy and is reported separately from the exact speedup, together with how far its output distribution moves from the base model's.
Baselines
The naive reference point is ordinary autoregressive decoding with GREATGRAMMA masking and no speculation, on the same target model and hardware. Every speedup and accuracy number is reported relative to it. The research file reports that plain grammar-constrained decoding reaches 100% constraint satisfaction on xLAM with about 1.1x overhead Mitigating Bias in Locally Constrained Decoding via Tractable Proposals. It also reports a masking cost of 5–32 ms per token for GREATGRAMMA. We therefore expect this baseline to be syntactically perfect, so our speed and value-accuracy claims are measured against a valid-output reference.
The strongest speed competitor is speculative decoding with a small draft model from the same family under the same grammar masks. This is the CDSL setting Constrained Decoding with Speculative Lookaheads, extended with GSD-style tree drafting Graph-Structured Speculative Decoding. We also run a Cactus variant Cactus as a lossy upper reference. The reported numbers for comparison are GSD's 1.96x end-to-end speedup on GSM8K with LLaMA-2-70B and Cactus's nearly 1.9x over autoregressive decoding. CDSL's 2.2x–12.15x is measured against expensive lookahead rollouts, not plain decoding, so it is not directly comparable. We found no reported result on Lacuna for any speculative method on grammar-constrained outputs with distractor-laden contexts. That absence is the gap, so we will produce these numbers ourselves.
All speculative methods share the target model, grammar engine, maximum tree size, hardware, and an equal tuning budget over draft length and tree width. Beating them means higher tokens per target pass and higher wall-clock speedup at equal output quality. It means this at every distractor density, and in particular a speedup that does not decay as density rises while the draft model's does.
The strongest accuracy competitors under noise are DAS Improving Zero-shot Reader, Superposition Prompting Superposition Prompting, and Ext2Gen-style extract-then-generate Aligning Extraction and Generation. The reported reference numbers are DAS's 231% relative gain on SQuAD with 100 retrieved documents, and Ext2Gen-R2's average QA score of 0.557 against 0.473 for the default Llama3.1-8B on HotpotQA and MS-MARCO. Each is run with the same retrieved sets and the same schema constraint. Beating them means matching or exceeding their value accuracy at lower total latency.
Two ablations isolate the key ingredient. The first is a forced-run-only drafter that drafts grammar-forced tokens but no context spans. It separates the contribution of the grammar from that of the context. The second is a span drafter whose spans are drawn at random from the context, matched in count and length, which tests whether suffix matching matters.
Why not just…?
Why not just skip grammar-forced tokens and decode everything else normally? This is the real threat to the speed claim. If $C$ is small, or copied spans are rarely accepted, forced-run skipping alone will capture nearly all the gain, and our contribution shrinks to something mostly already known. The forced-run-only ablation settles it. We will report the speedup gap between it and the full drafter per benchmark, along with the measured $F/L$ and $C/L$ fractions. If the gap is negligible on function calling and SQL, we will narrow the claim to extraction-heavy tasks or drop it.
Why not just use a small draft model with grammar masking? It is the standard method and it is exact. The file's own account of speculative decoding notes that small drafters diverge from the target under heavy prompt noise and complex grammars, and masking the drafter adds per-token cost (5–32 ms in GREATGRAMMA) that eats into the reason for using a small model. A copy-based drafter has no parameters and reads the same noisy context the target reads. The experiment that shows the difference is acceptance length plotted against distractor density for both drafters. If the small drafter's curve stays flat, this alternative wins on speed and our contribution reduces to the diagnosis and intervention.
Why not just prune the context first with Superposition Prompting or extract evidence first with Ext2Gen? Both work on open QA. Superposition Prompting reports a 93x compute reduction on NaturalQuestions-Open, but neither was tested with formal output schemas. Ext2Gen and LiteCoST lengthen the output, which worsens latency. Whole-passage pruning also risks discarding multi-hop evidence that has low surface overlap with the query, a limitation the file attributes to query-likelihood penalties. Our intervention touches only passages that supply competing candidate values. If whole-context pruning matches our accuracy at similar cost, the decision-point intervention is unnecessary. Our drafter would still compose with it, and we will test that combination explicitly.
Why not just fine-tune the model on noisy structured data? Ext2Gen reports that its SFT-Best baseline was outperformed by preference alignment. Grammar-Aligned Decoding reports that QLoRA-tuned models still suffer distortion from masking. Fine-tuning is also orthogonal to our decoder: we will apply the drafter to a fine-tuned xLAM model to show the speedup survives fine-tuning.
Proposed Experiments
The benchmarks are the Berkeley Function-Calling Leaderboard v2 and xLAM-style function calls xLAM, where xLAM-8x22b-r reports 87.31% overall accuracy. To these we add retrieved distractor documents containing plausible competing argument values. We also use Spider text-to-SQL with distractor schema descriptions and table rows. Finally, we pose HotpotQA and MuSiQue MuSiQue as JSON outputs with answer and supporting-evidence fields, under DAS-style retrieval of 5 to 100 passages. Targets are Llama-3.1-8B and a 70B model. Metrics are schema validity, exact-match value accuracy, the share of errors that are wrong-source copies, mean accepted tokens per target pass, and wall-clock latency at batch size one.
Three checks decide the proposal. The first is whether the full drafter's speedup over masked autoregressive decoding beats both the small-model tree drafter and the forced-run-only ablation at high distractor density. A clear margin would justify the context-span component; a flat result would not. The second is whether, with plain masked decoding, more than half of distractor-induced errors are syntactically valid copies from distractor passages. If so, the idea of decision points as the place noise acts is supported. If errors are mostly syntax failures or values copied from nowhere, it is refuted. The third is whether re-scoring only at decision points recovers a substantial share of the accuracy gap between clean and 100-passage contexts, while adding negligible latency compared with Superposition Prompting and Ext2Gen. Exactness of the speed component will be verified empirically by matching greedy outputs token for token against masked autoregressive decoding.
References
- Constrained Decoding with Speculative Lookaheads
- An Actor-Critic Algorithm for Sequence Prediction
- Efficient (Soft) Q-Learning for Text Generation with Limited Good Data
- Controlling Large Language Model with Latent Action
- Flexible and Efficient Grammar-Constrained Decoding
- Grammar-Aligned Decoding
- Mitigating Bias in Locally Constrained Decoding via Tractable Proposals
- Adaptive Constraint Propagation: Scaling Structured Inference for Large Language Models via Meta-Reinforcement Learning
- Multi-candidate Speculative Decoding
- Traversal Verification for Speculative Tree Decoding
- A Theoretical Perspective for Speculative Decoding Algorithm
- Graph-Structured Speculative Decoding
- Cactus: Accelerating Auto-Regressive Decoding with Constrained Acceptance Speculative Sampling
- Improving Zero-shot Reader by Reducing Distractions from Irrelevant Documents in Open-Domain Question Answering
- Superposition Prompting: Improving and Accelerating Retrieval-Augmented Generation
- Aligning Extraction and Generation for Robust Retrieval-Augmented Generation
- Long-Document QA with Chain-of-Structured-Thought and Fine-Tuned SLMs
- xLAM: A Family of Large Action Models to Empower AI Agent Systems
- ♫ MuSiQue: Multihop Questions via Single-hop Question Composition