Why do AI coding assistants make up package names?
Nobody has pinned down the precise cause, and the authors of the main study call it an open question. What they measured is how often it happens: in 16 code-generating models and 576,000 code samples, the average share of recommended packages that didn’t exist was at least 5.2% for commercial models and 21.7% for open-source ones, per the paper’s abstract.
The names aren’t typos. Of 76,489 hallucinated Python package names, only 13.4% were within one or two edits of a real package, and 48.6% were six or more edits away. Many repeat: among 500 prompts that had already produced a hallucinated package, 58% of the names showed up more than once across 10 reruns, and 39% never repeated. That makes the failure a security problem, because an attacker can publish a real package under a name a model keeps inventing.
Lower temperature gave the lowest rate. Retrieval and fine-tuning also cut it, but that was tested on two open-source models (DeepSeek and CodeLlama), and fine-tuning lowered code quality. Retrieval doesn’t make a model check its own answers.
The limit is age. The study tested models available in early 2024, with few commercial ones, and says newer models may behave differently.
published