Manuscript Offprint

arXiv:2610.05858

PreMaQ: Predicting Maintainability-Related Quality of LLM-Generated Code Before Generation

Taiki Wakamatsu, Yuta Ishimoto, Masanari Kondo, Yasutaka Kamei

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Taiki Wakamatsu*, Yuta Ishimoto†, Masanari Kondo*, Yasutaka Kamei*

*Kyushu University, Fukuoka, Japan †The University of Osaka, Osaka, Japan

t.wakamatsu@posl.ait.kyushu-u.ac.jp, ishimoto@ist.osaka-u.ac.jp, {kondo, kamei}@ait.kyushu-u.ac.jp

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.

Index Terms—LLM-generated code, internal representations, maintainability-related code quality assessment

I. INTRODUCTION

Large language models (LLMs) are now widely used to generate code, supporting tasks that range from code completion to whole-function generation. However, using such code in real-world development requires developers to inspect it and revise it where necessary. Prior studies report that LLM-generated code may contain functional errors [1], security vulnerabilities [2], [3], code smells [4], [5], and maintainability issues [6], [7]. Verifying and revising LLM-generated code also imposes additional effort and cognitive load on developers [8]. Assessing generated code therefore requires looking beyond whether it passes tests and considering maintainability-related quality, such as code smells and structural complexity.

Maintainability-related quality is typically assessed by applying static analysis to the code after it has been generated. However, code generation itself incurs computational cost and latency, and the generated code may still be functionally incorrect or difficult to maintain. If such code is discarded after generation and evaluation, both generation and evaluation costs are wasted. To reduce unnecessary code generation, prior work has used internal representations available before or during generation to predict properties of generated code. For example, such internal representations have been used to predict functional correctness [9]–[11] and compilability or vulnerabilities [12]. However, these studies mainly target functional correctness or security, and whether internal representations can predict maintainability-related quality before generation remains unexplored.

Motivated by this open question, this study introduces and evaluates Pre-Generation Maintainability-Related Quality Prediction (PreMaQ), which uses prefill activations to predict maintainability-related quality before code generation. Prefill activations are the internal representations computed while an LLM processes the input prompt. Figure 1 shows the PreMaQ workflow. As the maintainability-related quality to be predicted, we use the following two indicators used in a prior study [13]: Code Smell Score (CSS) [7], [14] and Maintainability Index (MI) [15], [16].

We evaluate prediction both within and across benchmarks to examine whether it extends beyond benchmark-specific patterns. As a downstream analysis, we examine the model selection problem of identifying, among multiple models known to generate functionally correct code for a task, the model likely to produce code with the highest maintainability-related quality. Our evaluation uses four open-weight LLMs (DeepSeek-Coder-6.7B-Instruct, Qwen2.5-Coder-7B-Instruct, Phi-4, and Qwen3.5-27B-FP8) and 2,695 tasks drawn from four Python code generation benchmarks (HumanEval+, MBPP+, BigCodeBench, and LiveCodeBench).

The main contributions of this study are as follows:

• PreMaQ predicts maintainability-related quality before code generation. Within benchmarks, its predictions are significantly correlated with observed CSS and MI in all 16 model–benchmark combinations, with mean Spearman ρ\rho values of 0.57 and 0.65, respectively. They also generalize across benchmarks for most combinations.

• PreMaQ supports maintainability-aware model selection. Among models that generate functionally correct code for a task, PreMaQ closes 59.5 % of the quality gap between random and oracle selection, outperforming strategies without internal representations.

• PreMaQ provides signals complementary to prompt embeddings. Combining predictions from PreMaQ and prompt embeddings closes 60.7% of the quality gap be-

Figure

Fig. 1. Overview of the PreMaQ workflow and its evaluation.

tween random and oracle selection, outperforming either method alone.

References (36)