Training with Pseudo-Code for Instruction Following

Prince Kumar, Rudra Murthy, Riyaz Bhat, Danish ContractorarXiv 2025

TL;DR

Large Language Models (LLMs) frequently struggle with complex, multi-step, or highly constrained instructions. This paper introduces a novel training-time approach where models are fine-tuned to translate natural language instructions into structured pseudo-code before generating a final response. This simple intermediate "thinking" step yields 8–21% relative gains on instruction-following benchmarks and dramatically boosts mathematical reasoning without requiring external code execution.

What Problem Does This Paper Address?

While modern LLMs excel at simple tasks, they often stumble when instructions involve compositional structures, nested logic, fine-grained formatting constraints, or irrelevant "distractor" information.

Prior research showed that prompting models with pseudo-code at inference time helps because code provides explicit representations of task structure, control flow, and constraints. However, forcing everyday users to write pseudo-code prompts is impractical, and relying on few-shot code demonstrations can be brittle. The authors address this gap by moving pseudo-code from an inference-time prompting trick to a core, training-time capability, making it a seamless, drop-in replacement for standard instruction-tuned models.

Figure 2. Examples of different instructions types: (a) a distractor instruction from KCIF (Murthy et al., 2025) (b) nested instruction from ComplexBench (Wen et al., 2024) (c) simple sequential chain from ComplexBench (Wen et al., 2024) (d) two ‘levels’ of fine-grained constraints from FollowBench (Jiang et al., 2024b)

Methods

The authors develop a scalable, automated Generate-Evaluate-Repair pipeline to augment existing natural language instruction datasets with high-quality pseudo-code equivalents:

  1. Generate: A powerful teacher model (Mixtral-8x7B-Instruct) uses 1-shot prompting to translate a natural language instruction into a structured pseudo-code program.
  2. Evaluate: The system executes inference using only the generated pseudo-code program to see if it successfully produces the correct ground-truth output.
  3. Repair: If the pseudo-code fails to produce the correct answer (but the original natural language instruction succeeded), an LLM-judge provides feedback to fix and refine the program.

Base models (ranging from 7B to 8B parameters) are then trained via Supervised Fine-Tuning (SFT) on this augmented data. During training, given a natural language prompt, the model learns to first output the pseudo-code enclosed in custom [PSEUDOCODE] tags before generating the final answer.

Figure 1. Sketch of the data conversion pipeline along with an example instruction and corresponding pseudo-code program. The prompt used for generating pseudo-code is shown in Appendix Figure 7 and the prompt used for pseudo-code Repair is presented in Appendix

Datasets

The training data was curated from a subset of the TuluV2 mixture, including:

  • Instruction & Code: Code Alpaca, GPT4-Alpaca, WizardLM Evol Instruct, and Super-NaturalInstructions (SNI v2).
  • Reasoning & Science: Tulu v2 Science and the Chain-of-Thought (CoT) subset of the FLAN collection.

The approach was evaluated across 12 benchmarks spanning four categories:

  • Instruction-Following: IFEval, KCIF, ComplexBench, FollowBench, AgentIF.
  • Mathematics: GSM8K, GSM8K Platinum, MathQA.
  • Common Sense & Reasoning: ARC, HellaSwag, PiQA, Winogrande.
  • Code Tasks: HumanEvalPack.

Key Insights and Ideas

  • Pseudo-code as an Implicit Plan: Unlike standard Chain-of-Thought (CoT) which relies on verbose natural language reasoning, pseudo-code forces the model to construct a concise, unambiguous execution plan. This structural clarity prevents the model from getting confused by nested constraints or distractors.
  • The "Free" Math Upgrade: Explicitly training models to generate pseudo-code instructions for non-math tasks drastically improves their performance on downstream mathematical reasoning tasks. For example, the Granite 3.1 8B model's GSM8K score shot up from a near-zero baseline (0.02) to 0.66 when trained with pseudo-code.
  • Training Beats Prompting: Integrating pseudo-code generation directly into the model's weights via SFT consistently outperforms inference-time code prompting baselines, proving that structural thinking can be internalized.

Key Results

The authors evaluated their method across six base models (including Llama 3.1 8B, Mistral 7B v0.3, and Qwen2.5 7B). Key quantitative findings include:

  • Instruction Following: Pseudo-code (PC) tuned models achieved relative performance gains of 8–21% over standard natural language (NL) tuned baselines.
  • Complex Logic: On ComplexBench, PC-tuned models consistently outperformed NL baselines across all nesting depths and compositional types (e.g., handling conjunctions and conditional sequences).
  • Formatting Mastery: PC-tuned models showed notable relative gains of 11–27% on strict formatting constraints like JSON and bulleted lists.
  • Code Robustness: Despite pseudo-code focusing purely on instruction specification rather than solution guidance, it positively transferred to standard code generation tasks, improving average scores across HumanEvalPack.

Limitations and Future Work

While promising, the authors highlight a few key limitations:

  • Scale Questions: It remains unclear if these performance gains persist when scaling up to much larger model architectures (e.g., 70B+ parameters) or massive instruction-tuning datasets.
  • Length Control Issues: Models trained to output pseudo-code struggled slightly with strict length-control constraints, likely because generating the code block alters the model's internal token-counting calibration.
  • Real-World Scenarios: The method has not yet been stress-tested in complex, real-world deployment setups such as Retrieval-Augmented Generation (RAG), multi-turn dialogues, or tool-calling environments.

Summary updated

BibTeX
@misc{kumar2025training,
  author = {Prince Kumar and Rudra Murthy and Riyaz Bhat and Danish Contractor},
  title = {{Training with Pseudo-Code for Instruction Following}},
  year = {2025},
  eprint = {2505.18011},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2505.18011},
}
Figure