mlsanityData to 7 Oct 2026

Beyond Functional Correctness: Exploring Hallucinations in LLM-Generated Code

arXiv 2404.00971 ↗First posted 1 Apr 2024cs.SE cs.AIcited by 106

Not on the map. Why?

Abstract (arXiv)

The rise of Large Language Models (LLMs) has significantly advanced various applications on software engineering tasks, particularly in code generation. Despite the promising performance, LLMs are prone to generate hallucinations, which means LLMs might produce outputs that deviate from users' intent, exhibit internal inconsistencies, or misaligned with the real-world knowledge, making the deployment of LLMs potentially risky in a wide range of applications. Existing work mainly focuses on investigating the hallucination in the domain of Natural Language Generation (NLG), leaving a gap in comprehensively understanding the types, causes, and impacts of hallucinations in the context of code generation. To bridge the gap, we conducted a thematic analysis of the LLM-generated code to summarize and categorize the hallucinations, as well as their causes and impacts. Our study established a comprehensive taxonomy of code hallucinations, encompassing 3 primary categories and 12 specific categories. Furthermore, we systematically analyzed the distribution of hallucinations, exploring variations among different LLMs and benchmarks. Moreover, we perform an in-depth analysis on the causes and impacts of various hallucinations, aiming to provide valuable insights into hallucination mitigation. Finally, to enhance the correctness and reliability of LLM-generated code in a lightweight manner, we explore training-free hallucination mitigation approaches by prompt enhancing techniques. We believe our findings will shed light on future research about code hallucination evaluation and mitigation, ultimately paving the way for building more effective and reliable code LLMs in the future. The replication package is available at https://github.com/Lorien1128/code_hallucination

Key facts. Cited by 106 papers in the map (data through 7 Oct 2026). Builds on 53 of its 87 references that are in the map. First posted on arXiv 1 Apr 2024.

Builds on

53 of 87 references.

References · 53

  1. 2022Chain-of-Thought Prompting Elicits Reasoning in Large Language Modelscited by 12,302
  2. 2020Retrieval-Augmented Generation for Knowledge-Intensive NLP Taskscited by 9,160
  3. 2021Evaluating Large Language Models Trained on Codecited by 8,053
  4. 2021Program Synthesis with Large Language Modelscited by 3,509
  5. 2019The Curious Case of Neural Text Degenerationcited by 2,881
  6. 2023Code Llama: Open Foundation Models for Codecited by 2,105
  7. 2022Survey of Hallucination in Natural Language Generationcited by 2,056
  8. 2024LiveCodeBench: Holistic and Contamination Free Evaluation of Large Language Models for Codecited by 1,906
  9. 2023Improving Factuality and Reasoning in Language Models through Multiagent Debatecited by 1,739
  10. 2023A Survey on Hallucination in Large Language Models: Principles, Taxonomy, Challenges, and Open Questionscited by 1,582
  11. 2022Competition-Level Code Generation with AlphaCodecited by 1,427
  12. 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,332
