mlsanityData to 7 Oct 2026

Executable Counterfactuals: Improving LLMs' Causal Reasoning Through Code

arXiv 2510.01539 ↗First posted 2 Oct 2025cs.LGcited by 10

On the map: LLM reasoning → Causal reasoning in LLMs

Abstract (arXiv)

Counterfactual reasoning, a hallmark of intelligence, consists of three steps: inferring latent variables from observations (abduction), constructing alternatives (interventions), and predicting their outcomes (prediction). This skill is essential for advancing LLMs' causal understanding and expanding their applications in high-stakes domains such as scientific research. However, existing efforts in assessing LLM's counterfactual reasoning capabilities tend to skip the abduction step, effectively reducing to interventional reasoning and leading to overestimation of LLM performance. To address this, we introduce executable counterfactuals, a novel framework that operationalizes causal reasoning through code and math problems. Our framework explicitly requires all three steps of counterfactual reasoning and enables scalable synthetic data creation with varying difficulty, creating a frontier for evaluating and improving LLM's reasoning. Our results reveal substantial drop in accuracy (25-40%) from interventional to counterfactual reasoning for SOTA models like o4-mini and Claude-4-Sonnet. To address this gap, we construct a training set comprising counterfactual code problems having if-else condition and test on out-of-domain code structures (e.g. having while-loop); we also test whether a model trained on code would generalize to counterfactual math word problems. While supervised finetuning on stronger models' reasoning traces improves in-domain performance of Qwen models, it leads to a decrease in accuracy on OOD tasks such as counterfactual math problems. In contrast, reinforcement learning induces the core cognitive behaviors and generalizes to new domains, yielding gains over the base model on both code (improvement of 1.5x-2x) and math problems. Analysis of the reasoning traces reinforces these findings and highlights the promise of RL for improving LLMs' counterfactual reasoning.

Key facts. Cited by 10 papers in the map (data through 7 Oct 2026). Placed in Causal reasoning in LLMs, one of 17 directions in LLM reasoning. Builds on 37 of its 62 references that are in the map. First posted on arXiv 2 Oct 2025.

Builds on

37 of 62 references.

Closest ancestors · 7

Same direction, newest first

  1. 2025On the Eligibility of LLMs for Counterfactual Reasoning: A Decompositional Study17 May
  2. 2025CounterBench: Evaluating and Improving Counterfactual Reasoning in Large Language Models16 Feb
  3. 2024Reasoning Elicitation in Language Models via Counterfactual Feedback2 Oct
  4. 2024Teaching Transformers Causal Reasoning through Axiomatic Training10 Jul
  5. 2023CLadder: Assessing Causal Reasoning in Language Models7 Dec
  6. 2023CLOMO: Counterfactual Logical Modification with Large Language Models29 Nov
  7. 2023Causal Reasoning and Large Language Models: Opening a New Frontier for Causality28 Apr

Other references · 30

  1. 2024DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Modelscited by 8,851
  2. 2025DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learningcited by 6,146
  3. 2024HybridFlow: A Flexible and Efficient RLHF Frameworkcited by 1,980
  4. 2020Beyond Accuracy: Behavioral Testing of NLP models with CheckListcited by 979
  5. 2025SFT Memorizes, RL Generalizes: A Comparative Study of Foundation Model Post-trainingcited by 655
  6. 2019Leveraging Procedural Generation to Benchmark Reinforcement Learningcited by 478
  7. 2019Learning the Difference that Makes a Difference with Counterfactually-Augmented Datacited by 428
  8. 2023Understanding the Effects of RLHF on LLM Generalisation and Diversitycited by 386
  9. 2021Brax -- A Differentiable Physics Engine for Large Scale Rigid Body Simulationcited by 375
  10. 2025Cognitive Behaviors that Enable Self-Improving Reasoners, or, Four Habits of Highly Effective STaRscited by 373
  11. 2023Can Large Language Models Infer Causation from Correlation?cited by 142
  12. 2025On the Generalization of SFT: A Reinforcement Learning Perspective with Reward Rectificationcited by 121
18 more
  1. 2024Physics of Language Models: Part 2.1, Grade-School Math and the Hidden Reasoning Processcited by 107
  2. 2020Generate Your Counterfactuals: Towards Controlled Counterfactual Generation for Textcited by 75
  3. 2019WIQA: A dataset for "What if..." reasoning over procedural textcited by 71
  4. 2023Integrating Large Language Model for Improved Causal Discoverycited by 54
  5. 2025OMEGA: Can LLMs Reason Outside the Box in Math? Evaluating Exploratory, Compositional, and Transformative Generalizationcited by 48
  6. 2023Causal Order: The Key to Leveraging Imperfect Experts in Causal Inferencecited by 46
  7. 2021An Investigation of the (In)effectiveness of Counterfactually Augmented Datacited by 42
  8. 2023Prompting Large Language Models for Counterfactual Generation: An Empirical Studycited by 36
  9. 2025Retro-Search: Exploring Untaken Paths for Deeper and Efficient Reasoningcited by 32
  10. 2023On Evaluating and Mitigating Gender Biases in Multilingual Settingscited by 31
  11. 2024LLMs for Generating and Evaluating Counterfactuals: A Comprehensive Studycited by 30
  12. 2025NaturalThoughts: Selecting and Distilling Reasoning Traces for General Reasoning Taskscited by 29
  13. 2023IfQA: A Dataset for Open-domain Question Answering under Counterfactual Presuppositionscited by 25
  14. 2025Finding Flawed Fictions: Evaluating Complex Reasoning in Language Models via Plot Hole Detectioncited by 24
  15. 2024CausalBN-Bench: A Comprehensive Benchmark for Causal Learning Capability of LLMscited by 20
  16. 2025Abduct, Act, Predict: Scaffolding Causal Inference for Automated Failure Attribution in Multi-Agent Systemscited by 14
  17. 2025Through the Valley: Path to Effective Long CoT Training for Small Language Modelscited by 10
  18. 2025Can LLMs Reconcile Knowledge Conflicts in Counterfactual Reasoningcited by 7

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2025: 1; 2026: 9.

10 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2026Better Think Thrice: Learning to Reason Causally with Double Counterfactual Consistency
  2. 2025Flying Pigs, FaR and Beyond: Evaluating LLM Reasoning in Counterfactual Worlds
  3. 2023Counterfactual Collaborative Reasoning
  4. 2026Counterfactual Simulation Training for Chain-of-Thought Faithfulness
  5. 2025Counterfactual reasoning: an analysis of in-context emergence
  6. 2022Counterfactual reasoning: Do language models need world knowledge for causal understanding?
  7. 2023What If the TV Was Off? Examining Counterfactual Reasoning Abilities of Multi-modal Language Models
  8. 2025Can LLMs Explain Themselves Counterfactually?