Skip to content
Conference Open access

Efficient Hallucination Detection in Automatic Code Generation

2026 · Annual Meeting of the Association for Computational Linguistics · pp. 43197-43220 · 0 citations · 33 references
Computer Science

TL;DR

A lightweight Transformer-based detector is trained that uses LLM internal representations to identify hallucinations, substantially outperforming existing methods across several code generation domains and shows particular promise for enabling self-correction in LLM-based coding agents.

Abstract

Large language models (LLMs) frequently produce source code that seems correct and well-formed, yet includes hallucinated elements that cause downstream test failures. In this study, we benchmark state-of-the-art uncertainty quantification methods and existing base-lines for the task of hallucination detection in source code and introduce a diff-based pipeline to construct a code dataset annotated with line-level hallucinations. Building on this, we train a lightweight Transformer-based detector that uses LLM internal representations to identify hallucinations, substantially outperforming existing methods across several code generation domains. The detector also shows particular promise for enabling self-correction in LLM-based coding agents. We release the first publicly available dataset of line-level code hallucinations, along with the corresponding source code and trained hallucination detectors https://github.com/ datapaf/CodeHallucinationDetection

Read PDF

Similar papers

#software testing Book Open access Aug 2026

Evaluating Inference-Time Defenses against Package Hallucination in LLM-Generated Code

The results recast package hallucination as both a measurement problem and a decoding-time control problem, and they demonstrate that the choice of defense must be matched to the threat model and recommendation utility.

Albérick Euraste Djiré, I. E. Olatunji, Melissa Tessa et al. · 1 citation
Preprint Aug 2026

Execution-Anchored Hallucination Calibration Reranking for Verilog Code Generation

EAHC is proposed, an Execution-Anchored Hallucination Calibration reranking framework that anchors reasoning judgments to execution behavior so that execution-equivalent candidates receive consistent scores, which implements a dual-channel architecture.

Guang Yang, Xing Hu, Xiang Chen et al. · 0 citations
Preprint Aug 2026

Hallucination Span Detection with Input-Side Evidence Alignment

This work introduces the task of hallucination span detection with input-side evidence alignment, which jointly identifies hallucinated spans and aligns output tokens with the corresponding input evidence.

Miyu Yamada, Yuki Arase · 0 citations
Preprint Aug 2026

Decomposed Entailment for Factuality Checking and Hallucination Detection

HallDetect, a lightweight, reference-free, and black-box framework for hallucination detection, is presented, a lightweight, reference-free, and black-box framework for hallucination detection that is evaluated not only on summarization but across a broader range of source-grounded generation settings.

Achir Oukelmoun, N. Semmar, Gaël de Chalendar · 0 citations
Jul 2026

HalluScope: Fine-grained Hallucination Diagnosis for Multimodal Large Language Models

Fine-grained hallucination diagnosis for MLLMs is proposed, a new unified task that jointly performs hallucination detection, classification, and interpretable explanation generation and feedback experiments show that the fine-grained diagnostic explanations produced by the model effectively guide target models to corr...

Weilin Jin, Mingyu Wang, Wenbo Li et al. · 0 citations

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.