LLM Hallucinations in Practical Code Generation: Phenomena, Mechanism, and Mitigation
Proceedings of the ACM on Software Engineering · 22.06.2025 · 2 (ISSTA) · 481-503
DOI: 10.1145/3728894 ↗Kurz gefasst
Fachartikel in der Zeitschrift Proceedings of the ACM on Software Engineering, online erschienen am 22.06.2025. Verfasst von Ziyao Zhang und 8 weiteren Autor:innen. Die Arbeit wurde bisher 128-mal zitiert (Crossref) und nennt 53 Literaturangaben. Der Volltext ist frei zugänglich (Open Access, CC BY 4.0). Gefördert von: CCF-Huawei Populus Grove Fund.
Abstract (Originalsprache)
Code generation aims to automatically generate code from input requirements, significantly enhancing development efficiency. Recent large language models (LLMs) based approaches have shown promising results and revolutionized code generation task. Despite the promising performance, LLMs often generate contents with hallucinations, especially for the code generation scenario requiring the handling of complex contextual dependencies in practical development process. Although previous study has analyzed hallucinations in LLM-powered code generation, the study is limited to standalone function generation. In this paper, we conduct an empirical study to study the phenomena, mechanism, and mitigation of LLM hallucinations within more practical and complex development contexts in repository-level generation scenario. First, we manually examine the code generation results from six mainstream LLMs to establish a hallucination taxonomy of LLMgenerated code. Next, we elaborate on the phenomenon of hallucinations, analyze their distribution across different models. We then analyze causes of hallucinations and identify four potential factors contributing to hallucinations. Finally, we propose an RAG-based mitigation method, which demonstrates consistent effectiveness in all studied LLMs.
Förderung
- CCF-Huawei Populus Grove Fund
Zitieren
APA
Zhang, Z., Wang, C., Wang, Y., Shi, E., Ma, Y., Zhong, W., Chen, J., Mao, M., & Zheng, Z. (2025). LLM Hallucinations in Practical Code Generation: Phenomena, Mechanism, and Mitigation. Proceedings of the ACM on Software Engineering, 2(ISSTA), 481-503. https://doi.org/10.1145/3728894
Vancouver
Zhang Z, Wang C, Wang Y, Shi E, Ma Y, Zhong W, et al. LLM Hallucinations in Practical Code Generation: Phenomena, Mechanism, and Mitigation. Proceedings of the ACM on Software Engineering. 2025;2(ISSTA):481-503. doi:10.1145/3728894
BibTeX
@article{Zhang2025,
author = {Zhang, Ziyao and Wang, Chong and Wang, Yanlin and Shi, Ensheng and Ma, Yuchi and Zhong, Wanjun and Chen, Jiachi and Mao, Mingzhi and Zheng, Zibin},
title = {LLM Hallucinations in Practical Code Generation: Phenomena, Mechanism, and Mitigation},
journal = {Proceedings of the ACM on Software Engineering},
year = {2025},
volume = {2},
number = {ISSTA},
pages = {481--503},
doi = {10.1145/3728894}
}
EUVIMED