Correctness-Guaranteed Code Generation via Constrained Decoding
Not on the map. Why?
Abstract (arXiv)
Language Models (LMs) are increasingly being used for code generation, but ensuring the correctness of generated programs remains a significant challenge. Although imperfect code may be acceptable during software development with human oversight, domains such as video games and robotics require one-shot correctness for runtime-critical components. We present a constrained decoding algorithm for generating semantically correct programs that incorporates a context-sensitive parser, which, at each step, outputs a regular expression that satisfies a critical non-extensible property to guide the generation of the next token sequence that can continue to a correct program. To build such a context-sensitive parser, we propose a framework of a dynamic tree of parsers (ToP) during parsing, where each parser corresponds to a modular context-free grammar enriched with contextual information such as variable scopes and type constraints, with tree branches representing ambiguity in the future code segment. We demonstrate our approach through sLua, a strongly typed variant of Lua, showing that our method can generate semantically correct programs conforming to any prescribed scripting API. We further show that, with careful design, our semantic guarantees extend to runtime correctness, as validated in the application of generating game mechanics for a roguelike video game.
Key facts. Cited by 7 papers in the map (data through 14 Oct 2026). Builds on 9 of its 34 references that are in the map. First posted on arXiv 20 Aug 2025.
Builds on
9 of 34 references.
References · 9
- 2023Efficient Memory Management for Large Language Model Serving with PagedAttentioncited by 5,944
- 2024Qwen2.5-Coder Technical Reportcited by 1,203
- 2019Stochastic Beams and Where to Find Them: The Gumbel-Top-k Trick for Sampling Sequences Without Replacementcited by 211
- 2022Synchromesh: Reliable code generation from pre-trained language modelscited by 156
- 2022GitHub Copilot AI pair programmer: Asset or Liability?cited by 152
- 2024XGrammar: Flexible and Efficient Structured Generation Engine for Large Language Modelscited by 75
- 2024Grammar-Aligned Decodingcited by 54
- 2024Automata-based constraints for language model decodingcited by 51
- 2025Type-Constrained Code Generation with Language Modelscited by 35
Built on by
Citing papers per year: 2025: 1; 2026: 6.
7 papers.
- 2026Mitigating Bias in Locally Constrained Decoding via Tractable Proposalscited by 8
- 2025AI-Driven Self-Evolving Software: A Promising Path Toward Software Automationcited by 3
- 2026TruncProof: A Guardrail for LLM-based JSON Generation under Token-Length Constraintscited by 1
- 2026Stay Within Your Bounds: Distance-Guided Decoding for Guaranteed Context-Free Grammar Compliancecited by 1
- 2026Cross-Dialect Generalization Without Retraining: Benchmarks and Evaluation of Schema-Derived Constrained Decoding for MLIRcited by 0
- 2026Decode-Time Grammars: Constrained LLM Generation over a Refinement Order of Grammar Fragmentscited by 0
- 2026The Parser Already Knows: Lightweight Bias Correction in Constrained Decodingcited by 0
- 2026Stay Within Your Bounds: Distance-Guided Decoding for Guaranteed Context-Free Grammar Compliance28 Aug 2026
- 2026The Parser Already Knows: Lightweight Bias Correction in Constrained Decoding10 Aug 2026
- 2026Decode-Time Grammars: Constrained LLM Generation over a Refinement Order of Grammar Fragments20 Jul 2026
- 2026Mitigating Bias in Locally Constrained Decoding via Tractable Proposals1 Jun 2026
- 2026Cross-Dialect Generalization Without Retraining: Benchmarks and Evaluation of Schema-Derived Constrained Decoding for MLIR14 May 2026
- 2026TruncProof: A Guardrail for LLM-based JSON Generation under Token-Length Constraints13 May 2026
- 2025AI-Driven Self-Evolving Software: A Promising Path Toward Software Automation1 Oct 2025