Sub topic 10
What Model and Tool Builders Can Do
This chapter assumes you know how package managers resolve names from public registries, why a model can suggest a package that does not exist, and how slopsquatting uses those names. It looks at the other side of the problem: what the people who build models and coding tools can change. Your own checks still come first. These measures only reduce how often a bad name reaches you.
Why the model side matters
A model invents a package name because it predicts text that looks plausible. It does not look the name up in a registry. Fixing this at the source cuts the number of bad names before any developer or agent sees them. Builders have two levers: how the model is trained and prompted, and how the tool around the model behaves.
Model-side mitigations
These changes act on the model itself.
- Grounding with retrieval. The tool fetches real package data, such as a registry index or the project's own manifest, and gives it to the model as context. The model then picks from names that exist instead of recalling them from memory.
- Fine-tuning for uncertainty. Training examples can reward answers like "I am not sure this package exists" over a confident invented name.
- Preference for standard-library solutions. When the standard library already solves the task, the model can be tuned to use it, which avoids a dependency entirely.
- Evaluation. Builders can measure the rate of non-existent package suggestions across many prompts and languages, and track it between model versions.
None of these removes hallucination. Grounding helps most, but it only works when the retrieved data is current and the model actually uses it.
Tool-side mitigations
The coding assistant or agent sits between the model and your machine. That position lets it add a check the model cannot perform on its own.
- The tool extracts every package name from a suggestion.
- It queries the registry for each name.
- It flags names that return a 404, were created very recently, or have almost no release history.
- It asks the user before running any install command, or blocks the command.
The check in the earlier chapter on verification is the same idea as a script you run by hand. A tool can run it automatically on every suggestion.
Safe defaults for agents
Agents that run commands need stricter defaults than chat assistants, because no human reads each line before it runs.
- Require approval for any command that adds a new dependency.
- Install with lockfiles and
--ignore-scriptsunless the user opts out. - Run installs in a sandbox with no access to credentials, SSH keys, or cloud tokens.
- Keep an allowlist of approved packages for the project and refuse names outside it.
Limits of what builders can do
Builders reduce the rate of bad suggestions, but they cannot reach zero. Models differ in how often they hallucinate names, and the same prompt can give different names on different runs. Names that repeat across runs are the most dangerous, because an attacker can predict and register them. Tools also see only the registries they query, so a private registry or a mirror can disagree with the public one.
For this reason, treat builder-side measures as a first filter. The preventive controls from the previous chapters, such as lockfiles, hash pinning, and restricted install scripts, stay in place.
Comparing the levers
| Measure | Where it acts | Main strength | Main weakness |
|---|---|---|---|
| Retrieval grounding | Model input | Names come from real data | Stale or incomplete data |
| Uncertainty training | Model weights | Fewer confident wrong names | Does not remove errors |
| Registry check in the tool | Tool layer | Catches 404 names | Passes once a name is registered |
| Age and history check | Tool layer | Flags new, sparse packages | Can flag legitimate new projects |
| Approval and sandboxing | Execution | Limits damage | Adds friction for the user |
Exercise
A coding agent checks that every suggested package exists on PyPI before it installs it. Why is this check not enough against slopsquatting, and what should the agent add?
Show answer
Slopsquatting works because an attacker registers the hallucinated name, so the name exists and the check passes. The agent should also check the package's age, release count, and source, compare it to an allowlist, require user approval for new dependencies, and install with hash-pinned lockfiles and restricted install scripts in a sandbox.