SlopScore for Code

Patterns / Hallucinated imports (and slopsquatting)

Hallucinated imports (and slopsquatting)

Code models predict plausible package names. Sometimes the package exists but isn't in your manifest; sometimes it doesn't exist at all. Research on package hallucination has found models invent non-existent package names at a meaningful rate, and many of those names repeat across runs, which makes them easy for attackers to register. The attack has a name now: slopsquatting.

What it looks like

import { formatCurrency } from "money-formatter-pro"  // not in package.json
from fastjsonx import loads  # not in requirements.txt
require("express-validator-helpers")

Why it matters

An undeclared import either breaks at runtime or, worse, works because someone later runs `npm install <name>` to fix the error and pulls in a squatted package.

Before and after

Before
import { retry } from "async-retry-utils";

await retry(() => fetchInvoice(id), { attempts: 3 });
After
import pRetry from "p-retry"; // already in package.json

await pRetry(() => fetchInvoice(id), { retries: 3 });

How to fix it

  1. Check every new import against package.json / requirements / pyproject in CI. SlopScore for Code does this on the PR diff and understands Node built-ins, the Python stdlib, local modules, tsconfig path aliases and common aliases like PIL → pillow.
  2. Never add a dependency just because an error says it's missing. Look it up first: age, downloads, repository, maintainer.
  3. Pin and review lockfile changes in the same PR.

When it's fine

Monorepos with workspace packages and path aliases. Those are read from your package.json files and tsconfig paths, so they don't get flagged.

Catch this automatically. SlopScore for Code checks every pull request for this pattern (rule hallucinated-import) and 11 others. Score a public PR or add the free GitHub Action.

Related