arXiv:2504.20799cs.SEcs.AI2025-04被引 18

代码大模型生成错误代码,这篇综述系统梳理了问题类型与应对方法。

Hallucination by Code Generation LLMs: Taxonomy, Benchmarks, Mitigation, and Challenges

  • 按错误性质分类代码生成中的幻觉类型
  • 总结现有评测基准与缓解策略
  • 适合关注AI编程安全的研究者和开发者

近年来,大型语言模型(LLMs)在代码生成方面取得突破,使开发者能用通用或专用代码模型修改代码甚至从零生成函数。这一能力也推动了无代码/低代码应用的发展。然而,由于内部机制限制,代码大模型(CodeLLMs)容易产生幻觉:即生成不正确、无意义且无法验证的代码,且难以识别。这类错误代码可能在特定执行路径下才暴露,常被忽略并混入代码库。本综述系统研究了与代码幻觉相关的最新成果,对生成代码中的幻觉类型进行分类,回顾现有评测基准与缓解策略,并指出开放挑战。基于这些发现,本文提出未来在检测与消除代码幻觉方面的研究方向。

原文摘要 · Abstract (English)

Recent technical breakthroughs in large language models (LLMs) have enabled them to fluently generate source code. Software developers often leverage both general-purpose and code-specialized LLMs to revise existing code or even generate a whole function from scratch. These capabilities are also beneficial in no-code or low-code contexts, in which one can write programs without a technical background. However, due to their internal design, LLMs are prone to generating hallucinations, which are incorrect, nonsensical, and not justifiable information but difficult to identify its presence. This problem also occurs when generating source code. Once hallucinated code is produced, it is often challenging for users to identify and fix it, especially when such hallucinations can be identified under specific execution paths. As a result, the hallucinated code may remain unnoticed within the codebase. This survey investigates recent studies and techniques relevant to hallucinations generated by CodeLLMs. We categorize the types of hallucinations in the code generated by CodeLLMs, review existing benchmarks and mitigation strategies, and identify open challenges. Based on these findings, this survey outlines further research directions in the detection and removal of hallucinations produced by CodeLLMs.

代码生成幻觉检测大模型安全

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。