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.
15 questions · take it digitally for instant feedback at tendril.neural-forge.io/learn/quiz/end-coding-debug-hallucinated-imports-creators
What is the core idea behind "Hallucinated Imports — When the AI Invents a Library"?
Which term best describes a foundational idea in "Hallucinated Imports — When the AI Invents a Library"?
A learner studying Hallucinated Imports — When the AI Invents a Library would need to understand which concept?
Which of these is directly relevant to Hallucinated Imports — When the AI Invents a Library?
Which of the following is a key point about Hallucinated Imports — When the AI Invents a Library?
Which of these does NOT belong in a discussion of Hallucinated Imports — When the AI Invents a Library?
Which statement is accurate regarding Hallucinated Imports — When the AI Invents a Library?
Which of these does NOT belong in a discussion of Hallucinated Imports — When the AI Invents a Library?
What is the key insight about "Slopsquatting is real" in the context of Hallucinated Imports — When the AI Invents a Library?
What is the key insight about "Ask the AI to cite" in the context of Hallucinated Imports — When the AI Invents a Library?
Which statement accurately describes an aspect of Hallucinated Imports — When the AI Invents a Library?
What does working with Hallucinated Imports — When the AI Invents a Library typically involve?
Which of the following is true about Hallucinated Imports — When the AI Invents a Library?
Which best describes the scope of "Hallucinated Imports — When the AI Invents a Library"?
Which section heading best belongs in a lesson about Hallucinated Imports — When the AI Invents a Library?