Beyond Strict Rules: Assessing the Effectiveness of Large Language Models for Code Smell Detection

Saymon da Silva Souza, Amanda Santana, Eduardo Figueiredo, Igor Muzetti, João Eduardo Montandon, Lionel C. BriandarXiv 2026 · DOI

TL;DR

This paper investigates how well Large Language Models (LLMs) can detect code smells, common indicators of software quality issues. The study finds that LLMs excel at identifying structurally simple smells but struggle with more subjective ones. Interestingly, a combined strategy of LLMs and traditional static analysis tools often outperforms individual methods, offering a promising avenue for more robust code smell detection.

What Problem Does This Paper Address?

Software maintainability is crucial, and code smells are known to hinder it, leading to increased development costs and potential defects. Traditionally, code smells are detected using static analysis tools with rigid rules. While effective for some smells, these tools can be imprecise and require human interpretation. Large Language Models (LLMs) have shown remarkable capabilities in various software engineering tasks, but their application to code smell detection, especially in real-world, complex codebases, remains underexplored. This paper aims to bridge this gap by empirically evaluating the effectiveness of several LLMs in detecting a range of code smells and comparing them against traditional tools.

Methods

The authors employed a multi-stage approach to evaluate LLMs for code smell detection.

  1. LLM Selection: Four prominent LLMs were chosen: DeepSeek-R1, GPT-5 mini, Llama-3.3, and Qwen2.5-Coder.
  2. Dataset Expansion: The study built upon an existing dataset of 30 open-source Java projects. This dataset was expanded to include LLM and human evaluations.
  3. Ground Truth Creation: A crucial step involved creating a ground truth by having 76 undergraduate computer science students manually inspect 268 code-smell candidates. Participants rated smells on a five-point scale, with an average score above 3 indicating a smell.
  4. LLM Prompting: A structured Chain-of-Thought (CoT) prompting strategy was used. This involved formulating specific questions for each code smell, derived from established definitions and detection strategies, to guide the LLMs' reasoning process.
  5. Evaluation: The effectiveness of LLMs and static analysis tools was measured using Precision, Recall, and F1-Score.
  6. Combined Strategy: A voting-based mechanism was developed to combine the outputs of LLMs and static analysis tools, aiming to improve overall detection accuracy and coverage.

Datasets

The study utilized an extended dataset based on 30 top-starred open-source Java projects mined from GitHub. This dataset initially contained 3,459 instances of 9 code smells. The authors expanded this dataset by incorporating LLM-generated code-smell information and human evaluations, resulting in a ground truth derived from 76 developers manually inspecting 268 code-smell candidates. The replication package for this study, containing the dataset and scripts, is made available.

Key Insights and Ideas

  • LLMs Excel at Structural Smells: LLMs demonstrate strong performance for code smells with clear, quantifiable structural patterns (e.g., Large Class, Long Method). This suggests their ability to grasp size and complexity metrics effectively.
  • Subjectivity is a Hurdle: More subjective or context-dependent smells (e.g., Feature Envy, Refused Bequest) pose significant challenges for LLMs. These smells often require a deeper understanding of code intent and relationships, which current LLMs struggle to fully capture.
  • Combined Strategies Offer Synergy: A voting-based strategy combining LLMs and static analysis tools often outperforms individual methods, particularly for structurally simpler smells. This highlights the complementary nature of these approaches.
  • Model Selection Matters: The effectiveness of LLMs varies not only by code smell but also by the specific LLM used. Some models, like Llama-3.3 and DeepSeek-R1, generally performed better, underscoring the importance of model choice.
  • Context is Key for Complex Smells: For smells like Long Parameter List or Refused Bequest, specialized tools or carefully selected individual LLMs can still be more effective than a combined strategy, suggesting that deep, holistic reasoning is sometimes better achieved by tailored approaches.

Key Results

  • Structurally Simple Smells: LLMs achieved high Precision, Recall, and F1-Scores for smells like Data Class, Large Class, and Long Method. For instance, Llama-3.3 achieved a Precision of 0.95 and an F1-score of 0.88 for Large Class.
  • Subjective Smells: For smells like Refused Bequest, all models struggled, with F1-scores generally below 0.40. Long Parameter List also presented challenges, with Llama-3.3 showing a Precision of 0.88 but a lower Recall of 0.54.
  • LLMs vs. Tools: LLMs outperformed static analysis tools for Data Class, Feature Envy, and Intensive Coupling. However, for more context-dependent smells like Dispersed Coupling and Long Parameter List, static tools like JSPIRIT and Organic showed an advantage.
  • Combined Strategy Performance: The combined strategy achieved the best F1-scores for 5 out of 9 code smells, particularly for those with localized structures. It consistently improved Recall, making it a robust choice for broader coverage. For example, the combined strategy achieved an F1-score of 0.93 for Large Class.

Limitations and Future Work

Limitations: * Data Contamination: The knowledge cutoff dates of LLMs raise concerns about potential data contamination, as the training data might have included the code analyzed in the study. The authors mitigated this by using fixed snapshots of projects and ensuring consistency across models. * Participant Profile: The study participants were primarily undergraduate students with limited professional experience, which might affect the generalizability of the human evaluation aspect. * Prompt Sensitivity: LLM performance can be sensitive to prompt design and configurations, making it challenging to attribute outcomes solely to model capabilities. The authors standardized prompts and configurations to mitigate this. * Language Specificity: The study focused on Java projects, limiting direct generalization to other programming languages.

Future Work: * Expand LLM Set: Incorporate more LLMs, including newer models and those with advanced prompting techniques like few-shot learning. * Increase Smell Coverage: Expand the dataset to include a wider range of code smells. * Cross-Domain and Cross-Language Evaluation: Adapt prompts and methodologies to evaluate LLMs on different programming languages and software domains. * Investigate Hybrid Models: Explore more sophisticated hybrid models that combine code analysis with design documentation or leverage chain-of-thought explanations for better detection of subjective smells. * Explainability: Focus on the explanatory capabilities of LLMs to help developers understand why a smell is present and how to prevent it.

Summary updated

BibTeX
@misc{souza2026beyond,
  author = {Saymon da Silva Souza and Amanda Santana and Eduardo Figueiredo and Igor Muzetti and João Eduardo Montandon and Lionel C. Briand},
  title = {{Beyond Strict Rules: Assessing the Effectiveness of Large Language Models for Code Smell Detection}},
  year = {2026},
  eprint = {2601.09873},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2601.09873},
}
Figure