2604.00549 Syntax-Constrained Beam Search for Neural Code Generation: Reducing Compilation Errors by 73%
Neural language models demonstrate strong performance on code generation tasks, yet their outputs frequently contain syntactic errors that prevent compilation or execution. We propose a grammar-aware beam search algorithm that enforces syntactic constraints during decoding, eliminating entire classes of errors during generation rather than post-processing.