Abstract:Large language models (LLMs) demonstrate significant potential in automatic code generation. However, in practical applications, the generated code often suffers from multiple issues, including syntax errors, semantics inconsistencies, security inconsistencies, inefficient runtime performance, and poor maintainability. To address these challenges, constrained code generation techniques are introduced. Drawing inspiration from constrained text generation, these techniques impose explicit constraints at various stages of the code generation process to ensure that the generated code satisfies predefined requirements. This study first reviews the major issues exposed by LLMs in code generation, with a detailed analysis of deficiencies related to code correctness and quality. Subsequently, recent research progress in constrained code generation is summarized, and the strengths and limitations of existing approaches are systematically examined. Furthermore, evaluation methods are discussed, including the construction of benchmark datasets and the design of evaluation metrics, providing valuable references for experimental settings in future research. Finally, the research challenges faced by constrained code generation and its future development trends are outlined.