← Back to blog
·The mirago teamGuidesPython

Catch Hallucinated Imports Before You pip install

A practical walkthrough: how to find AI-invented Python imports in seconds with mirago, before they ever reach pip install.

You pasted some AI-generated code, you're about to pip install its dependencies — and one of them was never real. Here's how to catch that in seconds.

1. Install mirago

```bash
pipx install mirago # or: pip install mirago
```

It's a pure-Python CLI, Python 3.10+, on Windows, macOS, and Linux. Full installation guide.

2. Check a file or your whole project

```bash
mirago check app.py # one file
mirago check . # this folder and everything under it
```

When you point it at a folder, mirago walks every .py file and skips noise like .venv, .git, caches, and build.

3. Read the result

A package that doesn't exist is an error:

```text
🚨 1 hallucination in app.py

Line 1: import fastjson_validator
→ Package 'fastjson_validator' does not exist on PyPI
```

If everything's fine, mirago stays quiet with a short summary. If you mistyped a popular package, it suggests the right one — and --fix applies it for you.

4. Make it automatic

The exit code is 1 on problems and 0 when clean, so mirago drops straight into CI. See Adding mirago to CI and the usage reference for every option.

One safety note: if PyPI can't be reached, mirago assumes your packages are fine rather than crying wolf. It would rather miss occasionally than block you on a network blip.