mlsanityData to 7 Oct 2026

Evaluating Inference-Time Defenses Against Package Hallucination in LLM-Generated Code

arXiv 2608.22652 ↗First posted 23 Aug 2026cs.SE cs.AIcited by 0

Not on the map. Why?

Abstract (arXiv)

LLMs are increasingly used for code generation, yet they frequently hallucinate non-existent software packages, creating exploitable entry points into the software supply chain. We make four contributions to this problem. First, we show that prior evaluation methodologies systematically inflate hallucination rates by misclassifying standard-library modules as hallucinations in some languages. For Python, the overestimation reaches 9.4 percentage points. Second, we evaluate seven inference-time defenses for mitigating package hallucinations, including five guided decoding strategies (Greedy, Contrastive, DoLa, Nudging, and Active Layer-Contrastive Decoding), an iterative self-refinement approach (Self-Refine), and a Retrieval-Augmented Generation (RAG)-based defense.. Across eight models spanning five families and four programming languages (Python, JavaScript, Ruby, Rust), RAG reduces the package hallucination rate (PHR) in 18 of 32 model--language configurations. Third, we introduce Package Utility (PU) to assess whether defenses preserve valid and task-relevant recommendations. Among strategies evaluated, Greedy decoding provides the strongest average mitigation--utility trade-off. Fourth, we stress-test all strategies under adversarial prompts seeded with fabricated package names and find that PHR surges by up to 45 percentage points relative to standard prompts, with Ruby consistently the most vulnerable language (80.9--95.2%). Under adversarial conditions, RAG and Self-Refine outperform all decoding-only strategies, indicating that robust defense requires either external grounding or iterative self-verification when prompts are actively hostile. Our results recast package hallucination as both a measurement problem and a decoding-time control problem, and they demonstrate that the choice of defense must be matched to the threat model and recommendation utility.

Key facts. No citing papers in the map yet (data through 7 Oct 2026). Builds on 21 of its 38 references that are in the map. First posted on arXiv 23 Aug 2026.

Builds on

21 of 38 references.

References · 21

  1. 2020Retrieval-Augmented Generation for Knowledge-Intensive NLP Taskscited by 9,160
  2. 2023Self-Refine: Iterative Refinement with Self-Feedbackcited by 3,317
  3. 2022Contrastive Decoding: Open-ended Text Generation as Optimizationcited by 598
  4. 2023DoLa: Decoding by Contrasting Layers Improves Factuality in Large Language Modelscited by 367
  5. 2024Semantic Entropy Probes: Robust and Cheap Hallucination Detection in LLMscited by 246
  6. 2023Grammar-Constrained Decoding for Structured NLP Tasks without Finetuningcited by 186
  7. 2024A Thorough Examination of Decoding Methods in the Era of LLMscited by 112
  8. 2024Beyond Functional Correctness: Exploring Hallucinations in LLM-Generated Codecited by 106
  9. 2023Is ChatGPT the Ultimate Programming Assistant -- How far is it?cited by 72
  10. 2024We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMscited by 61
  11. 2024Bugs in Large Language Models Generated Code: An Empirical Studycited by 59
  12. 2025Hallucination by Code Generation LLMs: Taxonomy, Benchmarks, Mitigation, and Challengescited by 9
9 more
  1. 2025Memorization or Interpolation ? Detecting LLM Memorization through Input Perturbation Analysiscited by 5
  2. 2025TreeCoder: Systematic Exploration and Optimisation of Decoding and Constraints for LLM Code Generationcited by 5
  3. 2026Correctness isnt Efficiency: Runtime Memory Divergence in LLM-Generated Codecited by 4
  4. 2026Learned or Memorized ? Quantifying Memorization Advantage in Code LLMscited by 4
  5. 2025Adversarial Attacks and Defenses on Graph-aware Large Language Models (LLMs)cited by 3
  6. 2026How Secure is Secure Code Generation? Adversarial Prompts Put LLM Defenses to the Testcited by 3
  7. 2023Journey to the Center of Software Supply Chain Attackscited by 2
  8. 2025ConfuGuard: Using Metadata to Detect Active and Stealthy Package Confusion Attacks Accurately and at Scalecited by 2
  9. 2021Achieving differential privacy for k-nearest neighbors based outlier detection by data partitioningcited by 1

Built on by

Not cited yet.

Similar, not cited

Close in wording, no citation either way

  1. 2026LLM Ghostbusters: Surgical Package Hallucination Suppression via Adaptive Unlearning
  2. 2024LLM Hallucinations in Practical Code Generation: Phenomena, Mechanism, and Mitigation
  3. 2024De-Hallucinator: Mitigating LLM Hallucinations in Code Generation Tasks via Iterative Grounding
  4. 2026Harmless Yet Harmful: Neutral Prompting Attacks for Stealthy Hallucination Steering in Agent Skills
  5. 2026Bayesian-Calibrated Detection of Hallucinated Package Imports in AI-Assisted Code ↗
  6. 2026Execution-Anchored Hallucination Calibration Reranking for Verilog Code Generation ↗
  7. 2025Towards Mitigating API Hallucination in Code Generated by LLMs with Hierarchical Dependency Aware
  8. 2026Refusing the Impossible: A Taxonomy and Benchmark for Code Hallucination in Large Language Models ↗