The Alignment Problem in Constrained Code Generation

📅 2026-06-19
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
Constrained decoding in code generation often suffers from misalignment between the constraint enforcer (e.g., a type system), large language models, and the target programming language (e.g., TypeScript), leading to degraded functional correctness. This work is the first to demonstrate that when constraint enforcers are incomplete or unsound, constrained decoding inadvertently steers models toward low-probability program regions, significantly reducing correctness—sometimes performing worse than unconstrained decoding, which achieves up to a 97% lower error rate in certain scenarios and incurs fewer timeouts. The study systematically evaluates decoding behaviors across seven large language models, two programming languages, and two classes of constraint enforcers on three benchmarks, and provides quantitative design principles for developing effective constraint mechanisms.
📝 Abstract
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 proposed as a solution to mitigate compilation errors by construction, improving functional correctness as a byproduct. However, previous works overlook a critical aspect of constrained decoding: the alignment between constrainer (e.g., types), language model and the target specification language (e.g., TypeScript). Misalignment is caused by the constrainer being incomplete--rejecting programs that belong to the target--or unsound--allowing programs that are not part of the target. The bias created by incompleteness distorts the language model distribution, and can be detrimental for code generation. We evaluate this hypothesis using seven language models, two target languages, two constrainers, enforcing types and syntax during decoding, and we study how language models react to varying levels of incompleteness. On three benchmarks, when the constrainer is incomplete, unconstrained decoding significantly outperforms constrained decoding in terms of functional correctness. Incompleteness pushes the model into low-probability regions of the program space, causing the generation to frequently time out, and reducing functional correctness by up to 97%. These contributions make the community aware of the negative effects of misalignment in constrained decoding, and provide quantitative insights on how to design constrainers that are beneficial for code generation systems with formal guarantees.
Problem

Research questions and friction points this paper is trying to address.

alignment problem
constrained decoding
code generation
incompleteness
functional correctness
Innovation

Methods, ideas, or system contributions that make the work stand out.

alignment problem
constrained decoding
code generation
type soundness
language model bias