EUVIMEDEUVIMED entdecken
Open Access · CC BY 4.0

Hallucinations in LLM-Based Code Summarization: Unveiling, Detection, and Mitigation

Guanghua Wan, Yuanning Feng, Yao Wan, Zhaoyang Chu, Zhangqian Bi, Junxiao Han, Zhou Zhao, Hongyu Zhang, Pingpeng Yuan, Xuanhua Shi, Hai Jin

Proceedings of the ACM on Software Engineering · 30.06.2026 · 3 (FSE) · 2976-2999

DOI: 10.1145/3808139 ↗

Kurz gefasst

Fachartikel in der Zeitschrift Proceedings of the ACM on Software Engineering, online erschienen am 30.06.2026. Verfasst von Guanghua Wan und 10 weiteren Autor:innen. Die Arbeit nennt 67 Literaturangaben. Der Volltext ist frei zugänglich (Open Access, CC BY 4.0). Gefördert von: Major Program (JD) of Hubei Province.

AbstractBibliografische AngabenZitierenVerwandte Studien

Abstract (Originalsprache)

Code summarization plays a vital role in program comprehension and software maintenance by generating natural language descriptions to summarize the semantics of code. While Large Language Models (LLMs) have shown remarkable performance in this area, recent empirical studies reveal a critical limitation: LLMs are prone to hallucinations, producing summaries that are factually inaccurate or unfaithful to the source code, potentially misleading developers. In this paper, we propose to unveil, detect, and mitigate hallucinations in LLM-based code summarization. First, we construct Hallu-Eval, a novel dataset for unveiling hallucination phenomena and rigorously evaluating the effectiveness of hallucination detection and mitigation in LLM-based code summarization. It comprises both original code snippets to capture naturally occurring hallucinations and their semantically perturbed counterparts, which are designed to systematically induce challenging logical hallucinations, all complemented with manual hallucination annotations on a curated testbed of 800 code-summary pairs. Next, we propose Hallu-Det, a synergistic approach that combines direct entity-level detection to identify explicit hallucinations with a synonymous mutation-based refinement to reliably confirm or refute more ambiguous cases. Finally, we introduce Hallu-Shield, an inference-time mitigation approach that leverages an external value model to guide LLMs toward producing more faithful summaries without costly retraining of the LLM itself. Extensive experiments show that Hallu-Eval effectively triggers hallucinations, increasing the hallucination rate of models such as Qwen2.5-Coder-7B from 17% to 97% on perturbed code. Our detection approach, Hallu-Det, achieves the best performance among baselines, reaching an F1-score of 0.95 for summaries generated by Qwen2.5-Coder-7B. Moreover, our mitigation method, Hallu-Shield, reduces hallucination rates. For example, it lowers the rate from 66% to 59%, a 10.6% relative reduction, on DeepSeek-Coder-6.7B, while simultaneously improving summary quality, achieving a 74.0% win rate evaluated by an LLM-as-a-judge majority vote ensemble.

Förderung

  • Major Program (JD) of Hubei Province

Zitieren

APA

Wan, G., Feng, Y., Wan, Y., Chu, Z., Bi, Z., Han, J., Zhao, Z., Zhang, H., Yuan, P., Shi, X., & Jin, H. (2026). Hallucinations in LLM-Based Code Summarization: Unveiling, Detection, and Mitigation. Proceedings of the ACM on Software Engineering, 3(FSE), 2976-2999. https://doi.org/10.1145/3808139

Vancouver

Wan G, Feng Y, Wan Y, Chu Z, Bi Z, Han J, et al. Hallucinations in LLM-Based Code Summarization: Unveiling, Detection, and Mitigation. Proceedings of the ACM on Software Engineering. 2026;3(FSE):2976-2999. doi:10.1145/3808139

BibTeX
@article{Wan2026,
  author = {Wan, Guanghua and Feng, Yuanning and Wan, Yao and Chu, Zhaoyang and Bi, Zhangqian and Han, Junxiao and Zhao, Zhou and Zhang, Hongyu and Yuan, Pingpeng and Shi, Xuanhua and Jin, Hai},
  title = {Hallucinations in LLM-Based Code Summarization: Unveiling, Detection, and Mitigation},
  journal = {Proceedings of the ACM on Software Engineering},
  year = {2026},
  volume = {3},
  number = {FSE},
  pages = {2976--2999},
  doi = {10.1145/3808139}
}
Kostenlos starten →