HackerPapers

arXiv:2406.10279cs.SE

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

Joseph Spracklen, Raveen Wijewickrama, A H M Nazmus Sakib, Anindya Maiti, Bimal Viswanath, Murtuza Jadliwala

Abstract

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.

arXiv comments
To appear in the 2025 USENIX Security Symposium. 22 pages, 14 figures, 8 tables. Edited from original version for submission to a different conference. No change to original results or findings
Journal reference
DOI
Subjects
cs.SESoftware Engineering cs.AIArtificial Intelligence cs.CRCryptography and Security cs.LGMachine Learning

On Hacker News

Linked by 2 identifiable commenters in 2 comments across 2 threads, from Apr 2025 to Nov 2025. Found in 1 HN submission from Oct 2024 to Oct 2024. Open submission discussions.

Comments linking this paper, per year.

Discussed in comments2 threads

    • Here's another one that went un-cited: > When you ask AI to generate code with dependencies, it hallucinates non-existent packages 19.7% of the time. One. In. Five. > Researchers generated 2.23 million packages across various prompts. 440,445 were complete fabrications.…

      simonwView on HNParent context

    • socket article seems to mostly be a review of this arXiv preprint paper: https://arxiv.org/pdf/2406.10279 there’s also some info from Python software foundation folks in the register article, so it’s not just a socket pitch article.

      dijksterhuisView on HNParent context

Submitted to Hacker News

Connected through shared HN threads, not inferred similarity or a recommendation.