An Empirical Analysis of Static Analysis Methods for Detection and Mitigation of Code Library Hallucinations
Not on the map. Why?
Abstract (arXiv)
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.
Key facts. No citing papers in the map yet (data through 14 Oct 2026). Builds on 27 of its 33 references that are in the map. First posted on arXiv 9 Apr 2026.
Builds on
27 of 33 references.
References · 27
- 2022DS-1000: A Natural and Reliable Benchmark for Data Science Code Generationcited by 452
- 2023Grammar-Constrained Decoding for Structured NLP Tasks without Finetuningcited by 197
- 2023Is Self-Repair a Silver Bullet for Code Generation?cited by 197
- 2024Granite Code Models: A Family of Open Foundation Models for Code Intelligencecited by 117
- 2023Self-Edit: Fault-Aware Code Editor for Code Generationcited by 111
- 2024Guiding LLMs The Right Way: Fast, Non-Invasive Constrained Generationcited by 101
- 2024Reducing hallucination in structured outputs via Retrieval-Augmented Generationcited by 93
- 2022Execution-Based Evaluation for Open-Domain Code Generationcited by 91
- 2024CodeRAG-Bench: Can Retrieval Augment Code Generation?cited by 91
- 2023Refining ChatGPT-Generated Code: Characterizing and Mitigating Code Quality Issuescited by 79
- 2024SynCode: LLM Generation with Grammar Augmentationcited by 69
- 2024We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMscited by 65
15 more
- 2024NExT: Teaching Large Language Models to Reason about Code Executioncited by 63
- 2024Automata-based constraints for language model decodingcited by 51
- 2024Constrained Decoding for Secure Code Generationcited by 37
- 2025HALoGEN: Fantastic LLM Hallucinations and Where to Find Themcited by 34
- 2022FixEval: Execution-based Evaluation of Program Fixes for Programming Problemscited by 17
- 2024De-Hallucinator: Mitigating LLM Hallucinations in Code Generation Tasks via Iterative Groundingcited by 15
- 2025Importing Phantoms: Measuring LLM Package Hallucination Vulnerabilitiescited by 15
- 2023A Static Evaluation of Code Completion by Large Language Modelscited by 14
- 2024Collu-Bench: A Benchmark for Predicting Language Model Hallucinations in Codecited by 13
- 2024FLAP: Flow-Adhering Planning with Constrained Decoding in LLMscited by 11
- 2024Constrained Decoding for Fill-in-the-Middle Code Language Models via Efficient Left and Right Quotienting of Context-Sensitive Grammarscited by 8
- 2025Towards Mitigating API Hallucination in Code Generated by LLMs with Hierarchical Dependency Awarecited by 6
- 2024ChatGPT Incorrectness Detection in Software Reviewscited by 5
- 2024LLM-based Frameworks for API Argument Filling in Task-Oriented Conversational Systemscited by 4
- 2024The Power of Types: Exploring the Impact of Type Checking on Neural Bug Detection in Dynamically Typed Languagescited by 1
Built on by
Not cited yet.