Verify before install
Confirm that an AI-suggested dependency exists and is the package you intended before it is used. This is the mitigation OWASP gives in LLM04:2026.
OWASP LLM04:2026When a coding model invents a package name and an attacker registers it. The definition, the measured rates and the controls that stop it.
Package hallucination is when a code-generating AI model recommends or references a software package that does not exist.
It becomes a supply chain risk when an attacker publishes a package under the invented name on a public repository such as PyPI or npm, so that anyone who installs the suggestion downloads the attacker’s code.
unique hallucinated package names across 576,000 code samples in Python and JavaScript
average share of hallucinated packages from open-source models (at least 5.2% for commercial models), across 16 models
of hallucinated packages were repeated more than once across 10 re-runs of the same prompt
A developer or coding agent asks for code. The model returns an import or an install command for a package that sounds right and was never published.
In the USENIX study, 58% of hallucinated packages appeared more than once across 10 runs of the same prompt. An attacker can find the repeatable names by asking the same questions.
The attacker publishes a package under the hallucinated name on an open-source repository. OWASP calls this slopsquatting.
A developer who trusts the suggestion, or an agent that installs dependencies unattended, pulls the attacker’s code into a build.
| Where the bad name comes from | What the attacker does | |
|---|---|---|
| Package hallucination | A model invents a package that never existed | Registers the invented name |
| Typosquatting | A person mistypes a real package name | Registers the likely misspellings |
| Dependency confusion | A build looks up an internal name on a public registry | Publishes a public package under the internal name |
Confirm that an AI-suggested dependency exists and is the package you intended before it is used. This is the mitigation OWASP gives in LLM04:2026.
OWASP LLM04:2026Lock dependencies to reviewed versions, resolve them through a registry you control, and keep a bill of materials so a new, unreviewed package stands out.
CycloneDXThe study tested retrieval-augmented generation, self-refinement and fine-tuning. Fine-tuning cut one model’s hallucination rate from 16.14% to 2.66%, at the cost of diminished code quality.
Spracklen et al.Straight answers, kept current. Last updated .
Ask us anything →Slopsquatting is the attack that exploits package hallucination. Coding assistants hallucinate plausible but nonexistent package names, and an attacker registers those names in advance so that unverified AI-suggested dependencies resolve to malicious code. OWASP describes it in LLM04:2026 Supply Chain. Its mitigation is to verify that a suggested dependency exists and is the intended package before using it.
In the largest study cited here, Spracklen and colleagues generated 576,000 code samples in Python and JavaScript with 16 models. The average share of hallucinated packages was at least 5.2% for commercial models and 21.7% for open-source models, and the team recorded 205,474 unique hallucinated names. Rates differ by model, so treat these figures as a baseline, not a constant.
No. Typosquatting depends on a person mistyping a real package name. Package hallucination needs no typing error: the model supplies a name that never existed, and the developer copies it correctly. The result is the same, an attacker-controlled package in the build, but checking the spelling of a name does not tell you whether the package was ever real.
Primary sources for the figures and frameworks cited on this page. Last verified .
See how Cranium AI discovers, observes, governs, secures and proves every AI model, agent and vendor in your enterprise.
Cookie Policy · Privacy Policy
Global Privacy Control detected. Opt-out request honored: marketing tags stay off in this browser.