mlsanityData to 7 Oct 2026

CodeMirage: Hallucinations in Code Generated by Large Language Models

arXiv 2408.08333 ↗First posted 14 Aug 2024cs.SE cs.AI cs.CLcited by 23

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

  1. 2022Training language models to follow instructions with human feedbackcited by 15,712
  2. 2023Llama 2: Open Foundation and Fine-Tuned Chat Modelscited by 12,865
  3. 2021Evaluating Large Language Models Trained on Codecited by 8,053
  4. 2021Program Synthesis with Large Language Modelscited by 3,509
  5. 2023Code Llama: Open Foundation Models for Codecited by 2,105
  6. 2022Survey of Hallucination in Natural Language Generationcited by 2,056
  7. 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,332
  8. 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
  9. 2020On Faithfulness and Factuality in Abstractive Summarizationcited by 895
  10. 2021CodeXGLUE: A Machine Learning Benchmark Dataset for Code Understanding and Generationcited by 732
  11. 2023Siren's Song in the AI Ocean: A Survey on Hallucination in Large Language Modelscited by 695
  12. 2023Harnessing the Power of LLMs in Practice: A Survey on ChatGPT and Beyondcited by 409
12 more
  1. 2023LLM-Adapters: An Adapter Family for Parameter-Efficient Fine-Tuning of Large Language Modelscited by 317
  2. 2021Retrieval Augmented Code Generation and Summarizationcited by 148
  3. 2023An Empirical Study of the Non-determinism of ChatGPT in Code Generationcited by 134
  4. 2023Purple Llama CyberSecEval: A Secure Coding Benchmark for Language Modelscited by 130
  5. 2023Can ChatGPT Reproduce Human-Generated Labels? A Study of Social Computing Taskscited by 88
  6. 2021The Factual Inconsistency Problem in Abstractive Text Summarization: A Surveycited by 79
  7. 2024A New Era in LLM Security: Exploring Security Concerns in Real-World LLM-based Systemscited by 74
  8. 2023AI-assisted coding: Experiments with GPT-4cited by 43
  9. 2023Large Language Models of Code Fail at Completing Code with Potential Bugscited by 28
  10. 2023AI in the Gray: Exploring Moderation Policies in Dialogic Large Language Models vs. Human Answers in Controversial Topicscited by 12
  11. 2024Software Vulnerability and Functionality Assessment using LLMscited by 11
  12. 2023HateRephrase: Zero- and Few-Shot Reduction of Hate Intensity in Online Posts using Large Language Modelscited by 8

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2024: 2; 2025: 10; 2026: 11.

23 papers.

Sort:

By area:

  1. 2024Agents in Software Engineering: Survey, Landscape, and Visioncited by 60
  2. 2024MedHalu: Hallucinations in Responses to Healthcare Queries by Large Language Modelscited by 20
  3. 2025SetupBench: Assessing Software Engineering Agents' Ability to Bootstrap Development Environmentscited by 18
  4. 2025From Code Foundation Models to Agents and Applications: A Comprehensive Survey and Practical Guide to Code Intelligencecited by 13
  5. 2026ALL-FEM: Agentic Large Language models Fine-tuned for Finite Element Methodscited by 12
  6. 2025Bridging LLM Planning Agents and Formal Methods: A Case Study in Plan Verificationcited by 6
  7. 2026PatchWorld: Gradient-Free Optimization of Executable World Models for Agent Environmentscited by 5
  8. 2025ALMAS: an Autonomous LLM-based Multi-Agent Software Engineering Frameworkcited by 4
  9. 2025Benchmarking AI Models in Software Engineering: A Review, Search Tool, and Unified Approach for Elevating Benchmark Qualitycited by 3
  10. 2025The Fools are Certain; the Wise are Doubtful: Exploring LLM Confidence in Code Completioncited by 3
  11. 2025Securing LLM-Generated Embedded Firmware through AI Agent-Driven Validation and Patchingcited by 3
  12. 2025SOK: Exploring Hallucinations and Security Risks in AI-Assisted Software Development with Insights for LLM Deploymentcited by 2
11 more
  1. 2025Chemical classification program synthesis using generative artificial intelligencecited by 1
  2. 2026From Natural Language to Executable Option Strategies via Large Language Modelscited by 1
  3. 2026Bridging Generation and Training: A Systematic Review of Quality Issues in LLMs for Codecited by 1
  4. 2026Delulu: A Verified Multi-Lingual Benchmark for Code Hallucination Detection in Fill-in-the-Middle Taskscited by 1
  5. 2026Beyond Document Grounding: Span-Level Hallucination Detection over Code, Tool Output, and Documentscited by 1
  6. 2025DuoLens: A Framework for Robust Detection of Machine-Generated Multilingual Text and Codecited by 0
  7. 2026ConceptRM: The Quest to Mitigate Alert Fatigue through Consensus-Based Purity-Driven Data Cleaning for Reflection Modellingcited by 0
  8. 2026RepoReviewer: A Local-First Multi-Agent Architecture for Repository-Level Code Reviewcited by 0
  9. 2026Task Abstention for Large Language Models in Code Generationcited by 0
  10. 2026Helpful or Harmful? Evaluating LLM-Assisted Vulnerability Patching via a Human Studycited by 0
  11. 2026Efficiency Hallucination: Formalizing and Measuring Behavioral Calibration in LLM-Based Code Optimizationcited by 0