Semantic Prefix Oracles for LLM Decoding: Contracts and Differential Validation
Not on the map. Why?
Abstract (arXiv)
Constrained decoding can enforce regular or context-free output formats, but many program-generation failures are semantic: scope, typing, and declaration effects depend on context. We present semantic grammar specifications, a declarative formalism that attaches such constraints to a context-free surface and executes them during Earley descent. Our implementation enforces safe pruning: it rejects only prefixes whose semantic contradictions cannot be repaired by any continuation. A separate, grammar-dependent, dead-end freedom property guarantees the existence of a realizable witness for each remaining branch. We give simple sufficient conditions based on surface productivity, type coverage, and left-to-right constraint flow. Our finite-lambda, core ML, and C-like fragments satisfy them, while the STLC instance used in our experiments does not: plain STLC can violate type coverage, and we show how restricting its type universe recovers it. A tokenizer-lifting lemma carries character-level witnesses to token sequences under an explicit vocabulary-coverage hypothesis. We validate the implementation differentially against production compilers (textttocamlc, textttcc). Across every prefix of 65 compiler-valid programs we observe zero false prunes. The semantic oracle localizes 25/30 invalid programs mid-stream, against 0/30 for a syntax-only oracle, and agrees on 42/42 recursion probes. A twelve-model generation study, including a matched semantic-versus-syntactic ablation for nine models, finds nonnegative observed semantic-minus-syntactic point estimates for every model-language pair, with maxima of +15.2 points on STLC task correctness and +14.3 points on ML validity.
Key facts. No citing papers in the map yet (data through 14 Oct 2026). Builds on 14 of its 27 references that are in the map. First posted on arXiv 28 Sep 2026.
Builds on
14 of 27 references.
References · 14
- 2022Chain-of-Thought Prompting Elicits Reasoning in Large Language Modelscited by 12,459
- 2023Pythia: A Suite for Analyzing Large Language Models Across Training and Scalingcited by 1,786
- 2021PICARD: Parsing Incrementally for Constrained Auto-Regressive Decoding from Language Modelscited by 411
- 2024Guiding LLMs The Right Way: Fast, Non-Invasive Constrained Generationcited by 101
- 2024SynCode: LLM Generation with Grammar Augmentationcited by 69
- 2023Tractable Control for Autoregressive Language Generationcited by 65
- 2025Flexible and Efficient Grammar-Constrained Decodingcited by 43
- 2025CRANE: Reasoning with constrained LLM generationcited by 38
- 2025Type-Constrained Code Generation with Language Modelscited by 35
- 2024IterGen: Iterative Semantic-aware Structured LLM Generation with Backtrackingcited by 29
- 2025ChopChop: a Programmable Framework for Semantically Constraining the Output of Language Modelscited by 15
- 2016Hazelnut: A Bidirectionally Typed Structure Editor Calculuscited by 8
2 more
Built on by
Not cited yet.