NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

CodePlan: Unlocking Reasoning Potential in Large Language Models by Scaling Code-form Planning

Jiaxin Wen, Jian Guan, Hongning Wang, Wei Wu, Minlie Huang

TL;DR

CodePlan is a scalable framework that boosts Large Language Model (LLM) reasoning by training models to generate a structured "code-form plan" (pseudocode) before producing a final answer. By leveraging the inherent logic of programming—such as loops and conditional branches—CodePlan achieves a 25.1% average performance boost across 13 complex reasoning benchmarks with minimal computational overhead.

The Challenge of Multi-Step Reasoning

While LLMs are masters of natural language, they frequently stumble when faced with complex, multi-step reasoning tasks. Common failure modes include "early answering" (jumping to a conclusion too fast), incoherent logic, and "focus drift" during long explanations.

Existing solutions like Chain-of-Thought (CoT) prompting or task-specific fine-tuning help, but they have distinct limitations. CoT can be messy and unstructured, while fine-tuning often fails to generalize to new types of problems. The authors of this paper argue that the "planning signal" in massive text corpora is often obscured by the nuances and ambiguities of natural language. To fix this, they propose using code as a universal language for planning, as it is inherently structured, unambiguous, and versatile.

The CodePlan Approach

The researchers introduce a two-stage generation process to enforce structured thinking:

  1. Planning ($Z$): The model generates a high-level, Python-style pseudocode plan that outlines the logic needed to solve the prompt. This includes using if-else statements for branching logic, for loops for iterative tasks, and modular functions to break down sub-problems.
  2. Surface Realization ($Y$): The model follows its own pseudocode to generate the final natural language response.
Comparison of Base Model, Standard Training, and CodePlan on reasoning tasks.

Scalable Data Curation

Instead of hiring humans to write millions of plans, the authors used a "gold annotator" model (Llama-3-8B-Instruct) to evaluate existing high-quality prompt-response pairs and "back-annotate" them with corresponding code-form plans. This allowed them to create a massive, diverse training set without the need for curated, task-specific datasets.

  • Training Data: A newly curated dataset of 2 million examples derived from WebInstruct, featuring ⟨prompt, code-form plan, response⟩ triples.
  • Evaluation: The model was tested across 13 benchmarks in five categories: Mathematical Reasoning (GSM8K, MATH, SVAMP), Symbolic Reasoning, Instruction Following, Multi-hop QA, and Decision-Making (ALFWorld).

Key Insights and Results

CodePlan was evaluated on Mistral-7B and Llama-2 (7B/13B) models, revealing several major advantages over traditional training methods:

  • 25.1% Average Relative Gain: Across all 13 benchmarks, CodePlan significantly outperformed vanilla training.
  • Code as a Logic Framework: Code naturally supports hierarchical reasoning. By defining variables and functions upfront, the model "frames" the problem before diving into low-level details, preventing logic drift.
  • The Complexity Advantage: One of the most striking findings is that CodePlan’s benefits increase as the task gets harder. On the MuSiQue benchmark, the relative improvement jumped from 6.3% for 2-hop questions to a massive 43.8% for 4-hop questions.
  • Superiority over Natural Language Planning: Training on code-form plans outperformed training on natural language plans. Code is more concise and easier for the model to learn from its pre-training data, where code is already prevalent.
  • High Efficiency: Unlike "implicit" planning methods that require heavy computation, CodePlan adds negligible overhead—only about a 5% increase in inference time.

Furthermore, CodePlan exhibits remarkable data efficiency. As shown in the training step analysis below, CodePlan models reach higher performance levels with significantly less training data than vanilla models, suggesting that the structured planning signal is much easier for the model to digest.

Training efficiency of CodePlan vs. Vanilla models on GSM8K and MuSiQue benchmarks.

Limitations and Future Work

While highly effective, CodePlan has a few limitations to address in future iterations:

  • Non-Executable Plans: Currently, the plans are pseudocode meant for the LLM to follow, not for a computer to execute. Integrating a real code interpreter for specific sub-tasks (like complex math) could further improve accuracy.
  • Error Propagation: The authors identified three main error types: Plan Error (logically flawed plan), Plan Following Error (ignoring a correct plan), and Subtask Execution Error (making a typo or arithmetic error despite a good plan).

Future directions include exploring "multi-path planning" (generating several plans and picking the best) and iterative plan refinement, allowing the model to fix its own plan if it detects an error mid-generation.

Summary updated

BibTeX
@inproceedings{wen2025codeplan,
  author = {Jiaxin Wen and Jian Guan and Hongning Wang and Wei Wu and Minlie Huang},
  title = {{CodePlan: Unlocking Reasoning Potential in Large Language Models by Scaling Code-form Planning}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=dCPF1wlqj8},
}
Figure