Type-Constrained Code Generation with Language Models
Not on the map. Why?
Abstract (arXiv)
Large language models (LLMs) have achieved notable success in code generation. However, they still frequently produce uncompilable output because their next-token inference procedure does not model formal aspects of code. Although constrained decoding is a promising approach to alleviate this issue, it has only been applied to handle either domain-specific languages or syntactic features of general-purpose programming languages. However, LLMs frequently generate code with typing errors, which are beyond the domain of syntax and generally hard to adequately constrain. To address this challenge, we introduce a type-constrained decoding approach that leverages type systems to guide code generation. For this purpose, we develop novel prefix automata and a search over inhabitable types, forming a sound approach to enforce well-typedness on LLM-generated code. We formalize our approach on a foundational simply-typed language and extend it to TypeScript to demonstrate practicality. Our evaluation on the HumanEval and MBPP datasets shows that our approach reduces compilation errors by more than half and significantly increases functional correctness in code synthesis, translation, and repair tasks across LLMs of various sizes and model families, including state-of-the-art open-weight models with more than 30B parameters. The results demonstrate the generality and effectiveness of our approach in constraining LLM code generation with formal rules of type systems.
Key facts. Cited by 32 papers in the map (data through 7 Oct 2026). Builds on 35 of its 65 references that are in the map. First posted on arXiv 12 Apr 2025.
Builds on
35 of 65 references.
References · 35
- 2020Language Models are Few-Shot Learnerscited by 32,199
- 2023GPT-4 Technical Reportcited by 18,132
- 2024The Llama 3 Herd of Modelscited by 14,192
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2024Qwen2.5 Technical Reportcited by 4,713
- 2021Program Synthesis with Large Language Modelscited by 3,509
- 2015Neural Machine Translation of Rare Words with Subword Unitscited by 2,898
- 2023Code Llama: Open Foundation Models for Codecited by 2,105
- 2024Gemma 2: Improving Open Language Models at a Practical Sizecited by 1,928
- 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,154
- 2024A Survey on Large Language Models for Code Generationcited by 646
- 2024StarCoder 2 and The Stack v2: The Next Generationcited by 484
23 more
- 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 417
- 2023A Survey of Hallucination in Large Foundation Modelscited by 365
- 2023Efficient Guided Generation for Large Language Modelscited by 192
- 2024SWT-Bench: Testing and Validating Real-World Bug-Fixes with Code Agentscited by 129
- 2022Prompting Is Programming: A Query Language for Large Language Modelscited by 110
- 2024Guiding LLMs The Right Way: Fast, Non-Invasive Constrained Generationcited by 99
- 2024SynCode: LLM Generation with Grammar Augmentationcited by 66
- 2024Bugs in Large Language Models Generated Code: An Empirical Studycited by 59
- 2023Copiloting the Copilots: Fusing Large Language Models with Completion Engines for Automated Program Repaircited by 55
- 2024What's Wrong with Your Code Generated by Large Language Models? An Extensive Studycited by 52
- 2020How Can Self-Attention Networks Recognize Dyck-n Languages?cited by 51
- 2023Masked Hard-Attention Transformers Recognize Exactly the Star-Free Languagescited by 47
- 2024A Systematic Literature Review on Large Language Models for Automated Program Repaircited by 37
- 2023Measuring The Impact Of Programming Language Distributioncited by 32
- 2023Exploring Parameter-Efficient Fine-Tuning Techniques for Code Generation with Large Language Modelscited by 28
- 2023CoTran: An LLM-based Code Translator using Reinforcement Learning with Feedback from Compiler and Symbolic Executioncited by 21
- 2024Code Less, Align More: Efficient LLM Fine-tuning for Code Generation with Data Pruningcited by 19
- 2024Syzygy: Dual Code-Test C to (safe) Rust Translation using LLMs and Dynamic Analysiscited by 16
- 2024Statically Contextualizing Large Language Models with Typed Holescited by 9
- 2025Enhancing Code Generation for Low-Resource Languages: No Silver Bulletcited by 9
- 2024Constrained Decoding for Fill-in-the-Middle Code Language Models via Efficient Left and Right Quotienting of Context-Sensitive Grammarscited by 8
- 2024A Comparative Study of DSL Code Generation: Fine-Tuning vs. Optimized Retrieval Augmentationcited by 8
- 2024Compilation Quotient (CQ): A Metric for the Compilation Hardness of Programming Languagescited by 1
Built on by
Citing papers per year: 2025: 12; 2026: 20.
32 papers.
Sort:
By area:
- 2025Unveiling the Potential of Diffusion Large Language Model in Controllable Generationcited by 14
- 2025Constrained Decoding of Diffusion LLMs with Context-Free Grammarscited by 13
- 2025Towards Formal Verification of LLM-Generated Code from Natural Language Promptscited by 8
- 2025Correctness-Guaranteed Code Generation via Constrained Decodingcited by 7
- 2025Beyond the Prompt: An Empirical Study of Cursor Rulescited by 7
- 2026SEVerA: Verified Synthesis of Self-Evolving Agentscited by 6
- 2025RefineStat: Efficient Exploration for Probabilistic Program Synthesiscited by 5
- 2025Agint: Agentic Graph Compilation for Software Engineering Agentscited by 4
- 2026Implementing Grassroots Logic Programs with Multiagent Transition Systems and AI (Full Version)cited by 1
- 2026Constrained Code Generation with Discrete Diffusioncited by 1
- 2026Verifier-Guided Code Translation via Meta-Step Decodingcited by 1
- 2026The Alignment Problem in Constrained Code Generationcited by 1
20 more
- 2026Large Databases Need Small, Open-Weight Language Modelscited by 1
- 2025LLM Agents for Generating Microservice-based Applications: how complex is your specification?cited by 0
- 2025Play by the Type Rules: Inferring Constraints for LLM Functions in Declarative Programscited by 0
- 2025Learning to Guarantee Type Correctness in Code Generation through Type-Guided Program Synthesiscited by 0
- 2025Position: Vibe Coding Needs Vibe Reasoning: Improving Vibe Coding with Formal Verificationcited by 0
- 2025Prompt Less, Smile More: MTP with Semantic Engineering in Lieu of Prompt Engineeringcited by 0
- 2026The New Compiler Stack: A Survey on the Synergy of LLMs and Compilerscited by 0
- 2026Hydra: Efficient, Correct Code Generation via Checkpoint-and-Rollback Supportcited by 0
- 2026Learning the Error Patterns of Language Modelscited by 0
- 2026Accelerating Constrained Decoding with Token Space Compressioncited by 0
- 2026Projectional Decoding: Towards Semantic-Aware LLM Generationcited by 0
- 2026Dynamic Infilling Anchors for Format-Constrained Generation in Diffusion Large Language Modelscited by 0
- 2026TypeProbe: Recovering Type Representations from Hidden States of Pre-trained Code Modelscited by 0
- 2026Generative Compilation: On-the-Fly Compiler Feedback as AI Generates Codecited by 0
- 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
- 2026Specification-Guided Synthesis of Deadlock-Free Communication Protocol Refinements with Large Language Modelscited by 0
- 2026SafeQL: Search-based Refinement for Safe and Efficient LLM-based Text-to-SQLcited by 0
- 2026Stay Within Your Bounds: Distance-Guided Decoding for Guaranteed Context-Free Grammar Compliancecited by 0
- 2026Semantic Prefix Oracles for LLM Decoding: Contracts and Differential Validationcited by 0
- 2026Semantic Prefix Oracles for LLM Decoding: Contracts and Differential Validation28 Sep 2026
- 2026Stay Within Your Bounds: Distance-Guided Decoding for Guaranteed Context-Free Grammar Compliance28 Aug 2026
- 2026SafeQL: Search-based Refinement for Safe and Efficient LLM-based Text-to-SQL10 Aug 2026
- 2026Specification-Guided Synthesis of Deadlock-Free Communication Protocol Refinements with Large Language Models30 Jul 2026
- 2026Decode-Time Grammars: Constrained LLM Generation over a Refinement Order of Grammar Fragments20 Jul 2026
- 2026Generative Compilation: On-the-Fly Compiler Feedback as AI Generates Code15 Jul 2026
- 2026TypeProbe: Recovering Type Representations from Hidden States of Pre-trained Code Models9 Jul 2026
- 2026Large Databases Need Small, Open-Weight Language Models30 Jun 2026
- 2026The Alignment Problem in Constrained Code Generation19 Jun 2026
- 2026Dynamic Infilling Anchors for Format-Constrained Generation in Diffusion Large Language Models3 Jun 2026
- 2026Projectional Decoding: Towards Semantic-Aware LLM Generation28 May 2026
- 2026Accelerating Constrained Decoding with Token Space Compression28 May 2026
20 more
- 2026Learning the Error Patterns of Language Models27 May 2026
- 2026Verifier-Guided Code Translation via Meta-Step Decoding17 May 2026
- 2026Constrained Code Generation with Discrete Diffusion16 May 2026
- 2026Cross-Dialect Generalization Without Retraining: Benchmarks and Evaluation of Schema-Derived Constrained Decoding for MLIR14 May 2026
- 2026Hydra: Efficient, Correct Code Generation via Checkpoint-and-Rollback Support14 May 2026
- 2026SEVerA: Verified Synthesis of Self-Evolving Agents26 Mar 2026
- 2026Implementing Grassroots Logic Programs with Multiagent Transition Systems and AI (Full Version)6 Feb 2026
- 2026The New Compiler Stack: A Survey on the Synergy of LLMs and Compilers5 Jan 2026
- 2025Beyond the Prompt: An Empirical Study of Cursor Rules21 Dec 2025
- 2025Agint: Agentic Graph Compilation for Software Engineering Agents24 Nov 2025
- 2025Prompt Less, Smile More: MTP with Semantic Engineering in Lieu of Prompt Engineering24 Nov 2025
- 2025Position: Vibe Coding Needs Vibe Reasoning: Improving Vibe Coding with Formal Verification31 Oct 2025
- 2025Learning to Guarantee Type Correctness in Code Generation through Type-Guided Program Synthesis11 Oct 2025
- 2025Play by the Type Rules: Inferring Constraints for LLM Functions in Declarative Programs24 Sep 2025
- 2025RefineStat: Efficient Exploration for Probabilistic Program Synthesis1 Sep 2025
- 2025LLM Agents for Generating Microservice-based Applications: how complex is your specification?22 Aug 2025
- 2025Correctness-Guaranteed Code Generation via Constrained Decoding20 Aug 2025
- 2025Constrained Decoding of Diffusion LLMs with Context-Free Grammars13 Aug 2025
- 2025Towards Formal Verification of LLM-Generated Code from Natural Language Prompts17 Jul 2025
- 2025Unveiling the Potential of Diffusion Large Language Model in Controllable Generation6 Jul 2025
- 2025Unveiling the Potential of Diffusion Large Language Model in Controllable Generationcited by 14
- 2026SEVerA: Verified Synthesis of Self-Evolving Agentscited by 6
- 2025Agint: Agentic Graph Compilation for Software Engineering Agentscited by 4
- 2025LLM Agents for Generating Microservice-based Applications: how complex is your specification?cited by 0
- 2026SEVerA: Verified Synthesis of Self-Evolving Agents26 Mar 2026
- 2025Agint: Agentic Graph Compilation for Software Engineering Agents24 Nov 2025
- 2025LLM Agents for Generating Microservice-based Applications: how complex is your specification?22 Aug 2025
- 2025Unveiling the Potential of Diffusion Large Language Model in Controllable Generation6 Jul 2025
- 2026Constrained Code Generation with Discrete Diffusioncited by 1
- 2026Constrained Code Generation with Discrete Diffusion16 May 2026
- 2025Constrained Decoding of Diffusion LLMs with Context-Free Grammarscited by 13
- 2025Towards Formal Verification of LLM-Generated Code from Natural Language Promptscited by 8
- 2025Correctness-Guaranteed Code Generation via Constrained Decodingcited by 7
- 2025Beyond the Prompt: An Empirical Study of Cursor Rulescited by 7
- 2025RefineStat: Efficient Exploration for Probabilistic Program Synthesiscited by 5
- 2026Implementing Grassroots Logic Programs with Multiagent Transition Systems and AI (Full Version)cited by 1
- 2026The Alignment Problem in Constrained Code Generationcited by 1
- 2026Large Databases Need Small, Open-Weight Language Modelscited by 1
- 2025Learning to Guarantee Type Correctness in Code Generation through Type-Guided Program Synthesiscited by 0
- 2025Prompt Less, Smile More: MTP with Semantic Engineering in Lieu of Prompt Engineeringcited by 0
- 2026The New Compiler Stack: A Survey on the Synergy of LLMs and Compilerscited by 0
- 2026Hydra: Efficient, Correct Code Generation via Checkpoint-and-Rollback Supportcited by 0
12 most cited of 24 All 24 (JSON)
- 2026Semantic Prefix Oracles for LLM Decoding: Contracts and Differential Validation28 Sep 2026
- 2026Stay Within Your Bounds: Distance-Guided Decoding for Guaranteed Context-Free Grammar Compliance28 Aug 2026
- 2026SafeQL: Search-based Refinement for Safe and Efficient LLM-based Text-to-SQL10 Aug 2026
- 2026Specification-Guided Synthesis of Deadlock-Free Communication Protocol Refinements with Large Language Models30 Jul 2026
- 2026Decode-Time Grammars: Constrained LLM Generation over a Refinement Order of Grammar Fragments20 Jul 2026
- 2026Generative Compilation: On-the-Fly Compiler Feedback as AI Generates Code15 Jul 2026
- 2026TypeProbe: Recovering Type Representations from Hidden States of Pre-trained Code Models9 Jul 2026
- 2026Large Databases Need Small, Open-Weight Language Models30 Jun 2026
- 2026The Alignment Problem in Constrained Code Generation19 Jun 2026
- 2026Dynamic Infilling Anchors for Format-Constrained Generation in Diffusion Large Language Models3 Jun 2026
- 2026Projectional Decoding: Towards Semantic-Aware LLM Generation28 May 2026
- 2026Accelerating Constrained Decoding with Token Space Compression28 May 2026
12 newest of 24 All 24 (JSON)