Homeglossary

Package Hallucination

Package hallucination is an AI coding error that invents a software package or dependency, then presents it as a real installable library. It happens when a model predicts a plausible name from patterns rather than checking an official package registry. A nonexistent name can cause a simple build failure, but it can become a software supply chain risk if an attacker later registers that name.

Build with AI safely by verifying every dependency.

What Is Package Hallucination?

Package hallucination is an AI coding error where a tool invents a software package and presents it as a real dependency. For example, it may suggest npm install data-cleaner-pro even though that name is absent from npm, PyPI, or crates.io.

Why AI Coding Tools Invent Package Names

AI models predict likely text from learned patterns. They do not necessarily check a live package registry. Familiar naming styles, old training data, and vague requests can therefore produce convincing but nonexistent dependencies.

Package Hallucination vs. Typosquatting vs. Slopsquatting

These issues can lead to an unsafe install, but their starting points differ.

IssueSource of nameMain risk
Package hallucinationAI invents a nameBroken build or unsafe future install
TyposquattingA misspelling of a real packageDeveloper installs an attacker-controlled lookalike
SlopsquattingAn attacker registers an AI-invented nameMalicious code is installed when AI output is copied

How to Verify an AI-Suggested Package

Check every new dependency before installing it.

  1. Search the official registry for the exact name.
  2. Confirm the publisher, source repository, and documentation.
  3. Review release activity and reported issues.
  4. Pin an approved version and commit the lockfile.
  5. Scan and review the dependency before merging.

Security and Delivery Risks

A missing package is not always harmless. Treat dependency verification as software supply chain hygiene.

  • Build failures and lost debugging time.
  • Malicious install scripts that access environment credentials.
  • Unreviewed transitive dependencies added downstream.
  • False confidence when generated code appears complete.

Package Hallucination in AI-Assisted Development

AI-assisted development works best when generated dependencies receive the same review as human-written code. Learn more about AI hallucinations, package hallucination, and an AI package supply chain breach. Build with AI safely by verifying every dependency.

Frequently Asked Questions

Your Questions, Answered

This will automatically populate, don't change

Don't change this element unless you know what you are doing

What is a package hallucination in AI coding?

It is when an AI coding tool recommends a package name that does not exist in the relevant software registry.

Why do AI coding assistants invent software packages?

They predict plausible names from patterns in their training data and prompt context, rather than always checking a live registry.

What is the difference between package hallucination and slopsquatting?

A package hallucination is the AI error. Slopsquatting is an attack in which someone registers the invented name to catch future installs.

How can developers verify an AI-suggested package?

Search the official registry, check the maintainer and source repository, review activity, pin the version, and scan it before use.

Can a nonexistent package name become a security risk?

Yes. An attacker can register the name later, turning copied AI-generated install commands into a potential malicious dependency installation.

Start Building
on Emergent today
Start Building