TL;DR
This paper introduces Decoding Time Verification (DTV), a framework that integrates deterministic code verifiers (like compilers and type checkers) directly into the LLM generation loop. By pausing at structural boundaries (like statements or blocks) to validate code prefixes and rolling back when errors are detected, DTV prevents early mistakes from corrupting the model's context, significantly boosting translation success rates while using fewer tokens.
What Problem Does This Paper Address?
When using Large Language Models (LLMs) for code translation (e.g., converting C to Rust), a single early mistake can ruin the entire output. Because LLMs generate text autoregressively—token by token, conditioning on everything they've written so far—an early syntax or type error corrupts the generation context. The model then tries to build on top of this broken foundation, leading to a cascade of errors.
Traditional test-time scaling methods try to fix this post-hoc by running compilers or tests after the entire program is generated and asking the model to self-debug. However, this is highly inefficient because the model rarely recovers from deeply entrenched early errors. The authors address this gap by bringing verification inside the decoding loop, catching errors before they propagate.
Methods
The authors propose Decoding Time Verification (DTV), a state-machine-driven decoding framework that interleaves code generation with deterministic verifier calls.
Instead of checking the code token-by-token (which is impossible for compilers that need complete code structures), DTV operates at meta steps defined by structural boundaries (statements, blocks, functions).
The core framework relies on three key mechanisms:
- Structural-Boundary Verification: Generation pauses at logical code boundaries. The partial prefix is rendered into a verifier-consumable artifact and checked by tools like compilers or linters. If it passes, the prefix is committed as a safe checkpoint.
- Structure-Aware Rollback with Escalation: If verification fails, the controller rolls back the generation to the smallest scope implicated by the compiler's error message (e.g., deleting just the faulty statement). If retries fail repeatedly, it escalates to wider scopes (e.g., rolling back the entire block).
- Feedback via Prompt Augmentation: When a rollback occurs, the compiler's error diagnostics are injected back into the prompt context. Retries proceed in either inline continuation mode (adding errors as comments) or patch-based repair mode (requesting a diff).
Datasets
The framework was evaluated on two distinct code translation tasks:
- C to Rust (Unsafe-to-Safe Translation): 300 C programs sampled from Project CodeNet. Test inputs were generated using a hybrid LLM-seeded AFL++ fuzzing pipeline to ensure high branch coverage. The in-loop verifier was
rustc. - JavaScript to TypeScript (Dynamic-to-Static Typing): 150 programs from TypeWeaver that fail standard type-checking. The verifiers used were
tsc(TypeScript compiler) and ESLint.
Key Insights and Ideas
- The Early-Rise Effect: DTV exhibits a distinct advantage in token efficiency. Because it catches and fixes errors early, it achieves high pass rates at much lower token budgets compared to naive self-refinement, which must regenerate entire programs from scratch.
- Locality Matters: DTV's rescue rate is highly dependent on the "shape" of the fix. It excels at resolving local errors (where the fix is on the exact line the compiler flagged) but its performance drops when dealing with non-local errors (e.g., an error flagged on line 50 that actually requires changing a variable definition on line 5).
- Compositionality: DTV acts as an inner-loop decoding wrapper. The authors found that it successfully composes with, rather than replaces, outer-loop test-time scaling methods like multi-round self-refinement.
Key Results
Using Qwen3-4B as the primary generation model under matched token budgets, DTV achieved substantial performance gains:
- C to Rust: DTV improved the compilation pass rate from 72.3% to 82.0% relative to a cost-matched self-refinement baseline, while actually using fewer tokens per case.
- JavaScript to TypeScript: The pass rate increased from 33.3% to 46.0%.
The authors also verified that these gains did not come at the expense of behavioral correctness; differential testing confirmed that DTV maintained semantic equivalence to the source programs. The performance gains also successfully transferred to another model family, Gemma-4-E4B.
Limitations and Future Work
- Oracle Requirements: DTV relies heavily on verifiers that provide localized, actionable diagnostics with source-line attribution. It cannot be easily driven by global pass/fail signals (like pure differential testing) during the inner loop.
- Non-Local Semantic Errors: Errors requiring global architectural redesigns or cross-module consistency checks fall outside the capabilities of DTV's localized rollback ladder.
- Wall-Clock Overhead: While DTV is highly token-efficient (saving LLM compute), it requires invoking compilers and linters frequently during generation. In environments where toolchain startup or compilation latency is high, this can increase overall wall-clock time.
Future work includes scaling DTV to larger models, extending it to non-translation domains (like theorem proving or formal modeling), and combining it with token-level constrained decoding.
Summary updated