NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

LLMs Meet Library Evolution: Evaluating Deprecated API Usage in LLM-Based Code Completion

Chong Wang, Kaifeng Huang, Jian Zhang, Yebo Feng, Lyuye Zhang, Yang Liu, Xin Peng

TL;DR

LLMs are great at writing code, but they are often "stuck in the past" because they were trained on massive amounts of now-outdated source code. This paper quantifies how often popular LLMs suggest deprecated APIs (25% to 38% of the time) and proposes two lightweight fixes—REPLACEAPI and INSERTPROMPT—to steer models toward modern, up-to-date library usage.

What Problem Does This Paper Address?

Software libraries evolve rapidly. Developers frequently deprecate old functions in favor of better, more secure, or more efficient alternatives (e.g., PyTorch replacing torch.lstsq() with torch.linalg.lstsq()). However, LLMs are trained on static snapshots of GitHub repositories that contain years of "stale" code.

When a developer uses an LLM for code completion, the model often suggests these deprecated APIs because it has "memorized" them from its training data. This introduces technical debt, security risks, and potential bugs. While previous research has looked at LLM "hallucinations" (making up APIs that don't exist), this paper is the first to systematically study the "stale knowledge" problem: when an LLM suggests a real, but outdated, API.

Methods

The researchers conducted a multi-perspective study (Model, Prompt, and Library perspectives) using seven prominent LLMs, including CodeGen, DeepSeek-Coder, StarCoder2, CodeLlama, and GPT-3.5.

To evaluate the models, they:

  1. Collected API Mappings: They identified 145 pairs of "Deprecated API $\rightarrow$ Replacement API" across eight popular Python libraries.
  2. Constructed Prompts: They used real-world code snippets, masking the line where the API call occurs to see if the LLM would fill it with the old or new version.
  3. Defined Metrics:
    • API Usage Plausibility (AUP): Did the LLM suggest either the deprecated or the replacement API? (i.e., did it understand the context?)
    • Deprecated Usage Rate (DUR): Of the plausible suggestions, how many were the "stale" version?
  4. Proposed Mitigations: They tested two "lightweight" fixes:
  5. REPLACEAPI: A post-processing step that detects a deprecated API in the output, swaps it for the new one, and asks the LLM to regenerate the arguments.
  6. INSERTPROMPT: A prompt-engineering approach that adds an inline comment (e.g., "# X is deprecated, use Y instead") to guide the model.

Datasets

The study utilized a newly constructed dataset based on:

  • 145 API Mappings: Sourced from the documentation of 8 libraries: Numpy, Pandas, scikit-learn, SciPy, seaborn, TensorFlow, PyTorch, and Transformers.
  • 28,125 Completion Prompts: Generated by searching Sourcegraph for real-world usages of these APIs in open-source repositories. This resulted in 9,022 "outdated" function contexts and 19,103 "up-to-dated" function contexts.

Key Insights and Ideas

  • The Popularity Trap: LLMs don't just "hallucinate"; they follow the statistical distribution of their training data. Because deprecated APIs appear frequently in older (but still public) code, models view them as "correct" patterns.
  • Bigger Isn't Always "Fresher": Larger models like GPT-3.5 and CodeLlama-7b actually showed higher Deprecated Usage Rates (DUR) than some smaller models. This suggests that more powerful models are better at memorizing old patterns, making them more susceptible to suggesting stale code.
  • Context is Contagious: If the surrounding code in a user's prompt uses old patterns or specific variable names associated with old versions, the LLM is significantly more likely to suggest a deprecated API to maintain "consistency" with the (outdated) context.
  • The "Knowledge Gap": The root cause is a lack of "posterior knowledge." The models know how to use the old API, but they don't know that it has since been deprecated.

Key Results

  • High Stale Rate: Across all models, the Deprecated Usage Rate (DUR) ranged from 25% to 38%.
  • Library Variance: Some libraries are harder than others. For example, LLMs suggested deprecated APIs for Transformers and PyTorch much more frequently than for Numpy.
  • Fixing the Problem:
    • REPLACEAPI was highly effective for open-source models, achieving a fix rate exceeding 85%.
  • INSERTPROMPT (prompt engineering) was hit-or-miss; it worked well for instruction-tuned models like GPT-3.5 but failed on models that weren't trained to follow explicit instructions in comments.

Limitations and Future Work

The authors acknowledge several areas for growth:

  • Language Scope: The study focused exclusively on Python. Other languages like Java or C# might exhibit different evolution patterns.
  • Granularity: The study looked at function-level deprecation. It did not account for parameter-level changes (where the function name stays the same but the arguments change).
  • Static Analysis Limits: The tool used for identifying APIs relies on lightweight static analysis, which might miss some edge cases in Python's dynamic environment.
  • Future Direction: The authors suggest that Retrieval-Augmented Generation (RAG)—where the model looks up the latest documentation in real-time—could be a more robust long-term solution than simple prompt engineering.

Summary updated

BibTeX
@inproceedings{wang2025llms,
  author = {Chong Wang and Kaifeng Huang and Jian Zhang and Yebo Feng and Lyuye Zhang and Yang Liu and Xin Peng},
  title = {{LLMs Meet Library Evolution: Evaluating Deprecated API Usage in LLM-Based Code Completion}},
  booktitle = {ICSE},
  year = {2025},
  doi = {10.1109/icse55347.2025.00245},
}
Figure