NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Improving LLM-Generated Code Quality with GRPO

Maxime Robeyns, Laurence Aitchison

TL;DR

Current reinforcement learning (RL) methods for code generation focus almost exclusively on functional correctness—whether the code passes unit tests—often producing messy, unmaintainable, or insecure code. This paper introduces cisq_analyzer, a library that turns automated software quality metrics into a dense scalar reward for Group Relative Policy Optimization (GRPO). Training with this quality-aware reward improves standard code quality metrics and earns a 79.2% win rate in blind human evaluations without hurting functional correctness.

What Problem Does This Paper Address?

While modern LLMs excel at generating code that passes unit tests, passing tests doesn't guarantee the code is actually good. Real-world software engineering requires readability, maintainability, type safety, security, and resource efficiency. Standard execution feedback (e.g., binary pass/fail test signals) often encourages "vibe-coded" solutions packed with unused imports, missing error handling, potential vulnerabilities, or unnecessary algorithmic overhead.

The authors address the gap between functional correctness and code quality by asking: Can we programmatically quantify holistic code quality and use it as a training reward in reinforcement learning?

Methods

  1. cisq_analyzer Reward Engine:
    The authors built an automated analysis library based on the Consortium for Information & Software Quality (CISQ / ISO 5055) standards. It combines established static analysis tools (Pylint, Radon, Xenon, Bandit, Vulture, and Mypy) with custom-built analyzers to cover four key dimensions:

  2. Maintainability: Cyclomatic complexity, dead code, code smell, docstrings.

  3. Security: Shell injection, insecure deserialization, weak hashing (MD5/SHA1).
  4. Performance: Suboptimal loops, repeated string concatenation, excessive memory allocations.
  5. Reliability: Bare except blocks, concurrency locks, loop termination conditions, and type safety.

Each detected flaw is mapped to a Common Weakness Enumeration (CWE) ID and assigned a severity weight: $$\{w_{\text{info}}=0.5,\, w_{\text{low}}=1.0,\, w_{\text{medium}}=2.5,\, w_{\text{high}}=5.0,\, w_{\text{critical}}=10.0\}$$ The weighted sum $W = \sum w_s N_s$ is converted into a normalized reward: $$r_{\text{quality}} = \frac{1}{1 + W}$$

  1. GRPO with Multi-Objective Reward:
    Using Group Relative Policy Optimization (GRPO), the policy is optimized with a composite reward: $$r = 0.2 \cdot r_{\text{format}} + 0.3 \cdot r_{\text{correctness}} + 0.5 \cdot r_{\text{quality}}$$
  2. $r_{\text{format}}$: Rewards well-structured markdown code blocks and penalizes multiple or broken blocks.
  3. $r_{\text{correctness}}$: Continuous pass rate on held-out unit tests.
  4. $r_{\text{quality}}$: The normalized CISQ score.

Datasets

The authors found standard benchmarks like HumanEval, MBPP, and APPS insufficient because their algorithmic toy problems rarely trigger complex quality issues like resource management, exception handling, or secure coding.

To address this, they synthesized a dataset of 200 Python code-editing problems generated via Gemini 2.5 Pro across 25 categories (e.g., immutability, exception handling, loop efficiency, redundant work). Each task includes:

  • A problem specification.
  • Suboptimal starter code exhibiting real-world code smells or bugs.
  • A reference solution and unit tests.

Key Insights and Ideas

  • Quality doesn't have to hurt correctness: Counterintuitively, penalizing code smells in Qwen 2.5 and Llama 3.2 did not compromise correctness. In fact, correctness slightly improved, likely because cleaner abstractions and defensive edge-case handling help avoid subtle bugs.
  • Shorter code at test time: Models trained with the quality reward generated cleaner, more concise code on average. This means post-training for quality reduces inference latency and token costs during deployment.
  • Computationally cheap rewards: Because static analyzers execute in parallel, cisq_analyzer evaluates a rollout in under 1 second on CPU, making it lightweight enough for on-policy RL loops.

Key Results

The authors fine-tuned Qwen 2.5 3B Instruct, Llama 3.2 3B Instruct, and OLMo 2 1B Instruct:

Model Val Quality (Base $\rightarrow$ +Quality) Val Correctness (Base $\rightarrow$ +Quality) Total Reward
Qwen 2.5 3B-Instruct 0.766 $\rightarrow$ 0.878 (+0.112) 0.567 $\rightarrow$ 0.690 (+0.123) 0.603 $\rightarrow$ 0.785
Llama 3.2 3B 0.859 $\rightarrow$ 0.894 (+0.035) 0.601 $\rightarrow$ 0.609 (+0.008) 0.627 $\rightarrow$ 0.760
OLMo 2 1B Instruct 0.791 $\rightarrow$ 0.864 (+0.073) 0.305 $\rightarrow$ 0.217 (-0.088) 0.410 $\rightarrow$ 0.631
  • Blinded Human Preference: In 418 pairwise comparisons evaluated by 5 expert annotators, code from quality-trained Qwen 2.5 was preferred 79.2% of the time ($p < 0.001$, Cohen’s $h = 0.614$).
  • Qualitative Improvements: As seen in side-by-side inspections, quality-trained outputs systematically pruned unused imports, integrated typing annotations (List[int] -> int), avoided bare exception handling, and favored cleaner idioms (e.g., built-in sum() over manual loops).

Limitations and Future Work

  • Capacity Bottlenecks in Smaller Models: For the smallest model tested (OLMo 2 1B), unit test correctness degraded noticeably (-0.088), suggesting that smaller models struggle to balance strict quality constraints with task completion.
  • Dataset Scale: The synthetic dataset comprises only 200 tasks, limiting diversity across broader software engineering paradigms.
  • Heuristic Reward Weighting: The linear coefficients (0.2 format, 0.3 correctness, 0.5 quality) and severity penalties were set empirically without extensive hyperparameter ablation.

Summary updated

BibTeX
@inproceedings{robeyns2025improving,
  author = {Maxime Robeyns and Laurence Aitchison},
  title = {{Improving LLM-Generated Code Quality with GRPO}},
  booktitle = {RLBrew @ RLC},
  year = {2025},
  url = {https://openreview.net/forum?id=wdJT3KNCv6},
}
Figure