SLMFix: Leveraging Small Language Models for Error Fixing with Reinforcement Learning

David Jiahao Fu, Aryan Gupta, Aaron Councilman, David Grove, Yu-Xiong Wang, Vikram S. AdvearXiv 2025 · DOI

Abstract

Code generation in Low-Resource Programming Languages (LRPLs) and Domain-Specific Languages (DSLs) often suffers from syntactic errors and hallucinations. SLMFix addresses this "last mile" problem through a "Large Model generates, Small Model repairs" strategy. By fine-tuning a 500M-parameter Small Language Model (SLM) using Reinforcement Learning (RL) with rewards based on static analysis and Abstract Syntax Tree (AST) similarity, SLMFix achieves over a 95% pass rate on DSLs, significantly outperforming larger models and traditional supervised fine-tuning.

Introduction

While Large Language Models (LLMs) excel at general coding tasks, they frequently struggle with the precise constraints of niche languages. Fine-tuning massive models for these specific domains is computationally expensive. Existing self-correction methods often fail because the model lacks deep domain-specific knowledge. SLMFix proposes a lightweight, specialized "repairman" model to ensure syntactic and functional correctness without the overhead of a giant model.

Methods

The SLMFix pipeline consists of two distinct stages: generation and repair.

The SLMFix training and inference workflow, highlighting the PPO-based repair loop.
  1. Generation: An off-the-shelf LLM (e.g., Qwen-7B) generates an initial program from a natural language query.
  2. Repair: If a static validator detects errors, a specialized SLM (e.g., Qwen-0.5B) takes the prompt, buggy code, and error message to produce a fixed version.

Reinforcement Learning with Adaptive Rewards

Instead of standard Supervised Fine-Tuning (SFT), SLMFix utilizes Proximal Policy Optimization (PPO). The reward function combines:

  • Static Validity: Rewards code that passes a compiler or linter.
  • Semantic Similarity: Uses AST-based scoring to measure functional alignment with the ground truth.

A key innovation is Dynamic Weighting, where the reward function shifts focus from syntax early in training to semantic correctness as the model matures.

Evaluation and Results

The authors evaluated SLMFix across three DSLs: Ansible (low-resource), SQL, and Bash (high-resource).

Performance comparison of SLMFix against baselines across various small language models (0.5B to 2B parameters).

Key Findings

  • High Pass Rates: SLMFix achieved a >95% pass rate on static validators across all tested languages. On the Ansible dataset, it reached a 96.64% pass rate using a Granite-3.3 2B base.
  • Efficiency: A 500M parameter repairer outperformed 7B models fine-tuned via SFT. For instance, on the Ansible dataset, SLMFix (0.5B) outperformed SFT on a 7B model by significant margins.
  • AST Advantage: AST similarity proved to be a highly effective proxy for functional correctness in DSLs, predicting execution results over 75% of the time without requiring full test suites.

Discussion and Conclusion

SLMFix demonstrates that "error fixing" is a distinct skill that can be efficiently mastered by small models. By specializing a tiny model in repair rather than generation, researchers can achieve high-quality results at a fraction of the computational cost.

Future work includes reducing dependency on ground-truth code for RL rewards and extending the framework to general-purpose languages like Python or C++, where AST similarity may be a less reliable metric for functional equivalence due to implementation diversity.

Summary updated

BibTeX
@misc{fu2025slmfix,
  author = {David Jiahao Fu and Aryan Gupta and Aaron Councilman and David Grove and Yu-Xiong Wang and Vikram S. Adve},
  title = {{SLMFix: Leveraging Small Language Models for Error Fixing with Reinforcement Learning}},
  year = {2025},
  eprint = {2511.19422},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2511.19422},
}
Figure