Abstract
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 \emph{safe pruning}: it rejects only prefixes whose semantic contradictions cannot be repaired by any continuation. A separate, grammar-dependent, \emph{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 (\texttt{ocamlc}, \texttt{cc}). 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.
Keywords
Subject
Publication details
- DOI
- 10.1145/3843750.3843841
- Journal
- Not available
- Open access
- Green open access
Cite this article
APA 7
Kronlund-Drouault, P. (2026). Semantic Prefix Oracles for LLM Decoding: Contracts and Differential Validation. https://doi.org/10.1145/3843750.3843841
MLA 9
Kronlund-Drouault, Paul. "Semantic Prefix Oracles for LLM Decoding: Contracts and Differential Validation." https://doi.org/10.1145/3843750.3843841.
Chicago (author–date)
Kronlund-Drouault, Paul. 2026. "Semantic Prefix Oracles for LLM Decoding: Contracts and Differential Validation." https://doi.org/10.1145/3843750.3843841.
Harvard
Kronlund-Drouault, P. (2026) 'Semantic Prefix Oracles for LLM Decoding: Contracts and Differential Validation', doi:10.1145/3843750.3843841.
Vancouver
Kronlund-Drouault P. Semantic Prefix Oracles for LLM Decoding: Contracts and Differential Validation. doi:10.1145/3843750.3843841
IEEE
P. Kronlund-Drouault, "Semantic Prefix Oracles for LLM Decoding: Contracts and Differential Validation," doi: 10.1145/3843750.3843841.