Loading lesson…
AI models confidently call libraries that do not exist. Learn the patterns of hallucinated imports, the verification habits that catch them, and the supply-chain attack this opens up.
Ask Claude or GPT for a function that fetches and parses RSS feeds in Python and you might get an import for `feedfetcher` or `pyfeed-parser`. They sound plausible. They do not exist. The model interpolated between real package names it has seen and produced a hybrid that compiles in its head but fails at `pip install`.
| Pattern | Example | Reality |
|---|---|---|
| Plausible compound | `import jwt_decoder` | Real package is `PyJWT`, you `import jwt` |
| Wrong submodule | `from pandas.io.json import read_json` | Moved to `pandas.read_json` years ago |
| Renamed package | `import sklearn.cross_validation` | Renamed to `sklearn.model_selection` in 2018 |
| Invented method | `requests.get_json(url)` | Real call is `requests.get(url).json()` |
| Phantom version flag | `openai.ChatCompletion.create()` | Removed in OpenAI Python SDK v1.0 |
# Before trusting AI-generated imports, run them in isolation mkdir /tmp/smoke && cd /tmp/smoke python -m venv .venv && source .venv/bin/activate # Try to install only the imports the AI suggested pip install feedfetcher pyfeed-parser # ERROR: Could not find a version that satisfies the requirement feedfetcher # Now you know — and you found out in 10 seconds, not in a PR review.A throwaway venv is the cheapest hallucination detector that exists.Claude Code, Cursor Agent, and Codex CLI can all run `pip install` and report back. Use that. If the agent ran the install and tests, the import is real. If it just wrote code, the import is unverified. This is the fastest reliability lift you can get from an agent loop.
Bad prompt: "Write code to parse RSS feeds." Better prompt: "Write code to parse RSS feeds. Use feedparser, version 6.x. Run pip install and a smoke test before showing me the code." The better prompt forces ground truth checks the bad one skips.A 20-second prompt edit eliminates an entire class of bug.The model has seen a million imports and remembered ninety percent of them perfectly.
— A frustrated AI engineer
The big idea: imports are the surface where the model's confidence meets the registry's reality. Verify package names, pin versions, and let agents run installs. The thirty seconds you spend confirming an import is the cheapest debugging you will ever do.
8 questions · take it digitally for instant feedback at tendril.neural-forge.io/learn/quiz/end-coding-debug-hallucinated-imports-creators
What is the main idea of "Hallucinated Imports — When the AI Invents a Library"?
Which concept is most central to "Hallucinated Imports — When the AI Invents a Library"?
Which use of AI fits this topic best?
What should a careful learner remember about "Slopsquatting is real"?
You want to use AI after this lesson. What is the safest next step?
How should AI output about hallucination be treated?
Name one way to verify an AI answer about hallucination.
Which action would help you apply "Hallucinated Imports — When the AI Invents a Library" responsibly?