paper-with-me

Papers

Type-Constrained Code Generation with Language Models

2025-04-12 · Niels Mündler, Jingxuan He, Hao Wang, Koushik Sen, Dawn Song, Martin Vechev

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.

📄 PDF Abstract BibTeX arXiv:2504.09246

Code (0)

등록된 구현이 없습니다.

Tasks

Code GenerationHumanEvalmbpp

Similar Papers 제목 키워드 기반

The Alignment Problem in Constrained Code Generation

2026-06-19 · Matteo Biagiola, Jahrim Gabriele Cesario, Luca Di Grazia, George Zakhour 외 arxiv

Large Language Models (LLMs) have demonstrated strong capabilities in code generation, but their outputs frequently contain syntax or type errors that result in compilation failures. Constrained decoding has been propose…

Code Generation

Evaluating, Understanding, and Improving Constrained Text Generation for Large Language Models

2023-10-25 · Xiang Chen, Xiaojun Wan

Advancements in natural language generation (NLG) and large language models (LLMs) have led to proficient text generation in various tasks. However, integrating intricate constraints into neural text generation, due to L…

Text Generation

Knowledge-enriched, Type-constrained and Grammar-guided Question Generation over Knowledge Bases

2020-10-07 · COLING 2020 8 · Sheng Bi, Xiya Cheng, Yuan-Fang Li, Yongzhen Wang 외

Question generation over knowledge bases (KBQG) aims at generating natural-language questions about a subgraph, i.e. a set of (connected) triples. Two main challenges still face the current crop of encoder-decoder-based …

DecoderDiversityQuestion GenerationQuestion-Generation

Learning to Guarantee Type Correctness in Code Generation through Type-Guided Program Synthesis

2025-10-11 · Zhechong Huang, Zhao Zhang, Ruyi Ji, Tingxuan Xia 외 arxiv

Language models have shown remarkable proficiency in code generation; nevertheless, ensuring type correctness remains a challenge. Although traditional methods, such as constrained decoding, alleviate this problem by ext…

Program SynthesisCode Generation

Correctness-Guaranteed Code Generation via Constrained Decoding

2025-08-20 · Lingxiao Li, Salar Rahili, Yiwei Zhao 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 develop…

Code Generation