A Causal Perspective on Measuring, Explaining and Mitigating Smells in LLM-Generated Code

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Velasco, Alejandro, Rodriguez-Cardenas, Daniel, Khati, Dipin, Palacio, David N., Alif, Luftar Rahman, Poshyvanyk, Denys
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866914259250708480
author Velasco, Alejandro
Rodriguez-Cardenas, Daniel
Khati, Dipin
Palacio, David N.
Alif, Luftar Rahman
Poshyvanyk, Denys
author_facet Velasco, Alejandro
Rodriguez-Cardenas, Daniel
Khati, Dipin
Palacio, David N.
Alif, Luftar Rahman
Poshyvanyk, Denys
contents Recent advances in large language models (LLMs) have accelerated their adoption in software engineering contexts. However, concerns persist about the structural quality of the code they produce. In particular, LLMs often replicate poor coding practices, introducing code smells (i.e., patterns that hinder readability, maintainability, or design integrity). Although prior research has examined the detection or repair of smells, we still lack a clear understanding of how and when these issues emerge in generated code. This paper addresses this gap by systematically measuring, explaining and mitigating smell propensity in LLM-generated code. We build on the Propensity Smelly Score (PSC), a probabilistic metric that estimates the likelihood of generating particular smell types, and establish its robustness as a signal of structural quality. Using PSC as an instrument for causal analysis, we identify how generation strategy, model size, model architecture and prompt formulation shape the structural properties of generated code. Our findings show that prompt design and architectural choices play a decisive role in smell propensity and motivate practical mitigation strategies that reduce its occurrence. A user study further demonstrates that PSC helps developers interpret model behavior and assess code quality, providing evidence that smell propensity signals can support human judgement. Taken together, our work lays the groundwork for integrating quality-aware assessments into the evaluation and deployment of LLMs for code.
format Preprint
id arxiv_https___arxiv_org_abs_2511_15817
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle A Causal Perspective on Measuring, Explaining and Mitigating Smells in LLM-Generated Code
Velasco, Alejandro
Rodriguez-Cardenas, Daniel
Khati, Dipin
Palacio, David N.
Alif, Luftar Rahman
Poshyvanyk, Denys
Software Engineering
Recent advances in large language models (LLMs) have accelerated their adoption in software engineering contexts. However, concerns persist about the structural quality of the code they produce. In particular, LLMs often replicate poor coding practices, introducing code smells (i.e., patterns that hinder readability, maintainability, or design integrity). Although prior research has examined the detection or repair of smells, we still lack a clear understanding of how and when these issues emerge in generated code. This paper addresses this gap by systematically measuring, explaining and mitigating smell propensity in LLM-generated code. We build on the Propensity Smelly Score (PSC), a probabilistic metric that estimates the likelihood of generating particular smell types, and establish its robustness as a signal of structural quality. Using PSC as an instrument for causal analysis, we identify how generation strategy, model size, model architecture and prompt formulation shape the structural properties of generated code. Our findings show that prompt design and architectural choices play a decisive role in smell propensity and motivate practical mitigation strategies that reduce its occurrence. A user study further demonstrates that PSC helps developers interpret model behavior and assess code quality, providing evidence that smell propensity signals can support human judgement. Taken together, our work lays the groundwork for integrating quality-aware assessments into the evaluation and deployment of LLMs for code.
title A Causal Perspective on Measuring, Explaining and Mitigating Smells in LLM-Generated Code
topic Software Engineering
url https://arxiv.org/abs/2511.15817