PreMaQ: Predicting Maintainability-Related Quality of LLM-Generated Code Before Generation
Taiki Wakamatsu, Yuta Ishimoto, Masanari Kondo, Yasutaka Kamei
Abstract
As large language models (LLMs) become increasingly capable of code generation, adopting generated code in software development requires assessing not only its functional correctness but also its maintainability-related quality. If such quality could be estimated before generation, developers could avoid the cost of generating, reviewing, and discarding low-quality code. Although prior work has shown that the functional correctness of the LLM-generated code can be predicted in advance, it remains unclear whether maintainability-related quality is similarly predictable. We introduce Pre-Generation Maintainability-Related Quality Prediction (PreMaQ), which predicts the Code Smell Score (CSS) and Maintainability Index (MI) of generated code from the internal representations of LLMs before generation. Our evaluation covers four open-weight LLMs and four Python code generation benchmarks, comprising 2,695 tasks in total. Our results show that predicted CSS and MI consistently correlate with their observed values across all 16 model-benchmark combinations, achieving mean Spearman rank correlations of 0.57 and 0.65, respectively. When used for model selection, PreMaQ achieves 59.5% of the maintainability-related quality improvement attainable by an ideal maintainability-based selector over random selection on tasks for which multiple models generate functionally correct code. Combining predictions from PreMaQ and prompt embeddings increases this proportion to 60.7%, indicating that the two signals are complementary. These findings suggest that PreMaQ can be used to predict and improve the maintainability-related quality of LLM-generated code.
Create a lesson
Metadata
- Comments
- 10 pages, 4 figures
Related papers
Understanding and Mitigating Library-Related Issues in LLM-Generated Code
Shared title terminologycs.SEYacine Majdoub, Rinad Hamid, Eya Ben Charrada et al.
Newer and Bigger, but Safer? A Longitudinal Study of the Functionality-Security Gap in LLM-Generated Code
Shared title terminologycs.SEThiago Santos de Moura, Fynn Matuschek, Flavio Toffalini et al.
Code Detectors Have a Half-Life: Obsolescence and Metric Illusions in LLM-Generated Code Detection
Shared title terminologycs.SEAlberick Euraste Djire
RBioBench: an execution-based benchmark for biomedical R code generation
Shared title terminologycs.SEXihao Piao, Dong Wang, Ziwei Yang et al.
Escalate on Failure: A Single-Model Mode-Switching Cascade for Local Code Generation
Shared title terminologycs.SEBrian K. Hudes
AI-Generated Code Issues: A Taxonomy from Repository Histories, AI Conversations, and Developer Interviews
Shared title terminologycs.SERosalia Tufano, Nargiz Humbatova, Daniele Bifolco et al.