Detection Library
highexperimentalAI/MLCloudT1195.001

Hallucinated Package Reference in LLM-Generated Code

Detects LLM-generated code suggesting installation of a package name that does not exist in the relevant public registry (PyPI, npm) -- the 'slopsquatting' risk, where attackers pre-register names LLMs are statistically likely to hallucinate and load them with malicious code.

Updated Oct 29, 2026 · Detection Engineering Team

llmslopsquattingsupply-chaincode-generationowasp-llm03

Problem Statement

Research across 16 popular code-generation models found none were free of package hallucination, with some open-weight models hallucinating over 20% of suggested package names; because the hallucination is statistically repeatable across prompts, attackers can pre-register the exact names models are likely to suggest and wait for an agent or developer to install them.

Sample Logs

{"event_type":"llm_response","timestamp":"2026-10-29T11:20:03Z","user":"dev-agent-ci","model":"codellama-13b-local","request_id":"req-91c7","response_body":"You'll need to install the helper library first:\n\npip install fastapi-auth-helpers\n\nThen import it as..."}

Required Fields

response_body
user
model
request_id
timestamp

False Positives

  • ·Legitimate internal/private packages not published to the public index being checked
  • ·Newly published packages not yet present in a stale local registry-index snapshot

Tuning Guidance

Refresh the local registry-index snapshot at least daily to avoid false positives on legitimate new packages, and only alert (rather than block) on first occurrence of a non-resolving name -- if an automated agent is about to execute `pip install` against that unresolved name, escalate to a blocking control instead, since an attacker-registered lookalike could now exist.