AI
New framework teaches AI code generators to follow quality standards alongside correctness
Researchers propose a preference learning approach that guides large language models to produce code that meets style and maintainability requirements, not just functional correctness.
While large language models have become integral to code completion tools, the code they produce often passes functional tests yet violates style guidelines and maintainability standards. A new framework aims to close this gap by training LLMs to generate code that adheres to non-functional quality criteria alongside delivering correct outputs.
The Quality Problem#
Functionally correct code—code that produces the right answer—represents only part of what constitutes good software. Professional codebases demand adherence to style conventions, clear naming, proper documentation, and architectural patterns that ensure long-term maintainability. Current LLM-based code generators frequently neglect these dimensions, producing working but poorly-formed implementations.
Three-Phase Training Approach#
The proposed framework works in three stages. Researchers first build training datasets pairing code samples with non-functional quality issues against improved versions that correct those issues. They then apply an adaptive token weighting mechanism that focuses the model's attention on quality-sensitive regions of the code. Finally, they combine multiple optimization signals—ranking loss, language modeling loss, and KL divergence—to guide the model toward generating compliant code.
Strong Early Results#
Testing on DeepSeek-Coder and Qwen2.5-Coder showed substantial improvements. On the MBPP-sanitized benchmark, Qwen2.5-Coder achieved a 75.7% relative increase in Quality Reciprocal Score, a metric capturing compliance with quality standards. Critically, the approach maintained functional correctness while raising quality compliance. Fine-tuning a 7-billion-parameter model took less than three hours, suggesting practical viability for real-world deployment.
Why It Matters#
As LLMs expand their role in production engineering, the ability to enforce quality standards automatically becomes increasingly valuable. Rather than requiring human review to catch style violations or maintainability gaps, AI systems trained this way can generate code ready for integration with minimal cleanup—accelerating development cycles while preserving code quality.

