mlsanityData to 7 Oct 2026

We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMs

arXiv 2406.10279 ↗First posted 12 Jun 2024cs.SE cs.AI cs.CRcited by 61

Not on the map. Why?

Abstract (arXiv)

The reliance of popular programming languages such as Python and JavaScript on centralized package repositories and open-source software, combined with the emergence of code-generating Large Language Models (LLMs), has created a new type of threat to the software supply chain: package hallucinations. These hallucinations, which arise from fact-conflicting errors when generating code using LLMs, represent a novel form of package confusion attack that poses a critical threat to the integrity of the software supply chain. This paper conducts a rigorous and comprehensive evaluation of package hallucinations across different programming languages, settings, and parameters, exploring how a diverse set of models and configurations affect the likelihood of generating erroneous package recommendations and identifying the root causes of this phenomenon. Using 16 popular LLMs for code generation and two unique prompt datasets, we generate 576,000 code samples in two programming languages that we analyze for package hallucinations. Our findings reveal that that the average percentage of hallucinated packages is at least 5.2% for commercial models and 21.7% for open-source models, including a staggering 205,474 unique examples of hallucinated package names, further underscoring the severity and pervasiveness of this threat. To overcome this problem, we implement several hallucination mitigation strategies and show that they are able to significantly reduce the number of package hallucinations while maintaining code quality. Our experiments and findings highlight package hallucinations as a persistent and systemic phenomenon while using state-of-the-art LLMs for code generation, and a significant challenge which deserves the research community's urgent attention.

Key facts. Cited by 61 papers in the map (data through 7 Oct 2026). Builds on 53 of its 97 references that are in the map. First posted on arXiv 12 Jun 2024.

Builds on

53 of 97 references.

References · 53

  1. 2017Attention Is All You Needcited by 59,932
  2. 2018BERT: Pre-training of Deep Bidirectional Transformers for Language Understandingcited by 40,204
  3. 2021Learning Transferable Visual Models From Natural Language Supervisioncited by 33,456
  4. 2020Language Models are Few-Shot Learnerscited by 32,199
  5. 2021High-Resolution Image Synthesis with Latent Diffusion Modelscited by 18,694
  6. 2023GPT-4 Technical Reportcited by 18,132
  7. 2020Retrieval-Augmented Generation for Knowledge-Intensive NLP Taskscited by 9,160
  8. 2021Evaluating Large Language Models Trained on Codecited by 8,053
  9. 2021Zero-Shot Text-to-Image Generationcited by 4,276
  10. 2021On the Opportunities and Risks of Foundation Modelscited by 3,961
  11. 2023Self-Refine: Iterative Refinement with Self-Feedbackcited by 3,317
  12. 2021TruthfulQA: Measuring How Models Mimic Human Falsehoodscited by 2,919
