Package Hallucination in 2026: What the Research Shows
How often do AI models invent package names, how is it measured, and what does the 2026 picture look like? A grounded look at package hallucination.
"How often does an AI actually invent a package?" is the question behind every slopsquatting headline. Here's how researchers measure it and how to read the numbers without overreacting.
How hallucination rate is measured
The basic method is simple: prompt a model for lots of coding tasks, extract every package it imports, and check each name against the real registry (PyPI for Python, npm for JavaScript). The hallucination rate is the share of suggested packages that don't exist.
Why the numbers vary so much
Reported rates swing widely — from low single digits to north of twenty percent — and that's expected, because the rate depends on:
- The model. Newer, larger, code-specialised models hallucinate less.
- The prompt. Niche or obscure tasks push models to invent more.
- The language and ecosystem. Bigger ecosystems give models more real names to recall.
- How you count. Unique names vs. every occurrence produce different figures.
Treat any single headline percentage with caution; the trend matters more than the decimal.
What actually matters for you
Even a "low" rate is dangerous when attackers are registering the fakes (see slopsquatting). A 3% hallucination rate across thousands of installs a day is a large attack surface. The defence doesn't depend on the exact rate — it depends on verifying imports before you install them.
A pragmatic stance for 2026
- Assume any AI-suggested dependency is unverified until checked.
- Automate the check in your editor and CI, not just in your head.
- Watch the deeper levels too: fake functions and arguments inside real packages.
mirago automates the first line of defence — run mirago check . and it flags every import that isn't real. See how it works.