38 more
  1. 2023Inference-Time Intervention: Eliciting Truthful Answers from a Language Modelcited by 1,259
  2. 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,154
  3. 2020On Faithfulness and Factuality in Abstractive Summarizationcited by 895
  4. 2021Measuring Coding Challenge Competence With APPScited by 879
  5. 2022CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesiscited by 876
  6. 2023StarCoder: may the source be with you!cited by 790
  7. 2023REPLUG: Retrieval-Augmented Black-Box Language Modelscited by 786
  8. 2021Deduplicating Training Data Makes Language Models Bettercited by 705
  9. 2023Siren's Song in the AI Ocean: A Survey on Hallucination in Large Language Modelscited by 695
  10. 2022InCoder: A Generative Model for Code Infilling and Synthesiscited by 492
  11. 2022DS-1000: A Natural and Reliable Benchmark for Data Science Code Generationcited by 442
  12. 2023Fine-Grained Human Feedback Gives Better Rewards for Language Model Trainingcited by 399
  13. 2023RepoCoder: Repository-Level Code Completion Through Iterative Retrieval and Generationcited by 357
  14. 2024Retrieval-Augmented Generation for AI-Generated Content: A Surveycited by 352
  15. 2023Check Your Facts and Try Again: Improving Large Language Models with External Knowledge and Automated Feedbackcited by 351
  16. 2023Adaptive Chameleon or Stubborn Sloth: Revealing the Behavior of Large Language Models in Knowledge Conflictscited by 333
  17. 2023How Language Model Hallucinations Can Snowballcited by 310
  18. 2020Unsupervised Translation of Programming Languagescited by 262
  19. 2023FacTool: Factuality Detection in Generative AI -- A Tool Augmented Framework for Multi-Task and Multi-Domain Scenarioscited by 247
  20. 2019Challenges in Building Intelligent Open-domain Dialog Systemscited by 147
  21. 2022Practical Program Repair in the Era of Large Pre-trained Language Modelscited by 133
  22. 2023CodeGen2: Lessons for Training LLMs on Programming and Natural Languagescited by 124
  23. 2023Self-Edit: Fault-Aware Code Editor for Code Generationcited by 110
  24. 2022Automating Code Review Activities by Large-Scale Pre-trainingcited by 98
  25. 2023No More Manual Tests? Evaluating and Improving ChatGPT for Unit Test Generationcited by 82
  26. 2023Refining ChatGPT-Generated Code: Characterizing and Mitigating Code Quality Issuescited by 78
  27. 2023Can ChatGPT replace StackOverflow? A Study on Robustness and Reliability of Large Language Model Code Generationcited by 72
  28. 2023Evaluating the Code Quality of AI-Assisted Code Generation Tools: An Empirical Study on GitHub Copilot, Amazon CodeWhisperer, and ChatGPTcited by 71
  29. 2023Factually Consistent Summarization via Reinforcement Learning with Textual Entailment Feedbackcited by 71
  30. 2024Bugs in Large Language Models Generated Code: An Empirical Studycited by 59
  31. 2022Entity Cloze By Date: What LMs Know About Unseen Entitiescited by 55
  32. 2023LLaMA-Reviewer: Advancing Code Review Automation with Large Language Models through Parameter-Efficient Fine-Tuningcited by 47
  33. 2023Large Language Models and Simple, Stupid Bugscited by 45
  34. 2023No Need to Lift a Finger Anymore? Assessing the Quality of Code Generation by ChatGPTcited by 45
  35. 2021Controlling Hallucinations at Word Level in Data-to-Text Generationcited by 41
  36. 2020Synthesize, Execute and Debug: Learning to Repair for Neural Program Synthesiscited by 39
  37. 2024CYCLE: Learning to Self-Refine the Code Generationcited by 39
  38. 2019How Often Do Single-Statement Bugs Occur? The ManySStuBs4J Datasetcited by 35

50 most cited of 53 All 53 (JSON)

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2024: 40; 2025: 50; 2026: 16.

106 papers.

Sort:

By area:

  1. 2024SAFREE: Training-Free and Adaptive Guard for Safe Text-to-Image And Video Generationcited by 125
  2. 2024LLM Hallucinations in Practical Code Generation: Phenomena, Mechanism, and Mitigationcited by 92
  3. 2024We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMscited by 61
  4. 2024Agents in Software Engineering: Survey, Landscape, and Visioncited by 60
  5. 2024Exploring and Unleashing the Power of Large Language Models in Automated Code Translationcited by 57
  6. 2024What's Wrong with Your Code Generated by Large Language Models? An Extensive Studycited by 52
  7. 2024Context-DPO: Aligning Language Models for Context-Faithfulnesscited by 50
  8. 2025Parameters vs. Context: Fine-Grained Control of Knowledge Reliance in Language Modelscited by 38
  9. 2024A Large Language Model-Driven Reward Design Framework via Dynamic Feedback for Reinforcement Learningcited by 29
  10. 2024A Survey of Useful LLM Evaluationcited by 28
  11. 2025SemEval-2025 Task 3: Mu-SHROOM, the Multilingual Shared Task on Hallucinations and Related Observable Overgeneration Mistakescited by 27
  12. 2025Estimating LLM Uncertainty with Evidencecited by 26
