CodeMirage: Hallucinations in Code Generated by Large Language Models
Not on the map. Why?
Abstract (arXiv)
Large Language Models (LLMs) have shown promising potentials in program generation and no-code automation. However, LLMs are prone to generate hallucinations, i.e., they generate text which sounds plausible but is incorrect. Although there has been a recent surge in research on LLM hallucinations for text generation, similar hallucination phenomenon can happen in code generation. Sometimes the generated code can have syntactical or logical errors as well as more advanced issues like security vulnerabilities, memory leaks, etc. Given the wide adaptation of LLMs to enhance efficiency in code generation and development in general, it becomes imperative to investigate hallucinations in code generation. To the best of our knowledge, this is the first attempt at studying hallucinations in the code generated by LLMs. We start by introducing the code hallucination definition and a comprehensive taxonomy of code hallucination types. We propose the first benchmark CodeMirage dataset for code hallucinations. The benchmark contains 1,137 GPT-3.5 generated hallucinated code snippets for Python programming problems from two base datasets - HumanEval and MBPP. We then propose the methodology for code hallucination detection and experiment with open source LLMs such as CodeLLaMA as well as OpenAI's GPT-3.5 and GPT-4 models using one-shot prompt. We find that GPT-4 performs the best on HumanEval dataset and gives comparable results to the fine-tuned CodeBERT baseline on MBPP dataset. Towards the end, we discuss various mitigation strategies for code hallucinations and conclude our work.
Key facts. Cited by 23 papers in the map (data through 7 Oct 2026). Builds on 24 of its 34 references that are in the map. First posted on arXiv 14 Aug 2024.
Builds on
24 of 34 references.
References · 24
- 2022Training language models to follow instructions with human feedbackcited by 15,712
- 2023Llama 2: Open Foundation and Fine-Tuned Chat Modelscited by 12,865
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2021Program Synthesis with Large Language Modelscited by 3,509
- 2023Code Llama: Open Foundation Models for Codecited by 2,105
- 2022Survey of Hallucination in Natural Language Generationcited by 2,056
- 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,332
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
- 2020On Faithfulness and Factuality in Abstractive Summarizationcited by 895
- 2021CodeXGLUE: A Machine Learning Benchmark Dataset for Code Understanding and Generationcited by 732
- 2023Siren's Song in the AI Ocean: A Survey on Hallucination in Large Language Modelscited by 695
- 2023Harnessing the Power of LLMs in Practice: A Survey on ChatGPT and Beyondcited by 409
12 more
- 2023LLM-Adapters: An Adapter Family for Parameter-Efficient Fine-Tuning of Large Language Modelscited by 317
- 2021Retrieval Augmented Code Generation and Summarizationcited by 148
- 2023An Empirical Study of the Non-determinism of ChatGPT in Code Generationcited by 134
- 2023Purple Llama CyberSecEval: A Secure Coding Benchmark for Language Modelscited by 130
- 2023Can ChatGPT Reproduce Human-Generated Labels? A Study of Social Computing Taskscited by 88
- 2021The Factual Inconsistency Problem in Abstractive Text Summarization: A Surveycited by 79
- 2024A New Era in LLM Security: Exploring Security Concerns in Real-World LLM-based Systemscited by 74
- 2023AI-assisted coding: Experiments with GPT-4cited by 43
- 2023Large Language Models of Code Fail at Completing Code with Potential Bugscited by 28
- 2023AI in the Gray: Exploring Moderation Policies in Dialogic Large Language Models vs. Human Answers in Controversial Topicscited by 12
- 2024Software Vulnerability and Functionality Assessment using LLMscited by 11
- 2023HateRephrase: Zero- and Few-Shot Reduction of Hate Intensity in Online Posts using Large Language Modelscited by 8
Built on by
Citing papers per year: 2024: 2; 2025: 10; 2026: 11.
23 papers.
Sort:
By area:
- 2024Agents in Software Engineering: Survey, Landscape, and Visioncited by 60
- 2024MedHalu: Hallucinations in Responses to Healthcare Queries by Large Language Modelscited by 20
- 2025SetupBench: Assessing Software Engineering Agents' Ability to Bootstrap Development Environmentscited by 18
- 2025From Code Foundation Models to Agents and Applications: A Comprehensive Survey and Practical Guide to Code Intelligencecited by 13
- 2026ALL-FEM: Agentic Large Language models Fine-tuned for Finite Element Methodscited by 12
- 2025Bridging LLM Planning Agents and Formal Methods: A Case Study in Plan Verificationcited by 6
- 2026PatchWorld: Gradient-Free Optimization of Executable World Models for Agent Environmentscited by 5
- 2025ALMAS: an Autonomous LLM-based Multi-Agent Software Engineering Frameworkcited by 4
- 2025Benchmarking AI Models in Software Engineering: A Review, Search Tool, and Unified Approach for Elevating Benchmark Qualitycited by 3
- 2025The Fools are Certain; the Wise are Doubtful: Exploring LLM Confidence in Code Completioncited by 3
- 2025Securing LLM-Generated Embedded Firmware through AI Agent-Driven Validation and Patchingcited by 3
- 2025SOK: Exploring Hallucinations and Security Risks in AI-Assisted Software Development with Insights for LLM Deploymentcited by 2
11 more
- 2025Chemical classification program synthesis using generative artificial intelligencecited by 1
- 2026From Natural Language to Executable Option Strategies via Large Language Modelscited by 1
- 2026Bridging Generation and Training: A Systematic Review of Quality Issues in LLMs for Codecited by 1
- 2026Delulu: A Verified Multi-Lingual Benchmark for Code Hallucination Detection in Fill-in-the-Middle Taskscited by 1
- 2026Beyond Document Grounding: Span-Level Hallucination Detection over Code, Tool Output, and Documentscited by 1
- 2025DuoLens: A Framework for Robust Detection of Machine-Generated Multilingual Text and Codecited by 0
- 2026ConceptRM: The Quest to Mitigate Alert Fatigue through Consensus-Based Purity-Driven Data Cleaning for Reflection Modellingcited by 0
- 2026RepoReviewer: A Local-First Multi-Agent Architecture for Repository-Level Code Reviewcited by 0
- 2026Task Abstention for Large Language Models in Code Generationcited by 0
- 2026Helpful or Harmful? Evaluating LLM-Assisted Vulnerability Patching via a Human Studycited by 0
- 2026Efficiency Hallucination: Formalizing and Measuring Behavioral Calibration in LLM-Based Code Optimizationcited by 0
- 2026Efficiency Hallucination: Formalizing and Measuring Behavioral Calibration in LLM-Based Code Optimization13 Sep 2026
- 2026Beyond Document Grounding: Span-Level Hallucination Detection over Code, Tool Output, and Documents1 Jul 2026
- 2026Helpful or Harmful? Evaluating LLM-Assisted Vulnerability Patching via a Human Study24 Jun 2026
- 2026PatchWorld: Gradient-Free Optimization of Executable World Models for Agent Environments29 May 2026
- 2026Task Abstention for Large Language Models in Code Generation16 May 2026
- 2026Delulu: A Verified Multi-Lingual Benchmark for Code Hallucination Detection in Fill-in-the-Middle Tasks7 May 2026
- 2026Bridging Generation and Training: A Systematic Review of Quality Issues in LLMs for Code6 May 2026
- 2026From Natural Language to Executable Option Strategies via Large Language Models17 Mar 2026
- 2026RepoReviewer: A Local-First Multi-Agent Architecture for Repository-Level Code Review17 Mar 2026
- 2026ConceptRM: The Quest to Mitigate Alert Fatigue through Consensus-Based Purity-Driven Data Cleaning for Reflection Modelling9 Feb 2026
- 2026ALL-FEM: Agentic Large Language models Fine-tuned for Finite Element Methods8 Jan 2026
- 2025From Code Foundation Models to Agents and Applications: A Comprehensive Survey and Practical Guide to Code Intelligence23 Nov 2025
11 more
- 2025DuoLens: A Framework for Robust Detection of Machine-Generated Multilingual Text and Code21 Oct 2025
- 2025Bridging LLM Planning Agents and Formal Methods: A Case Study in Plan Verification3 Oct 2025
- 2025ALMAS: an Autonomous LLM-based Multi-Agent Software Engineering Framework3 Oct 2025
- 2025Securing LLM-Generated Embedded Firmware through AI Agent-Driven Validation and Patching12 Sep 2025
- 2025The Fools are Certain; the Wise are Doubtful: Exploring LLM Confidence in Code Completion22 Aug 2025
- 2025SetupBench: Assessing Software Engineering Agents' Ability to Bootstrap Development Environments11 Jul 2025
- 2025Chemical classification program synthesis using generative artificial intelligence24 May 2025
- 2025Benchmarking AI Models in Software Engineering: A Review, Search Tool, and Unified Approach for Elevating Benchmark Quality7 Mar 2025
- 2025SOK: Exploring Hallucinations and Security Risks in AI-Assisted Software Development with Insights for LLM Deployment31 Jan 2025
- 2024MedHalu: Hallucinations in Responses to Healthcare Queries by Large Language Models29 Sep 2024
- 2024Agents in Software Engineering: Survey, Landscape, and Vision13 Sep 2024
- 2024Agents in Software Engineering: Survey, Landscape, and Visioncited by 60
- 2025SetupBench: Assessing Software Engineering Agents' Ability to Bootstrap Development Environmentscited by 18
- 2025From Code Foundation Models to Agents and Applications: A Comprehensive Survey and Practical Guide to Code Intelligencecited by 13
- 2026ALL-FEM: Agentic Large Language models Fine-tuned for Finite Element Methodscited by 12
- 2025Bridging LLM Planning Agents and Formal Methods: A Case Study in Plan Verificationcited by 6
- 2025ALMAS: an Autonomous LLM-based Multi-Agent Software Engineering Frameworkcited by 4
- 2025Securing LLM-Generated Embedded Firmware through AI Agent-Driven Validation and Patchingcited by 3
- 2026ALL-FEM: Agentic Large Language models Fine-tuned for Finite Element Methods8 Jan 2026
- 2025From Code Foundation Models to Agents and Applications: A Comprehensive Survey and Practical Guide to Code Intelligence23 Nov 2025
- 2025Bridging LLM Planning Agents and Formal Methods: A Case Study in Plan Verification3 Oct 2025
- 2025ALMAS: an Autonomous LLM-based Multi-Agent Software Engineering Framework3 Oct 2025
- 2025Securing LLM-Generated Embedded Firmware through AI Agent-Driven Validation and Patching12 Sep 2025
- 2025SetupBench: Assessing Software Engineering Agents' Ability to Bootstrap Development Environments11 Jul 2025
- 2024Agents in Software Engineering: Survey, Landscape, and Vision13 Sep 2024
- 2024MedHalu: Hallucinations in Responses to Healthcare Queries by Large Language Modelscited by 20
- 2025Benchmarking AI Models in Software Engineering: A Review, Search Tool, and Unified Approach for Elevating Benchmark Qualitycited by 3
- 2025The Fools are Certain; the Wise are Doubtful: Exploring LLM Confidence in Code Completioncited by 3
- 2025SOK: Exploring Hallucinations and Security Risks in AI-Assisted Software Development with Insights for LLM Deploymentcited by 2
- 2025Chemical classification program synthesis using generative artificial intelligencecited by 1
- 2026From Natural Language to Executable Option Strategies via Large Language Modelscited by 1
- 2026Bridging Generation and Training: A Systematic Review of Quality Issues in LLMs for Codecited by 1
- 2026Delulu: A Verified Multi-Lingual Benchmark for Code Hallucination Detection in Fill-in-the-Middle Taskscited by 1
- 2025DuoLens: A Framework for Robust Detection of Machine-Generated Multilingual Text and Codecited by 0
- 2026ConceptRM: The Quest to Mitigate Alert Fatigue through Consensus-Based Purity-Driven Data Cleaning for Reflection Modellingcited by 0
- 2026RepoReviewer: A Local-First Multi-Agent Architecture for Repository-Level Code Reviewcited by 0
- 2026Task Abstention for Large Language Models in Code Generationcited by 0
12 most cited of 14 All 14 (JSON)
- 2026Efficiency Hallucination: Formalizing and Measuring Behavioral Calibration in LLM-Based Code Optimization13 Sep 2026
- 2026Helpful or Harmful? Evaluating LLM-Assisted Vulnerability Patching via a Human Study24 Jun 2026
- 2026Task Abstention for Large Language Models in Code Generation16 May 2026
- 2026Delulu: A Verified Multi-Lingual Benchmark for Code Hallucination Detection in Fill-in-the-Middle Tasks7 May 2026
- 2026Bridging Generation and Training: A Systematic Review of Quality Issues in LLMs for Code6 May 2026
- 2026From Natural Language to Executable Option Strategies via Large Language Models17 Mar 2026
- 2026RepoReviewer: A Local-First Multi-Agent Architecture for Repository-Level Code Review17 Mar 2026
- 2026ConceptRM: The Quest to Mitigate Alert Fatigue through Consensus-Based Purity-Driven Data Cleaning for Reflection Modelling9 Feb 2026
- 2025DuoLens: A Framework for Robust Detection of Machine-Generated Multilingual Text and Code21 Oct 2025
- 2025The Fools are Certain; the Wise are Doubtful: Exploring LLM Confidence in Code Completion22 Aug 2025
- 2025Chemical classification program synthesis using generative artificial intelligence24 May 2025
- 2025Benchmarking AI Models in Software Engineering: A Review, Search Tool, and Unified Approach for Elevating Benchmark Quality7 Mar 2025
12 newest of 14 All 14 (JSON)