AI Hallucinated Packages: Check Names Before You Install
Short answer: AI hallucinated packages are a real supply-chain risk, because AI coding assistants sometimes recommend packages that do not exist. If nobody owns that name, an attacker can register it and wait for someone to run the install command. This is often called slopsquatting. Before you install anything an assistant suggested, paste the code or the install commands into the Package Checker to list every package name, spot typos and look-alikes offline, and (only if you agree) check whether the names exist on npm and PyPI.
What slopsquatting is
Typosquatting relies on you making a typo: reqeusts instead of requests. Slopsquatting relies on the model making one up. An assistant writes pip install fastjson-utils or import super-validator with total confidence, and no such package exists. Registering that exact name takes a couple of minutes, after which the next person who copies the suggestion installs the attacker's code. And install scripts can run on installation.
How common is it?
A 2024 academic study, "We Have a Package for You!" (Spracklen et al.), generated 576,000 code samples with 16 popular code-generating models in two languages. It found 205,474 unique hallucinated package names, with an average share of hallucinated packages of at least 5.2% for commercial models and 21.7% for open-source models. Numbers like these depend on the models, the prompts and the date, so read them as "this really happens", not as a rate for the assistant you use today.
Three layers of checking
The Package Checker works in three steps, and the first two never leave your browser.
Step 1: find the names (offline)
It reads JavaScript and TypeScript (import … from, export … from, require(), dynamic import()), Python (import a.b, from a import, pip install lines), install commands (npm install, npm i, yarn add, pnpm add, bun add, pip install, python -m pip, uv, poetry add) and manifests (package.json, requirements.txt). Relative paths, Node built-ins, the Python standard library, Git sources and URLs are skipped. Where the import name differs from the package name, it tells you: cv2 is installed as opencv-python, PIL as Pillow, yaml as PyYAML.
Step 2: look-alike check (offline)
Each name is compared with a built-in sample of about 300 widely used npm and PyPI names. It is flagged when it is one or two characters away from a popular name, when only a hyphen, underscore or dot differs, or when a js or py suffix is added or dropped. The sample is small and not authoritative. Being in it says nothing about trust, and a name that is not near a popular one can still be a typosquat.
Step 3: registry lookup (only when you ask)
If you tick the consent box and press the button, the tool sends one request per name (at most 60 names per run, 5 at a time) to registry.npmjs.org or pypi.org. For each package it shows whether it exists, the first publication date, the latest version, whether the latest version is deprecated, the number of maintainers (npm only), the repository link and install scripts (npm). It adds a warning when the package was first published less than 90 days ago, which is a useful signal for a name an assistant has only just made popular.
Exists is not the same as safe
A package that exists can still be malicious, abandoned or a look-alike. Treat the lookup as a first filter. Then:
- open the repository link and check that it is real and matches the package;
- look at the publisher, the publication date and the download history;
- read the install scripts before you run them;
- pin versions and commit a lockfile so a later "update" cannot swap code under you;
- for your own review, compare dependency files before and after with the Dependency Change Reviewer, as described in reviewing dependency changes before a merge.
When the problem is an API, not a package
The same kind of confident invention happens with API calls: an assistant uses an endpoint, a parameter or a field your API does not have. The API Hallucination Check compares code against your OpenAPI document and points to the evidence for every finding. Other risks in generated code are covered in AI-generated code security. Hidden characters and risky commands are different problems again (see How to detect hidden Unicode characters and Is this shell command safe?).
How to check AI hallucinated packages with the Package Checker
- Open the Package Checker.
- Paste the code, the install commands, a
package.jsonor arequirements.txt(up to 1,000,000 characters, up to 2,000 names). - Read the offline results: every package found and any look-alike flags.
- If you want existence data, tick the consent box and run the lookup. A request that takes longer than 15 seconds is stopped for that package.
- Investigate every name that is missing, very new, deprecated or has install scripts.
Limits to know
- Private and internal packages, workspace packages and path aliases show as "not found".
- Names built at run time or loaded from files are not seen.
- Python import names not in the built-in table are checked as written, and the real package name may differ.
- Registry data is limited: PyPI's JSON API does not list maintainers, and very large records are read only in part. The tool says when something was not read.
- Trust cannot be decided by a tool. Check the publisher and the code.
Frequently asked questions
What is slopsquatting? Registering a package name that an AI model tends to invent, so developers who follow the suggestion install malicious code.
How do I check if an npm or PyPI package exists? Paste the install command into the Package Checker and run the optional registry lookup.
Is a package that exists safe to install? Not automatically. Check its age, publisher, repository and install scripts.
Does the tool send my code anywhere? Not unless you tick the consent box. Then it sends package names only, to npm or PyPI.
What is the difference between typosquatting and slopsquatting? Typosquatting waits for human typos. Slopsquatting waits for model inventions.
Related tools and guides
- Dependency Change Reviewer (see Review dependency changes before you merge)
- API Hallucination Check
- AI Output Sanity Check
- LLM JSON Guard (see Fix invalid JSON from ChatGPT and other LLMs)
- AI Code Risk Linter
- SPDX license identifiers for checking the licence of a package you do adopt
- AGENTS.md and MCP config security
- Secret Scanner (see Leaked API key: what to do)
- Remove EXIF and GPS data from photos for another quiet way files leak information