Code Execution as Grounded Supervision for LLM Reasoning

Dongwon Jung, Wenxuan Zhou, Muhao Chen

Abstract

Training large language models (LLMs) with chain-of-thought (CoT) supervision has proven effective for enhancing their reasoning abilities. However, obtaining reliable and accurate reasoning supervision remains a significant challenge. We propose a scalable method for generating a high-quality CoT supervision dataset by leveraging the determinism of program execution. Unlike existing reasoning dataset generation methods that rely on costly human annotations or error-prone LLM-generated CoT, our approach extracts verifiable, step-by-step reasoning traces from code execution and transforms them into a natural language CoT reasoning. Experiments on reasoning benchmarks across various domains show that our method effectively equips LLMs with transferable reasoning abilities across diverse tasks. Furthermore, the ablation studies validate that our method produces highly accurate reasoning data and reduces overall token length during inference by reducing meaningless repetition and overthinking.

Introduction

Chain-of-Thought (CoT) prompting and fine-tuning have significantly advanced the reasoning capabilities of Large Language Models (LLMs). However, the scarcity of high-quality CoT training data remains a primary bottleneck. Current approaches typically rely on expensive human annotations or synthetic data generated by larger LLMs. Synthetic data often suffers from hallucinations or logical errors in intermediate steps, even when the final answer is correct. This paper introduces a scalable method to generate massive amounts of step-by-step reasoning data where the intermediate logic is grounded in deterministic code execution, ensuring correctness.

Methodology

The core innovation lies in bypassing the unreliability of LLM-generated "thinking" by grounding reasoning in executable code. The pipeline consists of three primary stages:

  1. Execution Trace Acquisition: Existing problem-solution Python pairs are executed with specific inputs using the Snoop debugging tool. This captures a line-by-line execution trace, including function calls, control flow, and exact variable state changes.
  2. Execution Trace Translation: Raw execution logs are translated into human-readable natural language reasoning paths using a strong LLM (e.g., Qwen3-32B). This "Translator" ensures the reasoning follows the exact logic and values from the code execution.
  3. Supervised Fine-Tuning (SFT): Target models (e.g., Qwen3-4B and Qwen3-8B) are fine-tuned on this translated, execution-grounded CoT dataset.
The proposed pipeline for generating execution-grounded reasoning traces.

Experimental Results

The method was evaluated on a training set of 15K instances derived from the PyEdu-R dataset and tested across multiple benchmarks including MATH500, BBH, AGIEval, GPQA, and LiveBench.

Performance and Accuracy

The proposed method consistently outperformed baselines, including the base models and the CodeI/O distillation method. For the Qwen3-8B model, average accuracy across all benchmarks reached 61.5%, compared to 57.8% for CodeI/O. Notably, the intermediate reasoning steps were correct 91.5% of the time on LiveBench, a significant improvement over the 73.0% achieved by CodeI/O.

Performance comparison across various reasoning benchmarks.

Efficiency and "Overthinking"

A key insight from the study is that grounding reasoning in linear, programmatic execution reduces "overthinking." Models trained with this method generated 20% to 30% fewer tokens during inference compared to base models, effectively eliminating circular logic and meaningless repetition.

Conclusion

By leveraging the determinism of code execution, this method provides a scalable way to generate high-quality, verifiable reasoning data. While currently limited to domains formalizable through code (math, logic, programming), it demonstrates that programmatic grounding is a powerful tool for aligning LLM reasoning with logical truth. Future work will explore broader applications and integration with test-time scaling methods.

Summary updated

BibTeX
@inproceedings{jung2025code,
  author = {Dongwon Jung and Wenxuan Zhou and Muhao Chen},
  title = {{Code Execution as Grounded Supervision for LLM Reasoning}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2025},
  url = {https://openreview.net/forum?id=UsPBAXoKLx},
}
Figure