38 more
  1. 2019The Curious Case of Neural Text Degenerationcited by 2,881
  2. 2023Code Llama: Open Foundation Models for Codecited by 2,105
  3. 2022Survey of Hallucination in Natural Language Generationcited by 2,056
  4. 2023A Survey on Hallucination in Large Language Models: Principles, Taxonomy, Challenges, and Open Questionscited by 1,582
  5. 2023Jailbroken: How Does LLM Safety Training Fail?cited by 1,565
  6. 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,332
  7. 2023Inference-Time Intervention: Eliciting Truthful Answers from a Language Modelcited by 1,259
  8. 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,154
  9. 2020On Faithfulness and Factuality in Abstractive Summarizationcited by 895
  10. 2023WizardCoder: Empowering Code Large Language Models with Evol-Instructcited by 728
  11. 2023Siren's Song in the AI Ocean: A Survey on Hallucination in Large Language Modelscited by 695
  12. 2023Bias and Fairness in Large Language Models: A Surveycited by 626
  13. 2023Jailbreaking ChatGPT via Prompt Engineering: An Empirical Studycited by 478
  14. 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 417
  15. 2023Multi-step Jailbreaking Privacy Attacks on ChatGPTcited by 320
  16. 2022AudioGen: Textually Guided Audio Generationcited by 292
  17. 2023Exploiting Programmatic Behavior of LLMs: Dual-Use Through Standard Security Attackscited by 268
  18. 2024A Comprehensive Survey of Hallucination Mitigation Techniques in Large Language Modelscited by 266
  19. 2023OpenChat: Advancing Open-source Language Models with Mixed-Quality Datacited by 250
  20. 2023Fine-tuning Language Models for Factualitycited by 219
  21. 2022BlenderBot 3: a deployed conversational agent that continually learns to responsibly engagecited by 197
  22. 2022Do Users Write More Insecure Code with AI Assistants?cited by 186
  23. 2024VASA-1: Lifelike Audio-Driven Talking Faces Generated in Real Timecited by 186
  24. 2019Challenges in Building Intelligent Open-domain Dialog Systemscited by 147
  25. 2020On Exposure Bias, Hallucination and Domain Shift in Neural Machine Translationcited by 127
  26. 2021Neural Path Hunter: Reducing Hallucination in Dialogue Systems via Path Groundingcited by 106
  27. 2024Beyond Functional Correctness: Exploring Hallucinations in LLM-Generated Codecited by 106
  28. 2023Evaluating Cognitive Maps and Planning in Large Language Models with CogEvalcited by 77
  29. 2023A Large-Scale Survey on the Usability of AI Programming Assistants: Successes and Challengescited by 75
  30. 2023Exposing Attention Glitches with Flip-Flop Language Modelingcited by 74
  31. 2020Backstabber's Knife Collection: A Review of Open Source Software Supply Chain Attackscited by 57
  32. 2022Taxonomy of Attacks on Open-Source Software Supply Chainscited by 57
  33. 2022Entity Cloze By Date: What LMs Know About Unseen Entitiescited by 55
  34. 2023Spear Phishing With Large Language Modelscited by 49
  35. 2022RHO (ρ): Reducing Hallucination in Open-domain Dialogues with Knowledge Groundingcited by 47
  36. 2019Small World with High Risks: A Study of Security Threats in the npm Ecosystemcited by 36
  37. 2022Towards Improving Faithfulness in Abstractive Summarizationcited by 27
  38. 2023Instruction Position Matters in Sequence Generation with Large Language Modelscited by 10

50 most cited of 53 All 53 (JSON)

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2024: 5; 2025: 20; 2026: 36.

61 papers.

Sort:

By area:

  1. 2024Enhancing Code LLMs with Reinforcement Learning in Code Generation: A Surveycited by 82
  2. 2025Design Patterns for Securing LLM Agents against Prompt Injectionscited by 67
  3. 2026Prompt Injection Attacks on Agentic Coding Assistants: A Systematic Analysis of Vulnerabilities in Skills, Tools, and Protocol Ecosystemscited by 30
  4. 2026The Attack and Defense Landscape of Agentic AI: A Comprehensive Surveycited by 26
  5. 2025AgentSentinel: An End-to-End and Real-Time Security Defense Framework for Computer-Use Agentscited by 25
  6. 2026SkillSieve: A Hierarchical Triage Framework for Detecting Malicious AI Agent Skillscited by 18
  7. 2025DarkMind: Latent Chain-of-Thought Backdoor in Customized LLMscited by 15
  8. 2025Active Layer-Contrastive Decoding Reduces Hallucination in Large Language Model Generationcited by 10
  9. 2025Hallucination by Code Generation LLMs: Taxonomy, Benchmarks, Mitigation, and Challengescited by 9
  10. 2026SOK: A Taxonomy of Attack Vectors and Defense Strategies for Agentic Supply Chain Runtimecited by 8
  11. 2025A Unified Definition of Hallucination: It's The World Model, Stupid!cited by 6
  12. 2026Human oversight of agentic systems in practice: Examining the oversight work, challenges, and heuristics of developers using software agentscited by 6