38 more
  1. 2025ProjectEval: A Benchmark for Programming Agents Automated Evaluation on Project-Level Code Generationcited by 26
  2. 2025AI Agentic Programming: A Survey of Techniques, Challenges, and Opportunitiescited by 26
  3. 2024Security of AI Agentscited by 24
  4. 2024Rome was Not Built in a Single Step: Hierarchical Prompting for LLM-based Chip Designcited by 24
  5. 2024On Mitigating Code LLM Hallucinations with API Documentationcited by 21
  6. 2024An LLM Agent for Automatic Geospatial Data Analysiscited by 21
  7. 2025VeriPlan: Integrating Formal Verification and LLMs into End-User Planningcited by 19
  8. 2024CodeMMLU: A Multi-Task Benchmark for Assessing Code Understanding & Reasoning Capabilities of CodeLLMscited by 18
  9. 2024Automated test generation to evaluate tool-augmented LLMs as conversational AI agentscited by 17
  10. 2024Cost-Effective Hallucination Detection for LLMscited by 16
  11. 2024Assessing and Verifying Task Utility in LLM-Powered Applicationscited by 15
  12. 2024Towards Rationality in Language and Multimodal Agents: A Surveycited by 15
  13. 2025An Empirical Study on Failures in Automated Issue Solvingcited by 15
  14. 2024Are LLMs Correctly Integrated into Software Systems?cited by 13
  15. 2024Collu-Bench: A Benchmark for Predicting Language Model Hallucinations in Codecited by 13
  16. 2025Trust Region Masking for Long-Horizon LLM Reinforcement Learningcited by 13
  17. 2025DeepSeek vs. ChatGPT vs. Claude: A Comparative Study for Scientific Computing and Scientific Machine Learning Taskscited by 12
  18. 2025HiBench: Benchmarking LLMs Capability on Hierarchical Structure Reasoningcited by 12
  19. 2025Towards Spoken Mathematical Reasoning: Benchmarking Speech-based Models over Multi-faceted Math Problemscited by 12
  20. 2025Robustness in Large Language Models: A Survey of Mitigation Strategies and Evaluation Metricscited by 12
  21. 2024A Deep Dive Into Large Language Model Code Generation Mistakes: What and Why?cited by 9
  22. 2025Hallucination by Code Generation LLMs: Taxonomy, Benchmarks, Mitigation, and Challengescited by 9
  23. 2025Inverse IFEval: Can LLMs Unlearn Stubborn Training Conventions to Follow Real Instructions?cited by 9
  24. 2025Investigating The Smells of LLM Generated Codecited by 9
  25. 2025A Lightweight Large Language Model-Based Multi-Agent System for 2D Frame Structural Analysiscited by 9
  26. 2024LProtector: An LLM-driven Vulnerability Detection Systemcited by 8
  27. 2024A Survey of Calibration Process for Black-Box LLMscited by 8
  28. 2025TestForge: Feedback-Driven, Agentic Test Suite Generationcited by 8
  29. 2024A Survey of Automatic Hallucination Evaluation on Natural Language Generationcited by 7
  30. 2024FLARE: Faithful Logic-Aided Reasoning and Explorationcited by 7
  31. 2024Collaboration Dynamics and Reliability Challenges of Multi-Agent LLM Systems in Finite Element Analysiscited by 6
  32. 2024A Methodology for Evaluating RAG Systems: A Case Study On Configuration Dependency Validationcited by 6
  33. 2025Jakiro: Boosting Speculative Decoding with Decoupled Multi-Head via MoEcited by 6
  34. 2025Pragmatic Reasoning improves LLM Code Generationcited by 6
  35. 2025Evaluating Evaluation Metrics -- The Mirage of Hallucination Detectioncited by 6
  36. 2025Towards Mitigating API Hallucination in Code Generated by LLMs with Hierarchical Dependency Awarecited by 6
  37. 2025MedOmni-45deg: A Safety-Performance Benchmark for Reasoning-Oriented LLMs in Medicinecited by 6
  38. 2024Code Hallucinationcited by 5

50 most cited of 106 All 106 (JSON)