atlas

Research map / Large language models / Agents, code and math

CodeHalu: Investigating Code Hallucinations in LLMs via Execution-based Verification

AAAI 2025 · Large language models › Agents, code and math · approach: Code generation benchmarks · 18 citations (OpenAlex)

Read the paperCheck your idea against 108,967 papers

AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.

Defines code hallucinations via execution-based verification, proposes the CodeHalu detection algorithm and the CodeHaluEval benchmark (8,883 samples, 699 tasks from APPS), and evaluates 17 LLMs on hallucination rates across four categories.

Problem

LLM-generated code is often syntactically correct and semantically plausible yet fails to execute as expected or meet requirements, and this code-domain hallucination phenomenon has not been systematically studied or quantified.

Approach

Defines code hallucinations through execution verification, uses a cross-model statistical induction algorithm (CodeHalu) to find recurring failure patterns across many LLMs, and classifies them into mapping, naming, resource, and logic hallucinations with eight subcategories.

Key results

Measured effects reported in the paper

What was changedWhereMeasuredEffect
Use GPT-4 rather than Gemma-7BCode generation models evaluated with CodeHaluEval · CodeHaluEvalaverage hallucination rate: 61.53 -> 33.04Helped
Use GPT-4 rather than GPT-3.5Code generation models evaluated with CodeHaluEval · CodeHaluEval — Data Compliancehallucination rate: 20.19 -> 32.31Hurt
Use GPT-4 rather than GPT-3.5Code generation models evaluated with CodeHaluEval · CodeHaluEval — Structure Accesshallucination rate: 22.05 -> 10.02Helped
Use Claude-3-haiku rather than GPT-4Code generation models evaluated with CodeHaluEval · CodeHaluEval — Identityhallucination rate: 27.74 -> 9.07Helped
Use LLaMA-3-8B rather than GPT-4Code generation models evaluated with CodeHaluEval · CodeHaluEval — Logic Deviationhallucination rate: 85.76 -> 78.39Helped
Use GPT-4 rather than Gemma-7BCode generation models evaluated with CodeHaluEval · CodeHaluEval — Logic Breakdownhallucination rate: 100.00 -> 0.51Helped
Use GPT-4 rather than LLaMA-3-8BCode generation models evaluated with CodeHaluEval · CodeHaluEvalaverage hallucination rate: 33.67 -> 33.04No clear effect

Surprising findings

Limitations

Experimental setup

Datasets: APPS

Benchmarks: CodeHaluEval

Metrics: Hallucination Rate (HR)

Baselines: GPT-4 GPT-3.5 LLaMA-3-8B DeepSeek Coder-6.7B Claude-3-haiku Code LLaMA-7B StarCoder-16B WizardCoder-7B

Builds on: APPS HumanEval

Closest papers by meaning

Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.

Open scime draft

Get the next scime Dispatch and a monthly field update

Free. We send a confirmation link first; every email has a one-click unsubscribe. Privacy