Efficient Hallucination Detection in Automatic Code Generation

ACL ARR 2026 January Submission9403 Authors

06 Jan 2026 (modified: 20 Mar 2026)ACL ARR 2026 January SubmissionEveryoneRevisionsBibTeXCC BY 4.0
Keywords: Large language models, Automatic Code Generation, Hallucination Detection
Abstract: Large language models (LLMs) frequently generate source code that appears plausible yet contains hallucinations that lead to test failures. While uncertainty quantification (UQ) methods have shown promise for hallucination detection in natural language, their effectiveness in the code generation setting remains largely unexplored. In this work, we investigate the performance of state-of-the-art UQ methods for hallucination detection in source code generation and propose an efficient and effective training-based approach. We develop a diff-based pipeline to construct a code dataset annotated with line-level LLM hallucinations, enabling systematic benchmarking of hallucination detection methods. Using this pipeline, we build a large-scale annotated dataset and train a lightweight Transformer-based hallucination detector that leverages LLM hidden states as input features. Experimental results across diverse code generation domains demonstrate that the detector substantially outperforms other existing approaches in line-level hallucination detection. We release the first publicly available dataset of line-level code hallucinations, along with the corresponding source code and trained hallucination detectors.
Paper Type: Long
Research Area: Code Models
Research Area Keywords: Code language models, code generation, program repair, evaluation of code models, bug detection
Contribution Types: Model analysis & interpretability, Publicly available software and/or pre-trained models, Data resources
Languages Studied: English, Python, Java
Submission Number: 9403
Loading