arXiv:2608.23897cs.CLAug 2026

Manuscript Offprint

arXiv:2608.23897

Names Can Hurt: Spotting Slopsquatting Risks Caused by Package Name Hallucinations in Local Coding LLMs

Akash Raj, Sargam Sahu

Abstract

When a code generating language model fabricates a Python package name, an adversary who has pre-registered that name on PyPI can convert that hallucination into a supply chain compromise. This event has been termed as 'slopsquatting'.

We propose a two layer detector to counter this issue. The first layer performs a deterministic PyPI existence check. The second is a Random Forest classifier trained on ten features derived from the package name and its PyPI metadata. An import name reconciler bridges the two, resolving cases such as import cv2 versus pip install opencv-python without a security bypass. The detector is embedded in a LangGraph state machine that retries at escalating temperatures and, on repeated failure, routes to a stronger fallback model.

Across 300 curated prompts, the pipeline produces hallucination free code on 76% of runs. The primary exhausts its retry budget on 28.7%; intra model retries recover roughly a quarter of those, and cross model fallback recovers a further 16.5% of the remainder.

Four findings have been observed. First, half of the flagged hallucinations are packages already registered on PyPI, as low quality lookalikes of well known projects, caught by the classifier rather than the deterministic layer (e.g., pil, faiss, tabula, haystack). Second, hallucination rate scales almost linearly with prompt adversariality, from 0 to 10% on routine coding to 40 to 73% on slopsquat baits. Third, the weaker primary refused 6 of 10 direct baits unaided, suggesting recent instruction tuning provides a baseline defense. Fourth, when primary and fallback share a model family, approximately 84% of primary failures recur on the fallback, motivating cross family pairing.

A user study (n = 24) reports mean satisfaction 4.4 out of 5 and 21 of 24 stated adoption intent. The second layer classifier is interchangeable: Section 6.10 shows a hand written two feature rule matches the ML version on the current features.

The paper releases the code, the prompts, and the classifiers for each LLM with the complete run log.

1. Introduction

A command such as pip install pdfgenius may simply return a 404, in which case nothing harmful occurs. The same is true of pip install cloudmindai. But if an attacker has already claimed the name on PyPI, an inexpensive and to our knowledge, weakly policed action, then a developer who trusts a coding assistant may instead install attacker controlled software. Spracklen et al. (2024) termed this attack pattern slopsquatting and showed that frontier LLMs hallucinate often enough to make the attack economically plausible.

Subsequent work has focused largely on frontier proprietary models. We instead study a different part of the model landscape: small, open-weight, locally runnable LLMs in the 7B to 70B range. This population matters for three reasons.

First, these are the models that many developers actually run outside large companies. Second, they tend to hallucinate more often than frontier systems. Third, local deployment removes the convenient fallback of asking a stronger hosted model to verify the recommendation, so local defenses must themselves operate locally.

This paper does five things.

  1. We construct a two-layer detector consisting of a deterministic PyPI check and a per-LLM Random Forest, trained across seven LLMs ('gpt-5', 'gpt-oss-120b', 'llama-3.1-8b', 'llama-3.3-70b', 'llama-4-scout', 'qwen3-27b', and 'qwen3-32b'). The agent evaluation uses two Groq-hosted models that fit into our free-tier budget. The primary model is 'llama-3.1-8b'. The fallback model is 'llama-3.3-70b'.

  2. We add an import-name reconciler for the common Python situation where the import name does not match the install name, such as cv2 versus opencv-python or PIL versus Pillow . The reconciler is intentionally narrow. It is triggered when PyPI returns a 404 for the extracted name. A broader rule could let attackers bypass the classifier by registering a squat under the alias. Section 4.4 explains this security argument in detail.

  3. We embed the detector in a LangGraph agent. The agent retries generations while raising the temperature and sends repeated failures to a fallback. Every attempt is saved to a JSONL log.

  4. We evaluate the system with 300 prompts that cover intermediate, difficult and adversarial settings. Section 6 shows the results.

  5. We also ran a controlled user acceptance study, on the standalone classifier UI using an evaluation protocol. The study design tasks and procedures but the participants were Sargam's CS undergraduate peers. Therefore a small amount of desirability bias might still be present.

All artifacts are released.