MCP
arXivarXiv
Preprint
Published: August 4, 2026
cs.SE

Route-Align-Verify for Functional Correctness in Code Generation

Abstract
Large language models (LLMs) have substantially improved code generation, yet achieving strong functional correctness remains difficult, especially for heterogeneous programming tasks where a single prompting strategy and a single directly generated output are often insufficient. In this paper, we present RAV, a lightweight and modular framework that improves code generation with a fixed backbone model through three coordinated stages: Route, which applies task-aware prompt routing before generation; Align, which reduces the mismatch between fine-tuning prompts and inference-time prompts through aligned LoRA adaptation; and Verify, which selects the final output by executing multiple candidates against visible public tests. We evaluate RAV on the MBPP benchmark under both the sanitized and full settings. The complete RAV pipeline achieves the best performance among all evaluated configurations, reaching 0.8911 on MBPP Sanitized and 0.8520 on MBPP Full. Compared with the base model, these results represent improvements of 6.35 and 9.92 percentage points, respectively. Component-wise ablation experiments further show that task-aware routing and aligned adaptation become substantially more effective when combined with execution-based verification. Additional robustness and contamination analyses support the reliability of the observed improvements. Overall, the results indicate that functional correctness in code generation can be meaningfully improved without modifying the backbone architecture, by jointly optimizing how tasks are prompted, how the model is adapted, and how final outputs are selected.
0
AI overview
Reviews
Citation graph
References · 16
Structured
This preview uses generator v1; v2 is available

Overview

Targeting the problem of improving functional correctness of code generation with a fixed backbone LLM, this paper proposes the lightweight modular RAV framework, consisting of three stages: Route (task-aware prompt routing), Align (prompt-alignment LoRA adaptation), and Verify (execution-based candidate selection), and completes an empirical validation on the MBPP benchmark.

Framework Preliminaries

Core Design of the RAV Lightweight Modular Framework

The RAV framework is a lightweight modular solution for optimizing functional correctness in code generation. It can be plugged into existing code generation pipelines without modifying the LLM backbone, and consists of three clearly positioned independent components corresponding to pre-generation, training, and post-generation stages. The pre-generation routing module selects the prompt suited to the current task based on task keywords and docstrings; the alignment module in the training stage reduces the mismatch between prompts and tasks by rewriting prompts according to the routed style; the post-generation verification module selects better generated candidates based on execution scores on public test sets. Together with the accompanying figure below, you can intuitively grasp the stage division of the full RAV pipeline and the arrangement of its modules.

Fig. 1: Overview of the Route-Align-Verify (RAV) framework: the upper part shows the aligned LoRA fine-tuning process with routed-style prompts; the lower part shows the inference pipeline including task-aware prompt routing and execution-based candidate selection.

Operating Mechanisms and Implementation Details of the Three RAV Stages

The task-aware prompt routing logic of the Route module, taking its implementation in the MBPP setting as an example, dispatches input tasks into three different prompt styles via lexical and task-structure cues: tasks dense in string processing trigger the string relaxed style, with trigger keywords including substring, palindrome, and other text-processing-related markers; algorithm- or math-oriented tasks trigger the algo relaxed style, with trigger keywords including prime number, greatest common divisor, and other arithmetic patterns; tasks with explicit boundary-case hints and relatively dense test descriptions trigger the edge relaxed style.

The Align module adopts the design of an aligned LoRA adapter, with the core goal of narrowing the distribution mismatch between the prompts used during fine-tuning and those used at inference. Unlike the common practice of training on generic instruction prompts and testing on routed prompts, this method rewrites the training inputs to be exactly consistent with the routed style used at inference, so that the resulting adapter can better fit the prompt mechanism actually used by the whole system.

The complete coordinated workflow of the three modules can be fully defined through formalized steps: first, the routing function Rtest(⋅)R_{test}(·) maps the raw task to a routed prompt pp, satisfying p=Rtest(x)p = R_{test}(x); then the generator GG, parameterized jointly by the backbone LLM MM and the optional aligned LoRA adapter AA, samples one or more sets of candidate programs C(x)={c1,c2,...,cn}C(x) = \{c_{1},c_{2},...,c_{n}\}, where each candidate cic_i is sampled from the distribution ci∼G(M;A,p)c_{i} \sim G(M;A, p); if verification is disabled, the system directly returns the first sampled candidate as the final output; if verification is enabled, the verifier VV scores each candidate and selects the highest-scoring candidate as the final output, i.e., the final result satisfies c^=arg⁡max⁡ci∈C(x)V(ci,x)\hat{c} = \arg \max_{c_{i} \in C(x)} V(c_{i},x).

Experimental Results on the MBPP Benchmark and Component Ablation Analysis

The study evaluates the RAV framework on the MBPP benchmark under the sanitized and full settings. The full RAV pipeline achieves the best results among all tested configurations, reaching 0.8911 on MBPP Sanitized and 0.8520 on MBPP Full, delivering performance improvements of 6.35 and 9.92 percentage points over the base model, respectively.

Component ablation results show clear differences across two-component combinations: the combination keeping only the Route and Align modules yields very limited improvement over the base model, whereas every two-component combination that includes the Verify module achieves performance gains close to those of the full RAV pipeline.

The interpretation of the experimental results indicates that the role of the Route and Align modules is to generate a candidate pool more favorable for producing correct solutions, and their effects fully materialize only when combined with the Verify module. The core value of routing and alignment adaptation is not to directly improve the quality of a single generation output, but to increase the probability that correct or near-correct candidates appear in the generation pool, after which the Verify module can select a better final program from this higher-quality candidate pool.

Inference Cost Boundary and Final Conclusions of the RAV Framework

The overall test-time inference overhead of the RAV framework can be quantified with a unified formula: let G be the cost of generating a single candidate program and E the cost of executing a single candidate on the public test cases; the framework's overall test-time cost is O(nG+1[Verify]⋅nE)O(nG + 1[\text{Verify}] \cdot nE), where n is the total number of sampled candidate programs. This expression clearly delineates the inference overhead boundary of the framework.

The paper's final core conclusion is that improvements in the functional correctness of code generation can be achieved without modifying the backbone architecture of the LLM itself: by coordinating the task's prompting approach, the model's adaptation logic, and the final output selection mechanism, significant performance gains can be obtained. The paper also notes that future work, through more complete full-factorial ablation experiments, broader benchmark coverage, and the introduction of stronger verification signals, can further clarify the framework's contribution boundaries and generality.

Rating
No ratings yet
Rate
Community rating
—
/ 5
No ratings yet
Rating
—
Soundness
—
Presentation
—
Contribution
—
Confidence
—
Discussion
Top
Newest
Questions
Replication
Author
No comments yet — be the first