The Last Dependency Crusade: Solving Python Dependency Conflicts with LLMs

Antony Bartlett, Cynthia Liem, Annibale PanichellaarXiv 2025

Abstract

Resolving Python dependency issues remains a tedious and error-prone process, forcing developers to manually trial compatible module versions and interpreter configurations. Existing automated solutions, such as knowledge-graph-based and database-driven methods, face limitations due to the variety of dependency error types, large sets of possible module versions, and conflicts among transitive dependencies. This paper investigates the use of Large Language Models (LLMs) to automatically repair dependency issues in Python programs. We propose PLLM (pronounced "plum"), a novel retrieval-augmented generation (RAG) approach that iteratively infers missing or incorrect dependencies. PLLM builds a test environment where the LLM proposes module combinations, observes execution feedback, and refines its predictions using natural language processing (NLP) to parse error messages. We evaluate PLLM on the Gistable HG2.9K dataset, a curated collection of real-world Python programs. Using this benchmark, we explore multiple PLLM configurations, including six open-source LLMs evaluated both with and without RAG. Our findings show that RAG consistently improves fix rates, with the best performance achieved by Gemma-2 9B when combined with RAG. Compared to two state-of-the-art baselines, PyEGo and ReadPyE, PLLM achieves significantly higher fix rates; +15.97% more than ReadPyE and +21.58% more than PyEGo. Further analysis shows that PLLM is especially effective for projects with numerous dependencies and those using specialized numerical or machine-learning libraries.

Introduction

Anyone who has tried to run an old Python project knows the pain of "dependency hell." Code often rots over time due to missing, incompatible, or conflicting package versions—a phenomenon known as dependency drift. While package managers like pip help, they cannot automatically resolve cases where a script requires a specific, undocumented version of a library to function.

Existing automated solutions typically rely on massive knowledge graphs (like PyEGo or ReadPyE) or brittle regex scripts to parse error logs. However, knowledge graphs require constant updates and struggle with complex transitive dependencies, while regex approaches fail when error log formats change. This research introduces PLLM, an automated tool that uses Large Language Models (LLMs) combined with Retrieval-Augmented Generation (RAG) and an iterative Docker-based feedback loop to dynamically infer and fix broken dependencies.

The PLLM Framework

PLLM operates as a five-stage pipeline designed to mimic the trial-and-error process of a human developer:

  1. Inference: The LLM analyzes the raw Python file to guess required modules and the base Python version.
  2. RAG-Augmented Versioning: To prevent hallucination, PLLM uses RAG to pull real-time metadata from PyPI, filtering for versions compatible with the guessed environment.
  3. Validation: PLLM generates a Dockerfile, installs the dependencies, and attempts to run the script, often testing multiple Python versions in parallel.
  4. Targeted Error Analysis: If execution fails, PLLM uses specific prompts to isolate diagnostic information (e.g., identifying the exact missing module from an ImportError) rather than processing the entire stack trace.
  5. Iterative Refinement: The LLM uses this feedback to refine its package selection, repeating the loop until success or a 10-attempt limit is reached.
The PLLM 5-stage pipeline: (A) Initial Prompting, (B) RAG-based Version Inference, (C) Docker Build/Run, (D) Error Analysis, and (E) Iterative Follow-up.

Experimental Evaluation

The system was evaluated on the Gistable HG2.9K dataset, containing 2,891 complex Python snippets that fail to run out-of-the-box. We tested six open-source models with and without RAG.

Key Results

  • Top Performance: Gemma-2 9B with RAG provided the best balance of success and efficiency, successfully fixing 1,583 projects.
  • Beating Baselines: PLLM significantly outperformed state-of-the-art knowledge graph baselines, achieving +15.97% more fixes than ReadPyE (1,365 fixes) and +21.58% more than PyEGo (1,302 fixes).
  • Complexity Scaling: While traditional tools struggle as dependency counts increase, PLLM maintained a consistent ~53-55% success rate even for projects with 7+ dependencies.
Performance of various LLMs with and without RAG across different dependency counts (1 to 5+). Gemma-2 9B with RAG shows peak performance.

Discussion and Insights

Grounding the model with actual PyPI release data via RAG was critical; without it, LLMs frequently invented non-existent package versions. Furthermore, multi-step prompting that isolates specific error types yielded better results than feeding entire stack traces to the model. While PLLM is slower than static baselines (averaging 151 seconds per fix due to iterative Docker builds), this latency is highly practical for developers seeking to revive legacy code.

Conclusion

PLLM demonstrates that LLMs, when grounded by RAG and execution feedback, can effectively navigate the complexities of Python dependency resolution. Future work will focus on expanding support to system-level dependencies (e.g., apt-get requirements) and exploring hybrid architectures that combine LLM reasoning with the curated facts of static knowledge graphs.

Summary updated

BibTeX
@misc{bartlett2025last,
  author = {Antony Bartlett and Cynthia Liem and Annibale Panichella},
  title = {{The Last Dependency Crusade: Solving Python Dependency Conflicts with LLMs}},
  year = {2025},
  eprint = {2501.16191},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.16191},
}
Figure