Abstract
Large Language Models (LLMs) have revolutionized automated code generation but are hampered by a "knowledge cutoff," leading them to suggest deprecated or insecure APIs that were prevalent during their training. This paper introduces APILOT, a navigation system designed to mitigate these risks. APILOT maintains a real-time database of outdated APIs via GitHub commit analysis and employs an iterative, version-aware prompting strategy. Our evaluation shows that APILOT reduces outdated API recommendations by an average of 89.42% and improves code usability by 27.54% by steering models toward modern, functional alternatives.
Introduction
The rapid evolution of software libraries creates a significant challenge for LLMs like GPT-4 or Llama-3. Because these models are trained on static datasets, their internal knowledge of "best practices" quickly becomes obsolete. This leads to the recommendation of deprecated APIs, patched APIs with known vulnerabilities (CVEs), and usage-modified APIs where security fixes have changed function signatures. Existing mitigation strategies, such as simple prompt engineering, often fail to capture the structural nuances of code or are too costly to update frequently.
Methodology: The APILOT Framework
APILOT operates as an intermediary layer between the user and the LLM, following a three-phase process to ensure code security and validity.
- Outdated API Collection: To bypass the latency of official documentation, APILOT performs differential analysis on GitHub commits for popular packages. This allows the system to identify API removals, deprecations, and security-related modifications in real-time.
- AST-Based Sanitization: Rather than relying on error-prone keyword matching, APILOT converts generated code into an Abstract Syntax Tree (AST). This structural analysis ensures that only actual function calls are flagged, avoiding false positives in comments or strings.
- Iterative Augmented Generation: When an outdated API is detected, APILOT appends it to a "ban list" and re-prompts the LLM with specific instructions to avoid those functions. This process iterates until the code is sanitized or a maximum iteration count is reached.
Evaluation and Results
The researchers evaluated APILOT against a benchmark of 221 deprecated, 100 CVE-patched, and 402 usage-modified APIs across 15 major Python packages.
Key Findings
- Risk Mitigation: APILOT achieved an average reduction of 89.42% in outdated API recommendations. For models like Llama-3, the reduction reached 100% in several categories.
- Usability Improvements: By steering LLMs away from removed or modified APIs, the "compilability" and overall usability of the code increased by 27.54%. This suggests that security-aware generation also yields more functional code.
- The Alternative Pitfall: A critical observation was that LLMs often attempt to substitute one banned outdated API with another. APILOT’s iterative approach is essential to "exhaust" these insecure options until the model identifies a modern solution.
- Performance Trade-off: The safety benefits come with a latency cost; iterative re-prompting results in an execution time approximately 1.97x longer than standard requests.
Conclusion
APILOT demonstrates that structural analysis combined with real-time API tracking can effectively bridge the gap created by LLM knowledge cutoffs. While currently focused on Python and GitHub-hosted projects, the framework provides a scalable blueprint for secure code generation. Future work will focus on expanding language support and reducing the latency of the iterative prompting cycle to facilitate integration into real-time development environments.
Summary updated