38 more
  1. 2024ETF: An Entity Tracing Framework for Hallucination Detection in Code Summariescited by 5
  2. 2025RAG-Pull: Turning Retrieval into a Code-Injection Channel via Invisible Unicode Perturbationscited by 4
  3. 2026Trust Me, Import This: Dependency Steering Attacks via Malicious Agent Skillscited by 4
  4. 2025Hierarchical Memorization in Large Language Models: Evidence from Citation Generationcited by 3
  5. 2026Measuring and Exploiting Contextual Bias in LLM-Assisted Security Code Reviewcited by 3
  6. 2026What Breaks When LLMs Code? Characterizing Operational Safety Failures of Agentic Code Assistantscited by 3
  7. 2024A Comprehensive Framework for Evaluating API-oriented Code Generation in Large Language Modelscited by 2
  8. 2025Empirical Evaluation of AI-Assisted Software Package Selection: A Knowledge Graph Approachcited by 2
  9. 2025Hallucinations in Bibliographic Recommendation: Citation Frequency as a Proxy for Training Data Redundancycited by 2
  10. 2025CoTDeceptor:Adversarial Code Obfuscation Against CoT-Enhanced LLM Code Agentscited by 2
  11. 2024Hallucinating AI Hijacking Attack: Large Language Models and Malicious Code Recommenderscited by 1
  12. 2025VECSR: Virtually Embodied Common Sense Reasoning Systemcited by 1
  13. 2025Investigating Security Implications of Automatically Generated Code on the Software Supply Chaincited by 1
  14. 2025Library Hallucinations in LLM-Generated Code: A Risk Analysis Grounded in Developer Queriescited by 1
  15. 2025HFuzzer: Testing Large Language Models for Package Hallucinations via Phrase-based Fuzzingcited by 1
  16. 2025Margin Adaptive DPO: Leveraging Reward Model for Granular Control in Preference Optimizationcited by 1
  17. 2025Hound: Relation-First Knowledge Graphs for Complex-System Reasoning in Security Auditscited by 1
  18. 2025LLMs as Packagers of HPC Softwarecited by 1
  19. 2025Evidence-Driven Decision Support for AI Model Selection in Research Software Engineeringcited by 1
  20. 2026PMAx: An Agentic Framework for AI-Driven Process Miningcited by 1
  21. 2026Correct Code, Vulnerable Dependencies: A Large Scale Measurement Study of LLM-Specified Library Versionscited by 1
  22. 2026When Retrieval Hurts Code Completion: A Diagnostic Study of Stale Repository Contextcited by 1
  23. 2026Harmless Yet Harmful: Neutral Prompting Attacks for Stealthy Hallucination Steering in Agent Skillscited by 1
  24. 2026Can LLMs Write Correct TLA+ Specifications? Evaluating Natural-Language-to-TLA+ Generationcited by 1
  25. 2026Phantom References: Hallucinated Citations That Survive Peer Review at Top-Tier Conferencescited by 1
  26. 2026CodePoisonRAG: Knowledge Poisoning Attacks on Retrieval-Augmented Code Generationcited by 1
  27. 2026LabAgent: Customize Any Research Hubs for Scientific Discoveries Using AI Agentscited by 1
  28. 2024Improving Zero-Shot ObjectNav with Generative Communicationcited by 0
  29. 2025LLM Agents for Generating Microservice-based Applications: how complex is your specification?cited by 0
  30. 2026An Empirical Analysis of Static Analysis Methods for Detection and Mitigation of Code Library Hallucinationscited by 0
  31. 2026GoCoMA: Hyperbolic Multimodal Representation Fusion for Large Language Model-Generated Code Attributioncited by 0
  32. 2026LLM Ghostbusters: Surgical Package Hallucination Suppression via Adaptive Unlearningcited by 0
  33. 2026DiffusionHijack: Supply-Chain PRNG Backdoor Attack on Diffusion Models and Quantum Random Number Defensecited by 0
  34. 2026The Range Shrinks, the Threat Remains: Re-evaluating LLM Package Hallucinations on the 2026 Frontier-Model Cohortcited by 0
  35. 2026Stdlib or Third-Party? Empirical Performance and Correctness of LLM-Assisted Zero-Dependency Python Librariescited by 0
  36. 2026AI-driven Software Development: A Pragmatic Path to Agentic Development Processescited by 0
  37. 2026LibEvoBench: Probing Temporal Knowledge Stratification in Code Generation Modelscited by 0
  38. 2026Beware of Agentic Botnets: Scalable Untargeted Promptware Attacks via Universal and Transferable Adversarial HalluSquattingcited by 0

50 most cited of 61 All 61 (JSON)