cs.CLApr 9, 2026

An Empirical Analysis of Static Analysis Methods for Detection and Mitigation of Code Library Hallucinations

Authors: Clarissa Miranda-Pena, Andrew Reeson, Cécile Paris, Josiah Poon, Jonathan K. Kummerfeld

Organizations: The University of Sydney · CSIRO’s Data61

Abstract

Despite extensive research, Large Language Models continue to hallucinate when generating code, particularly when using libraries. On NL-to-code benchmarks that require library use, we find that LLMs generate code that uses non-existent library features in 8.1-40% of responses. One intuitive approach for detection and mitigation of hallucinations is static analysis. In this paper, we analyse the potential of static analysis tools, both in terms of what they can solve and what they cannot. We find that static analysis tools can detect 16-70% of all errors, and 14-85% of library hallucinations, with performance varying by LLM and dataset. Through manual analysis, we identify cases a static method could not plausibly catch, which gives an upper bound on their potential from 48.5% to 77%. Overall, we show that static analysis methods are cheap method for addressing some forms of hallucination, and we quantify how far short of solving the problem they will always be.

Figures & tables

Appendix figures & tables9 assets

Supplementary material from the paper’s appendix.

Appendix

Explore similar work

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

    Aug 23, 2026Alberick Euraste Djire, Iyiola E. Olatunji, Melissa Tessa +3LLM Hallucination MitigationLLM Code Generation

  2. Hallucinations of Large Language Models in Cross-Language Code Translation: Phenomena and Mitigation

    Oct 20, 2026Yali Du, Yunji Zhang, Ming LiCode TranslationHallucination in Language Models

  3. CodeTD: Topology of Attention Detects Hallucinations in Code LLMs

    Sep 7, 2026Daria Voronkova, Ilya Trofimov, Anton Dmitriev +3LLM Hallucination DetectionCode Generation Evaluation