Executable Counterfactuals: Improving LLMs' Causal Reasoning Through Code
Authors: Aniket Vashishtha
Qirun Dai
Hongyuan Mei
Amit Sharma
Chenhao Tan
Hao Peng
Venue: ICLR 2026 Poster (2026)
Keywords: Counterfactual Reasoning
Large Language Models
Reinforcement Learning
Generalization
Primary area: foundation or frontier models, including LLMs
TL;DR: We introduce executable counterfactuals, a novel framework that operationalizes causal reasoning through code and math problems, and highlight the promise of RL for improving LLMs' counterfactual reasoning.

Abstract: Counterfactual reasoning, a hallmark of intelligence, consists of three steps: inferring latent variables from observations (abduction), constructing alternative situations (interventions), and predicting the outcomes of the alternatives (prediction). This skill is essential for advancing LLMs' causal understanding and expanding their applications in high-stakes domains such as scientific research and healthcare. However, existing efforts in assessing LLM's counterfactual reasoning capabilities tend to skip the abduction step, effectively reducing to interventional reasoning and leading to over-estimated 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 new frontier for evaluating and improving LLM's reasoning. Our results reveal substantial drop in accuracy (25-40%) from interventional to counterfactual reasoning for state-of-the-art models such as o4-mini and Claude-4-Sonnet. To address this gap, we construct a training set comprising counterfactual code problems having if-condition and test on out-of-distribution 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 (SFT) on stronger models' reasoning traces improves in-distribution performance of Qwen models, it leads to a decrease in accuracy on out-of-distribution tasks such as counterfactual math problems. In contrast, reinforcement learning (RL) induces the core cognitive behaviors and generalizes to new distributions, yielding substantial accuracy gains over the base model on both code (improvement of 1.5x-2x) and counterfactual math problems. Analysis of the reasoning traces further reinforces these findings and highlights the promise of RL with scalable data generation for improving LLMs' counterfactual reasoning.

Published as a conference paper at ICLR 2026
EXECUTABLE COUNTERFACTUALS. IMPROVING LLMs' CAUSAL REASONING THROUGH CODE
Aniket Vashishtha Qirun Dai Hongyuan Mei
Amit Sharma 41 Chenhao Tan 21
Hao Peng If
Universitt of Illinois Urbana-Chane Champaagn
"The University of Chicago
TTIIC
"Microsoft Research India
ABSTRACT
Counterfactual reasoning, hallmark of intelligence, consists of three steps: in- ferring latent variables from observations (abduction), constructing alternative situations (intervention), and predicting the outcomes of the alternatives (pre- diction). This skill is essential for advancing LLMs' causal understanding and expanding their applications in high-stakes domains such as scientific research and healthcare. However, existing efforts in assessing LLM's counterfactual reasoning capabilities tend to skip the abduction step. effectively reducing to interventional reasoning and leading to over-estimated LLM performance. To address this, we in- troduce 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 new frontier for evaluating and improving LLM's reasoning. Our results reveal substantial drop in accuracy (25-40%) from inter- ventional to counterfactual reasoning for state-of-the-ee models such 04-mini and Claude-4-Sonett. To address this gap, construct training set comprising counterfactual code problems having if-condition and test on out-of-distribution code structures (e.g., having while-loop); we also test whether a model trained on code can generalize to counterfactual math word problems. While supervised finetuning (SFT) stronger models' reasoning traces improves in-distribution per- formance of Qwen models, it leads to a decrease in accuracy on ouitt--diitribuution tasks. In contrast, reinforcement learning (RL) induces the core cognitive behaviors and generalizes to new distributions, yielding substantial accuracy gains over the base model both code (f-1.5-2X) and counterfactual math problems. Anal- ysis of the reasoning traces further reinforces these findings and highlights the promise of RL with scalable data generation for improving LLMs' counterfac- tual reasoning, Our code and data are available at AniketVashis hhtth hatchhaa/exeebbbbeeeeee caaelleooooteeaaaaaaa
com/
INTRODUCTION
Counterfactual reasoning is the cognitive process of answering what-if questions that underpin critical domains such as scientific discovery (Schölkopt et al. (02T), healthcare (Richens et al. 2020). economics (Athey & Imbens 2017), and public policy (Poulos & Zeng 2021p. Given action and an observed outcome, it involves inferring the latent state of a system when the action was performed (abduction), constructing alternative scenarios through interventions, and predicting the outcomes under those counterfactual scenarios (Pearl) [002aa] [Epstude & Roese (2008. Despite the importance of counterfactual reasoning. it remains widely documented weakness of current large language
models (LLMs; Jin et al. 2024 Yamin et al. 2025 Yu et al. 2023).
Evaluating and improving counterfactual reasoning is challenging because counterfactuals are inher- ently unobservable and rely on hypothetical alternatives to reality. As result, prior work considers
"Equal contribution.
1 Equul advising.
Correspondence v20 11
eduu, qi rundai @uchi cago.

---

Published as a conference paper at ICLR 2026
Structured Causal Model (SCM)
1
def f(r, x):
2
1f r 0.3:
y =
X
Y
R
else:
$3.1
5
y
6
return
$3.3
randon, randon()
9 f(r, x)
Given with and an unknown r, what would have been if we had set
Every catering tray is $6. There is
The tumor did not shrink after Interferon. Given the patient's s biology, what if they had received Imatinib instead?
per-tray service fee. For 6 trays the total $42. instead trays were ordered, what amount would be shown?
3, keeping the same
Step 1:
Infer r 2 0.3 based on the observation f(r =1 =-=
Infer the per-tray service fee is $1 based on the observation
Infer the unobserved tumor aggressiveness
Abduction
Step Intervention
Overwrite x
Overwrite #trays
Set the alternative treatment
Step 3:
Predict,(y > 0.3.3) =
Predict the amount 11 x (6 1) = 77
Predict alternative outcome
Prediction
Executable Counterfactuals
Executable Counterfactuals Math ($3.2)
Ilustrative Medical Toy Example
Code ($3.1)
Figure 1: Our Executable Counterfactuals framework rooted code reasoning (left), and can also be easily extended to the math domain (middle). Code offers controlled, executable setting that maps naturally to causal/computatinall graphs and transfers to natural-language tasks. We also offer medical toy example (right) to better illustrate the three cognitive skills, abduucionn-intervenion prediction, required for addressing true counterfactual reasoning.
either synthetic graph-based settings that are hard to map to real-world problem solving (Jin et al. 2024) simplistic tasks that are expressed in counterfactual language but can be solved without invoking all aspects of counterfactual reasoning. Examples include binary classification tasks given full information about the causal graph (Would Y still occur if X didn't It happen?: Chen al. 2025) or benchmarks based on perturbations of existing reasoning problems (thus creating new "counterfactual" problems: /w et al. 2024). With full information (i.e., there are no latent confounders or noise), these problems can be solved by simple forward reasoning (Gerstenberg) 2022): change the input variables' values as instructed and solve it as new problem, without any counterfactual reasoning.
These simplified interpretations of counterfactuals risk conflating them with simpler forms of causal reasoning ($2) and thus misrepresent LLMs' counterfactual abilities. To address these limitations, we identify the three core cognitive skills from Pearl's definition of counterfactual reasoning (Pearl 2002a Abbduciionn Intervention and Prediction-and construct tasks that requires all three skills to obtain correct solution. Key benefits of this perspective include explicit separation of counterfactual reasoning from simpler forms of causal reasoning, fine- fine-graine attribution of models' strengths and weaknesses, and actionable framework for improvement ($3). Moreover, beyond counterfactuals, improvements to these cognitive skills can independently serve as building blocks for stronger L.M reasoning in general.
Our key idea is to use code understanding as the problem setup to study counterfactual reasoning (i.e., executable counterfactuals). Specifically, we investigate whether model can correctly reason about the output of a code function when its input arguments are differently set, conditioned on a pair of factual input and output. Notably, we introduce latent random variables to these code functions. The values of these variables are kept unchanged throughout the reasoning process, but not revealed to the language model, thus requiring the model infer them from the given factual inputs and outputs. In the framework of structural causal models, these latent variables can be considered as noise variables that need to be inferred from the given factual information before making any counterfactual prediction. As shown in the illustrative example in Figure D the causal structure X + + R where X and R independently cause Y converts to a program where X computes Y while R determines conditional branching. A counterfactual question is constructed observation = f(r, x = 1) = -1 with unknown r, what would y have been if we had set x 3, keeping the same r? Solving this problem requries the agent invoke all three cognitive skills: (1)
Given
2

---

Published as a conference paper at ICLR 2026
infer r based on the observation x 1, -1 (abduction), (2) mentally set (intervention), and (3) compute the resulting y (prediction).
Beyond the aforementioned benefits, code-based framework avoids the potential ambiguity of natural language, and allows rich and controllable complexity for constructing evaluation problems and generating synthetic training data. It evaluates models' ability to use counterfactual reasoning for problem solving rather than reducing the task to answer binary classification questions (Jin et al. 2024; Chen et al. 2025). In addition, facilitates evaluating and improving out-of-distribution generalization by varying the program structures and translating coding tasks into math problems ($32).
We address the following important research questions with executable counterfactuals:
1. How do current LLMS perform on counterfactual reasoning? Our experiments with open models of sizes ranging from 1.5B to 72B parameter and commercial reasoning models show strong performance on straightforward code-execution tasks, but poor performance on counterfactual reasoning over the same code. Qualitative analysis indicates consistent failure the abduction step, leading to incorrect conditioning on the original observation to infer latent features.
Can SFT distillation from stronger models instill these skills and do they generalize? We finetune Qwen LBB/BB//B-Instrre on reasoning trajectories from DeepSeck-Distilld--e 32B, and observe ~40% performance improvements on in-domain evaluation. However, these improvements do not generalize to unseen code structures or counterfactual math problems, highlighting the limited generalization of SFT.
3. How does RL fare? Training the same models with RL from verifiable rewards (RLVR) using GRPO (Shao al.) 2024) leads the models acquire the necessary cognitive skills, showing strong transfer across diverse code structures and counterfactual math problems in natural language, with concrete evidence of improved generalization.
Our findings have two key implications. First, they reinforce recent evidence that current LLMs remain weak at counterfactual and causal reasoning (Jin et al., 2024 Second, our experiments call into question the effectiveness of SFT, a widely adopted approach by recent works to improve counterfactual reasoning (Guo et al. 2025 Li et al. (025), especially regarding its ability to generalize to complex and high-impact real-world domains. In contrast, our results show that RL elicits stronger generalization for counterfactual reasoning; despite training only on code, the model internalizes the core skills and applies them directly to counterfactual math problems, providing early evidence that RL is a promising pathway for eliciting such reasoning in LLMs. Crucially, shown in the experiments, our code-based framework has the potential to offer scalable way for learning counterfactual reasoning that transfers to new domains where training data can be scarce. All code and data will be publicly released upon publication.
2023: Willig et al. 2023).
2 BACKGROUND AND RELATED WORK
In this section, we will first outline the cognitive skills required for counterfactual reasoning and then show how it is often conflated with interventional reasoning in prior work.
From abduction prediction. We use Figure I as a running example expand the cognitive skills required for counterfactual reasoning. Three steps are needed to answer the counterfactual question Given observation y f(r, = 1), what would y have been had x instead the original run?
Step 1: Hindsight reasoning for abduction: Rewind back to the point where the original action taken, to infer latent features and noise present in the system at that time. The above counterfactual question, cannot be answered by simply re-running the program with x = 3. One must first abduce the hidden latent variable f 2 0.3 from the observed run f(f, = 1) = 1.
Step 2: Taking a different action (intervention): Conditioned on the inferred latent features from abduction stage, perform the counterfactual change by intervening the input to its counterfactual value while keeping everything else the same as in the earlier observation. For the code example, this means holding f fixed while intervening by overwriting x = 3.
Step 3: Prediction: Based on the new action taken, compute its consequences in the counterfactual scenario. In the example, computing yet = f( 2 0.3, 3) is final prediction step.
3

---

Published as a conference paper at ICLR 2026
Without latent states and the abduction step, counterfactual reasoning reduces to interventional reasoning, corresponding to Level 2 in Pearl's 's causal ladder (Pearl 2009). which breaks down causal reasoning to three progressively more advanced levels: Associational (Level 1), Interventional (Level 2), and Counterfactual (Level 3); see Appendix A for a detailed overview.
Past studies often overlook abduction. Prior evaluations of LLM counterfactual reasoning often use fully observed settings with no latent noise. This effectively makes the abduction step unnecessary since there no unobserved variable or noise to abduce. In such regimes, a counterfactual query collapses
interventional one: the answer follows directly from taking different action not requiring the step of inferring hidden state. Take Figure (left) as an example and consider the 0.4, x 3? Although q may appear similar to the counterfactual question in Figure [ it is fundamentally different. Crucially, answering q does not require abducting the values of r, since it is explicitly specified. Therefore, solving q relies solely on interventional reasoning (Level 2) rather than counterfactual reasoning (Level 3); this sense. q effectively collapses an interventional question despite its seemingly "counterfactual" framing.
following question q: What would y have been be if we had set
The above example question q, though synthetic, conceptually illustrates the key reason for the mischaracterization of counterfactuals in many recent works (Wu et al. (2024) Li et al. [022]] Chen
ct al.
2025 Nguyen et al. 2024b Paranjape et al. 2022 Wu et al. 202 Madaan et al. 202 Ye al.
2021
Joshi & He 2022 Vashishtha al. 2023 See Appendix D for detailed discussions.
Clearly distinguishing counterfactual from interventional reasoning important for accurately understanding the capabilities and limitations of current LLM paradigms, and for designing algorithms that advance their causal reasoning. It requires an explicit characterization of the three-step process of abduction, intervention, and prediction, which motivates our executable counterfactual framework.
Other related work. Jin et al. (2024) provides formal benchmarks across the causal ladder, includ- ing counterfactuals. While well grounded in causal theory, some tasks are less aligned with realistic applications and often presuppose familiarity with advanced tools of causal inference (do-calculus, d-separation, mediation, etc.), making it hard to pinpoint whether errors stem from graph inference, identification, effect decomposition, causal benchmarks for LLMs (Yang et al. 2025) Zhou et al.) 2024). Operating on code and math, two domains where recent LLMs have made rapid progress, our framework provides concrete mechanisms for isolating their causal capabilities and applying established methods such as SFT and RLVR to enhance counterfactual reasoning ($4). Finally, there is another line of related work on counterfactual example generation for fairness and interpretability research in NLP. We provide a detailed discussion on these topics in Appendix F
numerical calculation. Similar trade-offs appear in recent
3 OPERATIONALIZING COUNTERFACTUAL REASONING VIA CODE & MATH
We move beyond graphical approaches Yang et al. 2025) and purely formal tests (Jin et al. 2023 2024) by using executable code as an actionable environment for counterfactual reasoning. Because programs are computational graphs, they map naturally onto mathematical and graph formalisms and enable fine-graing -raigndi control of task difficulty and nutent-variable structures. This allows for designing out-of-distributte (OOD) evaluation by encoding causal graphs with novel features and logic unseen during training. Our framework produces executable counterfactuals with verifiable ground-truth outcomes for both evaluation and training.
3.1 EXECUTABLE COUNTERFACTUALS:: CODE
Overview. We generate distinct and executable Python functions from small set of templates (8 for training, and 3-4 for each evaluation setup) by abstracting out the overall program structure and isolating from specific variables and operators. Unlike prior work that typically uses checklist
It should be acknowledged that many of these works focus on robustness, generalization, and debiasing, and never intend to study counterfactuals as in the causal sense. Nonetheless, the loose use of the counterfactual framing can lead to misinterpretationss by the readers /Zhao et al. 2018); Kaushik et al. (2020); Vashishtha et al. 2023), which highlights the importance of precise characterization of counterfactuals.
4

---

Published as a conference paper at ICLR 2026
def (function_ socu_volue1
def generated_ lunc, 322RE, scel_value);
JuT generated, war.eee__nn___tnnoe SORVEN, 17: or
undoo..seedfoo aaodd//eeee_aaaa candor.randint... B1
r- www.aattadantnnnen (sax_(t)
reselt clsez
tpreprecessing_Bles.. block?
15: if 5:
result - -
condition_tspel: if r tcomperison_ppt (threshold);
result
alif x
slanz result r*c
result x
result = (0r.t
alif 4:
18-
elses
eiMe:
18
roultt
11
resul: (aritheetii
reault renslt
11-
elam:
(elck_Nleck)
returm
12
13-
e1se:
retur Trauite
slse__rrnch__crteene
(b) A concrete code function generated from the template in 2a
return (xpressoprrs
(c) Another structurally different
(a) One of the templates for If else functions in training dataset.
function that originates from the same template 2a
Figure 2:
Structural diversity emerges from our nested template based approach where single template can generate structurally and semantically different functions as shown in 2b and 2c
approach which merely swaps numbers or operators while keeping the same control flow (Ribeiro al. 2020), we use function templates where complete code blocks with different functional purposes are replaced by empty placeholders (Figure Fa). Specifically, we apply Claude-4-Someel to draft these templates and potential code block candidates for each placeholder, and perform manual verification to ensure quality and diversity. For each type of dataset split (training or evaluation) and control logic (if-else, while loop, etc.), we fix small set of templates along with list of code block candidates. For training datasets, we supply 15 combinations of function templates and code block candidates. Moreover, promote finer-grained variations in intermediate computations, and variables in the functions changeable. Finally, we deduplicate the generated functions using techniques in Appendix H which eventually results in large and diverse of executable functions using an efficient and controllable recipe.
also make operators
Template-based generation.
We consider the following four function logic:
1. If else: These simple functions have most level of nesting structure, thus keeping the intermediate computational steps at a low level (Figure 2a).
2. If else-long: To test if the models generalize longer code structures with more statements,
we construct this evaluation dataset with higher levels of nested if-else structures (Table 9
3. While: To test how models generalize counterfactual reasoning to control logic that it has never seen during training, we construct this dataset with while loops (Table
4. Multi r: To test how models generalize to a different causal structure where multiple hidden variables are present, we construct this dataset where each function has three unknown input arguments. Moreover, we level up the complexity by introducing simple for loops (Table 8) apart from if-else statements.
If else is used for both training and in-distribution (ID) evaluation, while If else-long. While, and Multi are used for
(OOD) evaluation and never used in the training data.
One important feature of our template approach is that there are three different levels of placeholders whose combinations can greatly advance the diversity of our final datasets.
Fixed placeholders: boilerplate such as the function name, reproducible draw of a latent variable r, by setting the random seed, and the final return statement. To design functions with more than one latent variables, we explicitly define placeholders for each extra latent variable.
Structural placeholders: Slots for complete code blocks that define the program's 's logic, including the optional pre-processing steps, the main i f--ondition (simple or compound), possible e elif clauses, code pieces inside each branch, and the form of the return statement.
Value placeholders: Specific operators and numbers (e.g., +, thresholds) that determine the function's detailed behavior once the structure chosen.
To better mirror real-world ambiguity, where multiple latent configurations can explain the same observation, insert modulo at the return statement training functions (i.e., return g(-) mod m).
5

---

Published as a conference paper at ICLR 2026
multiree pd
100
multi rintery While-ct
97.3
89.8
while-interv
35.0
75.9
76,3
71.5
744
Exact ExtctMatch Match
60
55.1
58.2
88.5
41.7
42.3
37.0
36.4
0
Owen 2.5-128 Instructt
Liama 3.3-708 33-708B-nstroct
OWO 328
GPC- 40
Claude 4-Sonnet
04
mint
Figure 3: Even for LLMs with strong general capabilities thinking features, the performance gap between counterfactual and interventional questions originated from the same code function can still be huge, showing the importance of targeted improvements in counterfactual reasoning.
The modulo's periodicity induces a many-to-one mapping from latent r to the observed output, so several r values consistent with the factual run, yielding multiple valid counterfactual outcomes. At evaluation, we score the model against the full set of valid answers: we report exact match (set equality) and an aggregated F/ that rewards partial coverage the ground-truth -ouun set.
To create the interventional version of the same programming problem, we keep the code unchanged and disclose the realized value(s) of Revealing r removes the abduction step, so the task reduces to re-evaluating the program under new input æ. Please refer to Table I0 for interventional prompt examples.
3.2 GSM MATH PROBLEM CONSTRUCTION FOR COUNTERFACTUAL REASONING
To test whether models can generalize beyond code, construct variants GSM-8K-style problems. See Figure (middle) for an illustrative example. The key idea introduce hidden factor in each problem. Taking inspiration from Ye et al. (024)), each problem starts in an everyday setting (office party, school fundraiser, etc.) and is specified by computational graph that tracks the key quantities (such as counts, unit prices, fees) and how they combine (sums, percentages, etc.). Inside this graph, we introduce one hidden factor that also contributes to the total; their value known in the computational graph but not revealed in the narrative. The hidden factors are simple but varied. Examples include: flat add-on (e.g., an unseen service fee), per-item add-on (e.g., an
dataset of counterfactual
fee per tray), and an unknown amount of additional items at a known unit price (e.g., some dessert boxes per tray at $3 each). We verbalize the graph into GSM-style word problems. To increase variety, we use a small set of phrasing templates for different settings (such as office party, fundraiser, etc) and vary both the scenarios and the point where the hidden factor is introduced into the graph. Ground truth answers are produced by executing the computational graphs, therefore resulting in verifiable answers. For creating an interventional version of the problem, we keep everything exactly the same and reveal the value of the latent variable in the problem statement (Table To ensure that the latent variable is used in final answer computation, for each problem constructed, we vary the value of the latent variable and see if it leads to change in final answer. there is change regenerate the problem.
EXPERIMENTS
With exccutable counterfactuals framework we answer the three research questions in $
4.1 LLMS SHOW WEAKNESSES IN COUNTERFACTUAL REASONING
Motivation and Setting. As discussed in 2 the lack of abduction in prior works reduces coun- terfactual reasoning interventional reasoning, thus failing distinguish the true counterfactual

---

Published as a conference paper at ICLR 2026
ID
Model Class
Model
_lse
if -eelse-long
multi.
while
F1
EM
F1
EM
F1
EM
F1
EM
Swen2..5-1.B-IIsstee
19.3
5.3
26.5
12.8
9.5
7.4
1.9
0.8
1ren2.551.5B-Insttuctte
62.7
44.4
51.3
32.0
21.4
20.7
2.8
2.4
Bwenn.5-1.5B-Imstruccee
34.7
20.2
50.3
39.6
25.5
25.2
5.0
4.2
Owen2.5-3B-Insteee
32.1
11.8
38.7
16.7
14,0
11.1
5.4
2.7
Swen2.5-3B-Instrutt--.
70.8
53.2
55.4
34.7
22.8
21.6
2.6
2.2
Controllably
Qwen2.5-3B-Instrruce
74.8
55.2
55.9
39.3
36.9
35.9
12.9
10.5
Trained Models
Qwen2.5-7B-Instuule
38.8
13.9
54.9
28.2
21.6
17.9
7.3
3.3
Owen2.5-7B-Instruu
75.8
59.0
61.4
41.7
24.9
23.3
2.5
2.1
Owen2.5-7B-Instrucct
81.7
67.8
75.0
58.3
40.3
36.3
11.2
8.1
Dwen2.5-32B-Instrrus
42.9
17.2
63.3
29.9
40.1
34.8
11,2
6.2
1rren2.5-72--nsstruue
47.0
20.3
65.0
32.8
42.3
37.0
13.6
9.0
General LLMs
Llama-3.
1.3 Instruttt
50.0
22.0
62.8
28.7
41.8
36.4
12.0
4.0
GPT-4o
50.6
25.6
62.6
32,9
44,8
41.7
10.5
4.4
Claude-4-Sonnet
79.1
60.6
81.3
59.0
63.5
58.8
53.0
46.9
RI-Distil-Qwwen322
86.0
69.1
89.7
77.9
57.1
47.9
69.7
63.1
Reasoning LLMs
QwQ-32B
73.5
54.9
85.1
73.0
44.7
41.3
63.2
58.5
04-mini
91.1
76.2
95.9
90.2
51.9
42.3
84.6
74.4
Table I:
Evaluation results on in-distribution (ID) and out-of-distribution (OOD) counterfactual coding tasks using executable counterfactuals framework. Since each question may contain multiple answers, we report both F1 and exact match scores percentage units.
from interventional capabilities. In light of this, we pair each of the counterfactual evaluation dataset of our framework with an interventional counterpart, which is built upon the same code function mathematical conditions except that the originally hidden variable is now revealed and fixed We evaluate a wide range of models with strong reasoning capabilities and present the comparison results in Figure 3 and Table [ Please refer to Appendix L.3 for the evaluation hyperparameters adopted throughout this work.
Findings. For six strong LLMs spamning four model families in both coding and math domains, there consistently exists significant performance gap between the counterfactual datasets of our framework and their interventional counterparts, regardless of model providers, sizes, and test-time scaling features. Notably, reasoning models (e.g., QwQ-32B (Team] 2025) and o4-mini) show nearly perfect interventional reasoning performance coding, yet achieve less than half on counterfactual reasoning. Non-reasoning models mostly score below 10% in counterfactual datasets with while loops, but can achieve over 70% their interventional counterparts. Therefore, our framework reveals the weakness of current strong LLMs in true counterfactual reasoning, suggesting the necessity of targeted post-trate tesittraining improvements apart from traditional focus on general capabilities only.
4.2 DISTILLATION-BAA. BASED SET GENERALIZES POORLY
Motivation and Setting. We then explore SFT, widely adopted approach that has been tradi- tionally shown effective for targeted improvements in counterfactual reasoning (Huyuk et al. 2025 Huang et al. 2024) Specifically, we opt for the popular long Chain-of-Thouuhh (long-Col CoTT) SFT paradigm, where the CoT annotations are distilled by reasoning model with thinking features, due to its proved benefits of better transfer in reasoning tasks (Guo et al., 2025 Li al., (025). We choose DeepSeek-R --ii--RR-D-D--------- Distill-Qwen-3211 (Guo et al.] 2025) as the teacher model, and D/wen2.5-1.5H/BBB Instruct series as the base models for all post- fost-training attempts throughout this work. Please refer to Appendix L. for more data annotation and training details.
Findings. As shown in Table and Figure g compared with their base, SFT models achieve strong in-distribution (ID) counterfactual reasoning performance, well decent performance when
7

---

Published as a conference paper at ICLR 2026
certain surface task features (e.g., length of code functions in if (eeeee--lon) out-of-distribution (OOD). However, when the fundamental reasoning structures these tasks become OOD, including the causal structure (e.g.. more hidden variables in multi r), control logic (e.g., while loops the control structure in while), and question domain (e.g.. from code-based to natural language- math reasoning in gsm), the gains of SFT diminishes and it even hurts the performance in most cases. Thus, our framework demonstrates that long-CoT SFT paradigm has only limited generalization of counterfactual reasoning. despite the powerful external supervision signals. These findings call for investigations into other post-training approaches that are not only more supervision-e -ffiiiennefi but can also generalize to complex and previously unseen task structures.
4.3 RLVR ELICITS GENERALIZABLE COUNTERFACTUAL REASONING SKILLS ACROSS CAUSAL STRUCTURES AND QUESTION DOMAINS
Motivation and Setting. In search of a supervision- efficient approach to generalize counterfactual reasoning capabilities, we eventually resort to reinforcement learn- ing. We use reinforcement learning from verifiable reward (RLVR) with GRPO (Shao et al. 2024), a popular com- bination that requires only outcome-hasee hased supervision, Following prior work (Sun et al.] 2025), we use exact match scores as the outcome-based reward, and set the prompt batch size and rollout size as 16 and 24 respec-
Instrct
SF1
RLVR
12.9
10.
tively. Please refer to Appendix L.2 for more details about RLVR training.
Figure 4: Accuracies on the GSM- counterfactual dataset under domain- transfer. RLVR consistently shows ef- fective generalization from code-based to natural language-basee counterfactual reasoning, while SFT consistently fails. Moreover, the improvements of RLVR also robustly scale with the model size.
Findings. As shown Table 1 and Figure RLVR achieves consistent and significant gains for all scales of models, and on all ID and OOD evaluation datasets. The improvements are especially strong multi_r. while, and gsm, where involve fundamentally OOD causal structures and reasoning contexts, and make our previous SFT at- tempt uniformly fail. Notably, a Qwen2.55-7 7-------rrr model trained with RLVR achieves comparable perfor- mance with Dwwen.55-72B-nnss
and consistently better performance than its 32B variant across the whole coding domain. Therefore, RLVR successfully achieves our goal of generalizing fundamental counterfactual reasoning skills to complex structures and previously unseen domains with minimal supervision.
BEHAVIORAL ANALYSIS OF REASONING TRACES
We next analyze the models' reasoning behaviors using executable counterfactuals. Table illustrates the three types prototypical failure that we observe in the reasoning traces:
1. Brute-force enumeration of all possible
values.
2. Assuming arbitrary value for the hidden variable the problem is considered too complex.
Complicating the problem through unnecessary case splitting and circular analyses.
Inspired by these observations, we evaluate each reasoning trace along two dimensions: planning and execution. The planning score evaluates whether the three core cognitive skills of counterfactual reasoning-abducctionn intervention, and prediction-ane sequentially applied. The execution score evaluates the correctness of mathematical computation and code simulation, a general skill that not specific to counterfactual reasoning. Following prior work (Sun al. 2025). use o4-mini the LLM judge to rate each dimension on a scale to 5, and defer other technical details, including the grading rubric in prompts, to Table 11 in Appendix. Figure presents the results.
Scaling model size improves computational accuracy, but not abduction skills. As shown in Figure 5 across all four coding tasks, scaling up the size of Qwen2.5- Instrrct models leads to
8

---

Published as a conference paper at ICLR 2026
Brute-Force Enumeration
Arbitrary Assumption
Since r not given, list r and unroll loops:
Assume r 3, otherwise would be too
r 0 - local_oosssoo sum 1 [1/3 0:
complex to solve. One outer iter: local_s _um = 3+ (3 1) =
r = 1 + local__sssaa = 3 [3/3 = 1:
r 2 Llocal_sune
[53 1;
17/3 2. For 12:
scan until y 120 fits at z
15.
12 2 12 36.
Unnecessary Case-Splitting
Recover from x 15, y 120 via inner-loop stops. Case 1: S 0 inner never runs
+ 15. Case 2: r > 0 - local_ sum after stepl is r. Split 2A: stop after stepl if r 2 5r. Split 2B: take step2 if 5r local sum 2r 1. Also split by 2r 1 vs. 5r
(<, =,=,>) and by (2r + 1) mod 3 {0, 1, 2); then branch q = [2r + 1)/3 E {6, 7, 7,8)
Table Examples of three prototypical failure modes in model-generated reasoning traces.
Planning
Execution
Instruct-78
Sff rivr
Instruct-328
instruct-720
3-
2.5
2.5
1.5
1.5
itelse
if-elselong
m
while
ifelsse
(felse-ions
muit
while
Figure 5: Evaluation results of the LLM- judde pipeline. For the responses generated by each model on each dataset, the evaluation objective is decoupled into "planning" (left; i.e., whether the "abduuctioniintervettio tntttrrreentoooppediitioon"" prediction" strategy is faithfully followed) and "execution" (right; i.e., whether the intermediate computations are correctly performed).
consistent improvements in execution ratings, but not in planning. Instead, 7B model consistently receives higher ratings for its abduction skills than 32B on 3/4 tasks, and scores 72B variant on both if_ else-long and while. This suggests that scaling up the size of LLMs that are post-trained general domains improves the final accuracy in way that does not comply with the standard "abduction- interveentionnpreeiiiiee performance even with large model size.
higher than the
strategy, thus resulting in poor counterfactual reasoning
SFT memorizes shallow abduction patterns that fail to generalize to complex problems. In Figure [5] the planning scores of SFT models substantially drop in OOD tasks. Our inspection of reasoning traces shows that when faced with OOD questions with increased complexity in completing the abduction step. SFT models tend to override the standard reasoning strategy, and instead revert to the prototypical failure modes discussed in Table 2 in order to evade true counterfactual reasoning.
RLVR generalizes counterfactual reasoning strategies, but is still bottlenecked by computational accuracy. As Figure 5 reveals, RLVR models achieve the highest planning scores across all evaluation datasets, demonstrating the generalizable counterfactual reasoning strategy that they learn to apply even in fundamentally OOD tasks. On the other hand, the sharp decrease in execution scores on both multi y and while also suggests that a major error type for RLVR is computational errors under the correct reasoning strategy. Therefore, learning counterfactual reasoning skills and general computational skills, and calls for future efforts into improving both skills simultaneously to build strong counterfactual reasoning agent.
framework identifies the asynchronism in

---

Published as a conference paper at ICLR 2026
6 CONCLUSION
We address gaps in evaluating counterfactual reasoning in LLMs by decomposing the skill into core components by introducing an executable, code-based framework. Our setup builds dynamic testbeds that require the full abduction, action, prediction rollout and allows for precise control over logic and latent features. Using a template-bn based approach, we generate many structurally diverse functions to form counterfactual queries and to train smaller models that currently struggle on these tasks. We find that LLMs typically struggle at the abduction step, and this limitation is not resolved by increasing model's s size large scale models (up 72B) also struggle with this. Our findings show that models trained with SFT transfer these skills in-domain code evaluations but significantly falter on OOD settings, whereas RL consistently induces them from code-only training and generalizes to novel control flows and natural- lattrall-luuggge counterfactual math. We corroborate this with qualitative case studies and L..M-as-a-Judae evaluations. Beyond counterfactuals, the same framework enables flexible evaluation of other causal skills and can help pinpoint where current systems fall short.
ETHICS AND REPRODUCIBILITY STATEMENT
Ethics. All datasets used in our work are created synthetically and will be released publicly. We also make best efforts provide fair and thorough comparison between framework and prior work. To the best of our knowledge, our work investigates fundamental aspects of causal reasoning in the context of large language models, and should not have direct societal impact or implication that should be discussed here specifically.
straightforward to construct our framework and reproduce our experimental results, given the implementation details specified in both the main text and appendix. We also plan to release our code and data to further advance the reproducibility of this work.
Reproducibility.
ACKNOWLEDGEMENTS
We are grateful to Lifan Yuan, Dylan Zhang, Junlin Yang, Shivam Agarwal, Deema Alnuhait, Daman Arora, Divyat Mahajan, Abhinav Kumar, Kabir Ahuja, Melanie Sclar, Yanai Elazar and members of Chicago Auman+AT Lab for their valuable support and insightful discussions. We are also grateful to Prof. Tobias Gerstenberg for the valuable feedback and insights our idea. This project is partly supported by NSF under award No. 2505932, No. 2126602, an Amazon AICE Award, an award from the Sloan foundation. grant from Coefficient Giving, gift funding from AI2, and an award from the Open Philanthropy foundation.
REFERENCES
Kabir Ahuja, Melanie Sclar, and Yulia Tsvetkov. Finding flawed fictions: Evaluating complex reasoning in language models via plot hole detection, 2025. URL /tt/attta://ccxi..com /bs// 2504. 900
Susan Athey and Guido W. Imbens. The state of applied econometries: Causality and policy evaluation. Journal of Economic Perspectives, 31(2):3-32, 2017. doi: 10. 10.12577jep.31.2233 URL
https: http://wwweeeeooorrroorreeeeeeea
Taiyu Ban, Lyvzhou Chen, Xiangyu Wang. and Huanhuan Chen. From query tools to causal architects: Harnessing large language models for advanced causal discovery from data. arXiv preprint arXiv:2306. 16902, 2023.
Yuefei Chen, Vivek K. Singh, Jing Ma, and Ruxiang Tang. Counterbench: A benchmark for counterfactuals reasoning large language models, 2025. URLLattps:/// arxiv. org/ abs/ 2502. 008
Tianzhe Chu, Yuexiang Zhai, Jihan Yang, Shengbang Tong, Saining Xie, Dale Schuurmans, Quoc V. Le, Sergey Levine, and Yi Ma. Sft memorizes, generalizes: A comparative study of foundation model post-training, 2025.
http://xwwwvvvoor/////////////// 17161
10

---

Published as a conference paper at ICLR 2026
Karl Cobbe, Christopher Hesse, Jacob Hilton, and John Schulman. Leveraging procedural gener- ation to benchmark reinforcement learning, 2020. URL http::://xxsx........m wwtp:xiw..rq.aaaoooo abs /911 01588
Tri Dao, Dan Fu, Stefano Ermon, Atri Rudra, and Christopher Ré. Flashattention: Fast and memory- efficient exact attention with io- ww-awsressss Advances in neural information processing systems, 35: 16344-16359, 2022.
Kai Epstude and Neal J. Roese.
The functional theory of counterfactual thinking. Personality and Social Psychology Review, 12(2):168-13 2008. doi: 10.1177/108866808311
C. Daniel Freeman, Erik Frey, Anton Raichuk. Sertan Girgin, Igor Mordatch, and Olivier Bachem. Brax a differentiable physics engine for large scale rigid body simulation, 2021. URL https
13281
Tobias Gerstenberg. What would have happened? counterfactuals, hypotheticals and causal judge- ments. Philosophical Transactions of the Royal Society B, 377(1866):22113339, 2022.
Daya Guo, Dejian Yang. Haowei Zhang, Junxiao Song, Ruoyu Zhang, Runxin Xu, Qihao Zhu, Shirong Ma, Peiyi Wang, Xiao Bi, et al. Deepseek-rl: Incentivizing reasoning capability in Ilms via reinforcement learning. arXiv preprint arXiv:2501.12944, 2025.
Pin-Lun Hsu, Yun Dai, Vignesh Kothapalli, Qingquan Song, Shao Tang, Siyu Zhu, Steven Shimizu, Shivam Sahni, Haowen Ning. Yanning Chen, and Zhipeng Wang. Liger-kernel: Efficient triton kernels for LLM training. In Championing Open-source DEvelopment in ML Workshop @ ICML25, 2025. URL btttee://oeeneeeeeeeeeeee/rrrrrp
Yinya Huang, Ruixin Hong, Hongming Zhang, Wei Shao, Zhicheng Yang, Dong Yu, Changshui Zhang, Xiaodan Liang and Linqi Song. Clomo: Counterfactual logical modification with large language models, 2024. htt.tpps////xx...trr////aa//////
17438
Alihan Huyuk, Xinnuo Xu, Jacqueline Maasch, Aditya V. Nori, and Javier GonzAalez. Reasoning elicitation in language models via counterfactual feedback, 2025. URL URL httptss////axx..orrr abs/2410.em 03767
Zhijing Jin, Jiarui Liu, Zhiheng Lyu, Spencer Poff, Mrinmaya Sachan, Rada Mihalcea, Mona Diab, and Bernhard Schölkopf. Can large language models infer causation from correlation? arXiv preprint ar arXiv:2306.0588
2023.
Zhijing Jin, Yuen Chen, Felix Leeb, Luigi Gresele, Ojasv Kamal, Zhiheng Lyu, Kevin Blin, Fer- nando Gonzalez Adauto, Max Cladder: Assessing causal reasoning in language models, 2024. URLhttps: /ttttps//arxiv..oo
Mrinmaya Sachan, and Bernhard SchÄülkopf.
abs/2312, 04 0
Nitish Joshi and He He. An investigation of the (in)effecttvenness of counterfactually augmented data, 2022. URLpttps: http:tttts//ax...ott wttp:///..rgaaa////aaaaaaaa 00753
Divyansh Kaushik, Eduard Hovy, and Zachary C. Lipton. Learning the difference that makes a difference with counterfactuully-augnnee augmented data, 2020. URL httpttt://axxi..rr////// abs//
1909. 12434
Emre KIeman, Robert Ness, Amit Sharma, and Chenhao Tan. Causal reasoning and large language models: Opening new frontier for causality. arXiv preprint 23X.:2233500000000 2023.
Robert Kirk, Ishita Mediratta, Christoforos Nalmpantis, Jelena Luketina, Eric Hambro, Edward Grefenstette, and Roberta Raileanu, Understanding the effects rlhf on 1lm generalisation and diversity, 2024. URL httpt:ttpps:/sttte orq/ abs 2310.3100 06452.
Woosuk Kwon, Zhuohan Li, Siyuan Zhuang, Ying Sheng, Lianmin Zheng, Cody Hao Yu, Joseph Gonzalez, Hao Zhang, and Ion Stoica. Efficient memory management for large language model serving with pagedattention. Proceedings of the 29th symposium on operating systems principles, pp. 611-62,, 2023.
11

---

Published as a conference paper at ICLR 2026
Brenden M Lake. Ruslan Salakhutdinov, and Joshua B Tenenbaum. Human-level concept learning through probabilistic program induction. Science, 350(6266) 1338, 2015. doi: 10.1126/ sciemce.aab3050.
0at. aab3050
Yang Li, Youssef Emad, Karthik Padthe, Jack Lanchantin, Weizhe Yuan, Thao Nguyen, Jason Weston, Shang-War Li, Dong Wang, Ilia Kulikov, et al. Naturalthouuhts: Selecting and distilling reasoning traces for general reasoning tasks. arXiv preprint arXiv:2507.01921, 2025.
Yongqi Li, Mayi Xu, Xin Miao, Shen Zhou, and Tieyun Qian. Prompting large language models for counterfactual generation: An empirical study, 2024. httthhttp://artt arg.abb/oooggs//
2305 14791
Stephamie Long, Alexandre Piché, Valentina Zantedeschi, Tibor Schuster, and Alexandre Drouin. Causal discovery with language models as imperfect experts. In ICML 2023 Workshop on Struc- tured Probabilistic Inference & Generative Modeling, 2023.
Ximing Lu, Seungju Han, David Acuna, Hyunwoo Kim, Jaehun Jung, Shrimai Prabhumoye, Niklas Muennighoff, Mostofa Patwary, Mohammad Shoeybi, Bryan Catanzaro, and Yejin Choi. Retro- search: Exploring untaken paths for deeper and efficient reasoning, 2025. URL https://
arxiv. abs/ 04383
Renjie Luo, Jiaxi Li, Chen Huang, and Wei Lu. Through the valley: Path to effective long cot training for small language models. arXiv preprint arXiv:2506.07712 2025.
Nishtha Madaan, Inkit Padhi, Naveen Panwar, and Diptikalyan Saha. Generate your counterfactuals: Towards controlled counterfactual generation for text, 2021. URL httptttt///ax....rrrgp/
abs/2012. 04698
Ashish Mishra, Gyanaranjan Nayak, Suparna Bhattacharya, Tarun Kumar, Arpit Shah, and Martin Foltin. LIm-guided counterfactual data generation for fairer ai. In Companion Proceedings of
the ACM Web Conference 2024, WWW '24, pp. 1538aA$1545, New York, NY. USA, 2024. Association for Computing Machinery, ISBN 97984000011726 1ttp://...111/333110 3355535883355555 3651929
doi: 10.1145/3589333.66112222
Van Bach Nguyen, Paul Youssef, Christin Seifert, and Jörg Schlötterer. LLMs for generating and evaluating counterfactuals: A comprehensive study. In Yaser Al-Onaizan, Mohit Bansal, and Yun- Nung Chen (eds.), Findings of the Association for Computational Linguistics: EMNLP 2024, pp. 14809-14824, Miami, Florida, USA, November 2024a. Association for Computational Linguistics. h/nn///nnnnnn..i.n---o- fww.iings-emll...7777 emnlp.870.
doi: 10.18653/v11200000 Sindings-emm-n 870/]
URL bttps::/acclanchoocoyy....
Van Bach Nguyen, Paul Youssef, Christin Seifert, and JÄürg SchlÄftterer. Lims for generating and evaluating counterfactuals: A comprehensive study, 2024b.
Bhargavi Paranjape, Matthew Lamm, and Ian Tenney. Retrieval-guidee counterfactual generation for QA. In Smaranda Muresan, Preslav Nakov, and Aline Villavicencio (eds.), Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Pupers), pp-
1670-16688 1680, Dublin, Ireland, May 2022. Association for Computational Linguistics. doi: 10.18653/ v1/2022.acl-long. 117. httpa//epp////aaaatttooo//////r.
Judea Pearl. Reasoning with cause and effectt. Af 23():)2, 2002a doi: 000.::::00.1100 10.1609/ammag. 22311.1612.
article/view/ine
Judea Pearl. Reasoning with cause and effect. A/ Magazine, 23(1):95-111,, 2002b. doi: 10.1609/
aimag.
Judea Pearl. Causality. Cambridge university press, 2009.
Jason Poulos and Shuxi Zeng. RNN-based counterfactual prediction, with an application to homestead policy and public schooling. Journal of the Royal Statistical Society: Series C (Applied Statistics),
124 August 2021. doi: 10.1111/rssc.l 1251. URL https: http::://doi.orr/11
1111/rssc: 12511
12

---

Published as a conference paper at ICLR 2026
Lianhui Qin, Antoine Bosselut, Ari Holtzman, Chandra Bhagavatula, Elizabeth Clark, and Yejin Choi. Counterfactual story reasoning and generation. In Kentaro Inui, Jing Jiang, Vincent Ng. and Xiaojun Wan (eds.), Proceedings of the 2019 Conference Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNNP--JCNIIP), pp. 5043- 3053-, Hong Kong, China, November 2019. Association for Computational Linguistics. doi: 10.18653/11/D1940 1509. URL httph:t//claanttiiiie
org/D19-1500
Jeff Rasley, Samyam Rajbhandari, Olatunji Ruwase, and Yuxiong He. Deepspeed: System op- timizations enable training deep learning models with over 100 billion parameters. In Pro- ceedings of the 26th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining, KDD '20, pp. 35058A$3506, New York, NY, USA, 2020. Association for Com- puting Machinery. ISBN 9781450379984, doi: 10.1145/3394488634007999 URL https
//doi.org/10. 1141/
3406703
Marco Tulio Ribeiro, Tongshuang Wu, Carlos Guestrin, and Sameer Singh. Beyond accuracy: Behavioral testing of nlp models with checklist, 2020. URL
2005. 04118
Jonathan G. Richens, Ciarán M. Lee, and Saurabh Johri. Improving the accuracy of med- ical diagnosis with causal machine learning. Nature Communications, 11:3923, 2020. doi: 10.1038/<4146--020- 1471000-1777-0 17419-7.
URL httpp::/wwwt www.w..tt.......m/..////w. com/ articles/
s 941467-020-174199
Bernhard Schölkopf, Francesco Locatello, Stefan Bauer, Nan Rosemary Ke, Nal Kalchbrenner, Anirudh Goyal, and Yoshua Bengio. Toward causal representation learning. Proceedings of the IEEE, 109(5):61--634, 2021. doi: 10. 10.109//PROC.2201.335599
Zhihong Shao, Peiyi Wang, Qihao Zhu, Runxin Xu, Junxiao Song, Xiao Bi, Haowei Zhang, Mingchuan Zhang, YK Li, Yang Wu, et al. Deepseekmath: Pushing the limits of mathemat- ical reasoning open language models. arXiv preprint arXiv:2402.033: 03000, 2024.
Guangming Sheng, Chi Zhang, Zilingfeng Ye, Xibin Wu, Wang Zhang, Ru Zhang, Yanghua Peng, Haibin Lin, and Chuan Wu. Hybridflow: A flexible and efficient rlhf framework. arXiv preprint arXiv: 2409. / 19256, 2024.
Yiyou Sun, Shawn Hu, Georgia Zhou, Ken Zheng, Hannaneh Hajishirzi, Nouha Dziri, and Dawn Song. Omega: Can Ilms reason outside the box in math? evaluating exploratory, compositional, and transformative generalization. arXiv preprint arXiv:2506.18881 2025.
Qwen Team, Qwq-32b: 32b: Embracing the power of reinforcement learning, March 2025. URL https: /twp::///ww/lm..mmm wwtpwenm..ithhb.......... ho/blogg/waaae qwa- 32b/
Aniket Vashishtha, Kabir Ahuja, and Sunayana Sitaram. On evaluating and mitigating gender biases in multilingual settings, 2023. URL phttps:///arxt.t http://aaxxx.cc./aaaaaa/aaaaaaa/ 2307. C1503
Aniket Vashishtha, Abhinay Kumar, Atharva Pandey, Abbavaram Gowtham Reddy, Kabir Ahuja, Vineeth N Balasubramanian, and Amit Sharma. Teaching transformers causal reasoning through
wttpivaiiiiv//.ia//eaaaaaaaae..a axiomatic training, 2025a. URL htt.apppp///aaai....rr/////22./2
Aniket Vashishtha, Abbavaram Gowtham Reddy, Abhinav Kumar, Saketh Bachu, Vineeth N Bala- subramanian, and Amit Sharma. Causal order: The key to leveraging imperfect experts in causal inference, 2025b. htt.stts:::///
org abs 2310 10.301111 201../111111111
Moritz Willig, Matej Zečević, Devendra Singh Dhami, and Kristian Kersting. Probing for correlations of causal facts: Large language models and causality, 2023. URL
Tongshuang Wu, Marco Tulio Ribeiro, Jeffrey Heer, and Daniel Weld. Polyjuice: Generat- ing counterfactuals for explaining, evaluating, and improving models. In Chengqing Zong, Fei Xia, Wenjie Li, and Roberto Navigli (eds.), Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference Natural I Language Processing (Volume I: Long Papers), pp. 6707-6723, Online, August
13

---

Published as a conference paper at ICLR 2026
2021. Association for Computational Linguisties. doi: 10.18653ww12002..adllongg URL 523/
Yongliang Wu, Yizhou Zhou, Zhou Ziheng, Yingzhe Peng, Xinyu Ye, Xinting Hu, Wenbo Zhu, Lu Qi, Ming-Hsuan Yang, and Xu Yang. On the generalization of sft: reinforcement learning perspective with reward rectification, 2025.
wwwpooggggbbboooeeeee 05629
Zhaofeng Wu, Linlu Qiu, Alexis Ross, Ekin Akyürek, Boyuan Chen, Bailin Wang. Najoung Kim, Jacob Andreas, and Yoon Kim. Reasoning or reciting? exploring the capabilities and limi- tations of language models through counterfactual tasks. In Kevin Duh, Helena Gomez, and Steven Bethard (eds.), Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume I: Long Papers), pp. 1819-1862, Mexico City, Mexico, June 2024, Association for Computational Linguis- 102. URL httpps//aacllaaccoooooooooooo
tics. doi: haacl-long 1027
Khurram Yamin, Gaurav Ghosal, and Bryan Wilder. Lims struggle to perform counterfactual reason- ing with parametric knowledge. 2025. URL URRptttss://axxi org/ abs/ 15732
Shuai Yang. Qi Yang, Luoxi Tang, Jeremy Blackburn, and Zhaohan Xi. On the eligibility of ilms for counterfactual reasoning: A decompositional study, 2025. URL
11839
Tian Ye, Zicheng Xu, Yuanzhi Li, and Zeyuan Allen-Zhu. Physics of language models: Part 2.1, grade-school math and the hidden reasoning process, 2024. URLLitttpp///axiiv..oo/////
2407. 203161
Xi Ye, Rohan Nair, and Greg Durrett. Connecting attributions and QA model behavior on realistic counterfactuals. In Yih (eds.), Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, pp. 5496-5512, Online and Punta Cana, Dominican Republic, November 2021. 101166551i12221...mmmmmaaa----
Moens, Xuanjing Huang. Lucia Specia, and Scott ten-tau
Association for Computational Linguistics. doi: 10. 00.18653/v1/22111 2at.022.-mmmp-mmii444444 URL https
//aclanchology.oom oww.:ooyy.or.o..... org/2011 emnlp- manoommain... 447/
Yixin Ye, Zhen Huang. Yang Xiao, Ethan Chern, Shijie Xia, and Pengfei Liu, LIMO: Less is more for reasoning. In Second Conference on Language Modeling, 2025. URL
net m d=
Wenhao Yu, Meng Jiang, Peter Clark, and Ashish Sabharwal. Ifqa: A dataset for open-domain question answering under counterfactual presuppositions, 2023. URL httl:tttt///xiii//
abs5 14010
Jieyu Zhao, Tianlu Wang, Mark Yatskar, Vicente Ordonez, and Kai-Wei Chang, Gender bias in coreference resolution: Evaluation and debiasing methods. In Marilyn Walker, Heng Ji, and Amanda Stent (eds.), Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 2 (Short Papers), pp. 15-20, New Orleans, Louisiana, June 2018. Association for Computational Linguistics. doi: 10. 10L.1855/11111--220
Yaowei Zheng, Richong Zhang, Junhao Zhang, Yanhan Ye, and Zheyan Luo. LlamaFactory: Unified efficient fine-tuning of 100+ language models. In Yixin Cao, Yang Feng, and Deyi Xiong (eds.), Proceedings of the 62nd Annual Meeting of the Association for Computational Lingwistics (Volume 3: System Demonstrations), pp. 400-410, Bangkok, Thailand, August
2024. Association for Computational Linguistics. doi: 10. 18653// 002663//1/2222.... ac2024.acl-dmmos... URL
387]
Yu Zhou, Xingyu Wu, Beicheng Huang, Jibin Wu, Liang Feng, and Kay Chen Tan, Causalbench: A comprehensive benchmark for causal learning capability of llms, 2024. WtRLhttts: htttps:///rxiiisi org/ bog/abs/2405 06349
14

---

Published as a conference paper at ICLR 2026
LIMITATIONS
One notable limitation of our work is that we focus on evaluating support-set inference instead of full counterfactual distributions. Despite being limitation, the choice of evaluating support-set inference only was made out of the following reasons:
1. With the form of the latent variable explicitly given (as input argument of the code function), support-set inference has exceptional tractability and verifiability.
2. Our results show that frontier models are already failing support-set inference alone. In light of this, the focus of our work on support-set inference can serve as the first step towards evaluating L.Ms on full counterfactual distributions.
Furthermore, we would like note that the majority of the prior works on counterfactual reasoning evaluation, as highlighted in $ follows a simple setting without the presence of any latent features or randomness, leading to a purely deterministic setting. Therefore, our focus on support-set inference is already major step towards faithful counterfactual reasoning evaluation.
A LLM USAGE STATEMENT
We use Large Language Models for analysis (LLM-as-a-Judge) and data construction in this work, which we have clearly defined our paper's methodology and analysis sections. LLMs have not been used in our study for other purposes.
B CAUSAL LADDER: LEVELS OF CAUSAL REASONING
The seminal work Pearl (009) breaks down causal reasoning in three progressively more advanced levels: Associational (level I), Interventional (level 2), and Counterfactual (level 3):
Associational level concerns observational learning and forms causal hypothesis solely through observations, often interpreted as pattern matching. This mirrors how most machine learning models learn from input features and corresponding labels. This form of learning suffers from potential confounding and selection bias as one cannot perform interventions to identify the underlying causal structure.
Interventional learning (level 2) requires learning through interventions, mirroring how humans typically learn by taking actions and observing the outcomes. While this type of learning might appear to be causal, due to the overall noise in the system which might be changing, identifying whether the observed outcome was solely due to the action performed becomes challenging.
Counterfactual reasoning (level 3) is the highest form of causal reasoning on the causal ladder. It helps in disentangling the effect of other factors in the system, to identify the outcome had the original action been different. However this requires stronger, unit-level structural assumptions, many counterfactuals are not identifiable from data without modeling and this form of reasoning typically sensitive to model misspecification and "cross-world" assumptions.
15

---

Published as a conference paper at ICLR 2026
Level
Concept
Expression
Activity
Question
Example
Would the grass be dry we found the sprinkler
Association
Secing Observing
How does seeing change my belief in y?
Ply m)
Correlation
off?
Would the grass be dry we made sure that sprinkler off?
Intervention Hypotheticals
Would happen if did x??
P(y do(x))
Doing
Would have happened instead of y if had done instead of x'?
Would the grass have been dry if the sprinkler had been off, given that the grass is wet and the sprinkler on?
III
Counterfactuals
P(ye x',8")
Imagining
What would have happened if I had done æ, given that doing x! led to y
Table 3: Definition of the causal ladder proposed by Pearl (Pearl 2009). where {z, x'} denote candidate causes, {y, 3/ denote candidate effects, and P denotes the probability of an event. Notably, Interventions and Hypotheticals are different names of the same reasoning paradigm, which only thinks about changes that lie in the future (Gerstenberg) 2022). Counterfactuals differs from them by thinking about changes that lie in the observed outcome or past.
C COUNTERFACTUAL VS INTERVENTIONAL: EXAMPLES OF GSM-BASED TASKS
Setting
GSM Problem
Answer
Counterfactual
Ravi is organizing an office lunch. Every catering tray is priced at $68. There is
$648.78
also a per-catering tray service fee. discount of 14% is applied to the items subtotal (before any fees). For 6 catering trays, the total shown is $3.3.88. If instead 11 catering trays were ordered, with all else unchanged, what amount would be shown?
Interventional
Ravi is organizing office lunch. Every catering tray is priced at $68. There is a per-catering tray service
$648.78
$0.50. discount of applied to the items subtotal (before any fees). For catering trays, the total shown is $353.88. If instead 11 catering trays were ordered, with all else unchanged, what amount would be shown?
Table Two GSM-style instances derived via the dependency -raaph approach inspired by Ye et al. (2024). The first row is counterfactual with hidden latent variable (highlighted) that must be inferred; the second row is the corresponding interventional instance with the fee (hidden latent variable) revealed.
16

---

Published as a conference paper at ICLR 2026
D COUNTERFACTUAL VS INTERVENTIONAL: PERFORMANCE ON GSM-BASED TASKS
Model
GSM-Interventional
GSM-Counterfactual
Qwen2.5-1.55
1.5555--.5BBnsstrue
18.4
9.0
40.3
22.0
Diven2.5-7B-Instuuut
60.4
39.0
Dwven.55-32B-Inssi
88.5
73.1
Dwwen.55-7BBIInstee
79.7
73.1
Llama-3.3-70B-Insiie
95.1
82.2
GPT-44 DeepScck-RI -1-asskk----iiiiie 1--isstill---Qn-33
93.1
68.6
75.3
60.7
Table 5: Performance comparison on GSM-based counterfactual and interventional tasks for various models, where the latter is still consistently and significantly higher than the former, echoing prior observation in Figure for code-based tasks.
E WHEN COUNTERFACTUALS AND INTERVENTIONALS CONFLATE
Wu et al. (2024) analyze GPT-4 under altered premises; since their tasks contain no latent variables, intervention and counterfactual queries coincide, the reported failures does not probe abductive backtracking effectively. For example one of their evaluated tasks arithmetic, switching the base from 10 9 is simply do(base = 9): 2710 + 6210 8910 but 27g 62g (100)g; state needs to be inferred. Consequently, these setups don't diagnose whether a model can perform abduction. Using Fig. [ as comparison, the base is and there is no in this example. Similar approaches are also adopted in previous works (Li et al. 2024
latent
Nguyen et al. 2024b] Paranjape et al. 2021 Joshi & He 2022; Vashishtha al.
2022; Wu al., [021] Madaan et al. 2021] Ye al.
2023). Most of these works use counterfactuals for robustness, debiasing and other purposes. They operate in fully observed settings without latent variability, where the query effectively reduces to an intervention. In contrast, our evaluation targets cases that require abduction, testing whether LLMS can execute the full Abduction Actinn-cttonn-nii Peciiinttrriiiioon rollout.
F ADDITIONAL RELATED WORK
Causality and LLMs. Recently a lot of work has focused on how effectively LLMs can be used as
domain priors for discovering causal relationship between different real world entities (Kıeıman et al.,
2023; Ban et al. 2023 Long et al. 2023 Willig et al. 2023 Vashishtha et al. 2025b). Furthermore, improving LLM'' 's causal reasoning via training on synthetic data (CoT) based methods (Jin et al., 2024). Works like Jin al. (2023 20244) underline the current limitations of language models' causal reasoning in synthetic and formal settings across different types of reasoning including counterfactual reasoning.
efforts have also focused
(Vashishtha et al. 2025 a) or by testing different
Using Counterfactuals for NLP tasks. Past work has also been focusing on improving robustness in NLP tasks such as debiasing for gender-based associations (Wu et al.) 2024; Paranjape et al. 2022
Wu al. 2021 Madaan et al. 2021 Ye et al. 2021 Joshi & He| 2022 Vashishtha al.) [2023] ), story generation (Qin et al. 2019), fictional complex reasoning (Ahuja et al. (025). and improving the efficiency of reasoning traces (Lu et al. 2025). Though intended for different purposes, these works uniformly follow simplified interpretation of counterfactual reasoning (Pearl (002b). Another line of research investigates the capabilities of LLMs in generating and evaluating counterfactuals, specifically for data augmentation. faimess enhancement, and interpretability research (Mishra et al.) 2024 Nguyen et al. 2024a). However, they focus more on the utility the generated examples for downstream tasks, instead of a truthful evaluation of counterfactual reasoning itself.
17

---

Published as a conference paper at ICLR 2026
RL vs SFT. Past studies have explored how the training paradigms of SFT and RL based training differ, which guide our training design setup. Kirk et al. (2024) shows how Reinforcement Learning from Human Feedback (RLHF). generalizes better then SFT under distribution shift from train set, however results in lack of diversity. Chhu et al. (202)) showed how RI. trained on outcome based reward generalizes better across both text and visual tasks, while SFT memorizes the task leading lack of generalization. However the work emphasises the importance of SFT before RL for effective training. [w et al. (2023) shows how standard SFT's lack of generalization is due to gradients encoding problematic reward leading to lack of generalization.
We take inspiration from cognitive science literature (Gerstenberg) 2022)
design our program- based analysis in order to evaluate the core cogmitive skills required for counterfactual inference. To build math-based generalization tests we build upon the framework Ye et al. (2024) to generate counterfactual variant of grade school level math problems following a dependency graph based approach. Past work uses programs as world models and simulations, including concept learning from programs (Lake et al. 2015) and code driven or physics based simulators (Cobbe al. 2020
Freeman et al. 2021) showing the potential graph for this, which we leverage for our work.
G META TEMPLATES:
STRUCTURAL. PLACEHOLDEE DESCRIPTION
Placeholder
What controls
Code/line type inserted
[function_net name)
Name of generated function.
Identifier used in def header (snake _aasee____ee..__
(min_r), (max_r)
Bounds for the random draw r.
Integer literals or simple expressions inside random, randint (a, b). One or more Python statements (e.g.. assignments, helper calls).
[preprocesaing_llock]
Optional setup before branching.
(condition_type)
The top-level i condition.
Boolean expression (comparisons, logical ops).
(if_braach_content)
Body when i is true.
Indented suite: one more Python statements.
bllifbblock]
Optional middle branch.
Either empty, or elif <boolean expr> indented suite. Indented suite: one more Python statements.
(else_branch_content)
Body when previous conditions are false. Value the function returns.
(retum_cxprcasioon)
Exprcssion used in return (identi- fier. arithmetic expr, tuple, etc.).
Table 6: Placeholders, roles, and expected code/line types for the if-else meta-template.
H DEDUPLICATION AND VERIFICATION OF CODE FUNCTIONS
We validate each function by executing it small, randomly generated verification set ensure runs without errors.. We also parse the code into Python's Abstract Syntax Tree (AST) to confirm that compiles without syntax emrors. For computing the similarity we convert each generated function into a structural fingerprint by counting key elements (if-statements, assignments, operators) and analyzing the overall code pattern. To analyze patterns, it walks through the code structure and identifies sequences like "preprocessing - condition check - branch calculations -> return result". then compares these fingerprints numerically: if two functions have similar counts each element type and follow the same logical flow pattern, they get high similarity score E [0, 1]. Functions with identical structure and execution sequence get a score of s = 1.0, while completely different functions near O. Based on manual analysis, we set the threshold at 0.8. This helps identify when the generation process is creating duplicate or overly similar functions that should be filtered maintain training data diversity.
18

---

Published as a conference paper at ICLR 2026
1 COUNTERFACTUAL REASONING PROMPTS FOR CODE FUNCTIONS
L1 WHILE
You language model that reasons about code without using any external execution envi- ronment. Do not simply repeat the prompt. Instead, analyze Python function below, provide step-by-step reasoning, and answer the counterfuctual question.
fyncttnuncttion
Python function:
def generated Eenc__unneeeeeeeeeeeeeeeee 96666996666066 (x,
primary_sum secendary_sum 0
counter =
while counter x: primary_sum += r counter
sccondary_sum += counter
if primary_sum secondary_sum: primary_sum 5
counter += 1
return (primary sum secondary_sume //
Observed call:
When this function called with input 10, it produced the output y 36.
Counterfactual query:
If instead of x = 10, we had called this function with different input value of x = 8 while keeping everything else unchanged, what could the output have been? Let's think step by step get the answer.
Required answer format: \boxed ansl, ans2, ans3
Table 7: Counterfactual prompt example for While dataset.
19

---

Published as a conference paper at ICLR 2026
1.2 MULTI
You are language model that reasons about code without using any external execution envi- ronment. Do not simply repeat the prompt. Instead, analyze the Python bythonfunction function below, provide step-by-step reasoning, and answer the counterfactual question.
Python function:
import random
def Sunerated_fun__1te (x, r1, r2, r3):
prep (r2 r3)
if X -- rl: result = r3
for i in range (2)
pass
result = result x r2
else:
result = r2
for i in range (6): pass
result result = x rl
result result (rl r3) return result
Observed call:
When this function called with input 16, it produced the output y 3640.
Counterfactual query:
If instead of x: 16, we had called this function with a different input value of x = 18 while keeping everything else unchanged, what could the output have been? Let's think step by step get the answer.
Required answer format: \boxed| ansl, ans2, ans3
Table 8: Counterfactual prompt example for Multi dataset
20

---

Published as a conference paper at ICLR 2026
1.3 IF ELSE-LONG
You language model that reasons about code without using any external execution envi- ronment. Do not simply repeat the prompt. Instead, analyze Python Python,function below, provide step-by-step reasoning, and answer the counterfactual question.
Python function:
def fanerrated_fun___eee (x, r):
alt4 10
final2 =
final3
final4
templ
temp2 3
temp3 2
abs (r)
if r 9:
templ (x $ 1) (r $ 10)
if (r 10) == 5:
if templ
if (temp3 x) < r:
final4 (temp3
result final4
else:
alt4 x temp3
result = alt4 +
else:
final3
temp2 +
result = final3 x
else:
final2 (templ 5)
result final2
else:
else_val val (r ** 4) x
result = eise_val +
return result
Observed call:
When this function called with input 18, it produced the output y 4.
Counterfactual query:
If instead of x = 18, we had called this function with a different input value of x. = 20 while keeping everything else unchanged, what could the output have been? Let's think step by step get the
Required answer format::
\boxed| ansl, ans2, ans3
Table 9: Counterfactual prompt example for If elseeloln dataset.
21

---

Published as a conference paper at ICLR 2026
J INTERVENTIONAL REASONING PROMPTS FOR CODE FUNCTIONS
You are language model that reasons about code without using any external execution envi- romment, Do not simply repeat the prompt. Instead, analyze the Pythonffunction function below, provide step-hy-step reasoning, and answer the interventional question.
Python function:
def @eneerate__unc_liee (x, rl, r2, r3):
prep (r2 r3)
if x rl: result = x + r2
for i in range (6) pass
result result x r1
else:
result = x r3
for in range (2)
pass
result result x r3
result - result + (rl - r2 - r3)
return result
Observed call:
When this finction was called with inputs the output = 358.
18, rı 20, r2 5, and r3 17, it produced
Interventional query:
If instead of x = 18, we had called this function with x = 20 while keeping = 20, r2 = 5. and 17 unchunged, what could the output have been? Let's 's think step by step to get the
Required answer format: \boxed (ansl, ans2, ans3)
Table 10: Interventional prompt example for Multi dataset. We omit the interventional examples of the remaining three code-based datasets, as their prompt templates are mostly similar to this one, and the examples of python functions are already displayed in Appendix
22

---

Published as a conference paper at ICLR 2026
K PROMPT TEMPLATE FOR LLM-AS-A-JUDGE ANALYSIS
You are presented with counterfactual reasoning question about code function, along with sample solution. Your lask is to carefully analyze this solution and rute how it performs in terms of planning and execution, on a scale from 1 to 5.
Criteria for rating planning:
The solution adopts perfect plan for all such counterfactual questions with two stages: (1) Backward Reasoning with Original Data: determine the value(s) of the unknown variable r by setting up a mathematical equation based on the arithmettic operations performed on r and the original input within the code path that produced the original output y. (2) Forward Reasoning with Counterfactual Data: the value(s) s) of r found in the previous step to determine the new outpu((s) based on the counterfactual input.
3 The solution shows awareness of first finding values of r from the original x and y, and then computing the new oulputs using the same but it does not follow this Backward weekward-then-eee corward plan faithfully decisively. For instance, it hesitates about solvability without an explicit resorts to brute-force enumeration without persisting the desired plan.
The solution does not align with the Backward then Forward plan at (e.g., starts with brute-force enumeration of r without using the given to determine smartly).
Criteria for rating execution:
Score execution based on whether the solution follows code-simulation paths and performs hep-by-stee numerical computations faithfully and correctly. More simulationlcomputttion mistakes + lower execution score.
Question: (prompt)
Ground Truth Answers:
(ground_ truth)
Solution:
(respense)
Required response format (JSON):
2
"planning": [112131415),
3
"pllamiin_exxplanaiion "first briefly describe the planning or strategy this solution adopts, and then explain why you gave this planning score",
4 "execution"; [21213/415],
5 "execution "exxcution__expaaatiio""" eem_eeelaaaaiin": "brief explanation of why you gave this execution score"
6
Table 11: The prompt template for au--uee analyses in with detailed evaluation rubrics for both planning and execution scores.
TRAINING AND EVALUATION DETAILS
L.1 SET TRAINING SETUPS
Reasoning Trace Generation. Our training dataset built upon 5500 code-based counterfactual reasoning prompts that only involve jf_else logic. We leverage
-iis--iiied--iueeee -itilleedd-Qw-3322--- Instruct Guo et al. (2025) to annotate the reasoning traces for these prompts through rejection sampling Li et al. (2025) Specifically, for each prompt, sample multiple responses until the model reaches the correct final answer or a budget of 8 is reached. The resulting training set achieves a final F1 score of 95.9 and exact match score of 88.9, ensuring the correctness of SFT training signals.
23

---

Published as a conference paper at ICLR 2026
Training Configurations. Throughout this work, follow prior practice Yee al. 2025) by performing full parameetrr SFT training using the LlamaFactory framework (Zheng et al. 2024). All the SFT experiments are carried out using four NVIDIA H100 GPUs, with DeepSpeed Z (Rasley et al. 2020), FlashAttention- V2 (Dao et al. 2022), and Liger Kernel (Hsu et al. 2025) enabled to improve time and memory efficiency. The key training hyperparameters shown below:
--cutoff_len 16384
--num train_epochs 2 --bf16 True --opt.im adamw_torch
=ir__shheduler_tppe cosine
-Learning_rate 5e-05
warmup__atto 0.05
-weight_decay 0.0
--per_ "per_device_tzalle batch size 4
--seed 42
L.2 RL TRAINING SETUPS
Throughout this work, we follow prior practice (Luo et al. 2025 Sun et al. 2025) by performing full-parameter RLVR training with the verl (Sheng et al., 2024) framework. We four NVIDIA H100 GPUs for training 1.5B and 3B models, and eight H100 GPUs for 7B models. We adopt an effective prompt batch size of 16. rollout batch size of 24, prompt length limit of 512, response length limit of 2000, sampling temperature of 1.0, coefficient of 10 for low-variance KL auxiliary loss, and total of 1 1500 training steps. The reward is the simple exact match score.
L.3 EVALUATION SETUPS
Dataset Statistics. The in-distribution (ID) If else evaluation dataset contains 500 examples, while the three out-of-distribution (OOD) evaluation datasets, el_elee elss--lnn,, Multi r and While, contain 480, 575 and 480 examples respectively.
Evaluation Protocol. Throughout this work, we use the vLLM framework (K et al. 2023) for efficient evaluation. Specifically, we follow prior practice (Luo et al. 2025 Guo et (025) by using sampling with temperature of 0.6, top-p of 0.95, and a maximum 16000 generated tokens to generate k = 3 responses per question. For each evaluation dataset, report the average accuracy over l responses (i.c., avg@k @rekk) k) to reduce the variance in performance statistics.
M BENCHMARKS WITH RICHER CAUSAL STRUCTURES: deetermines__r
To further enrich the diversity causal structures within our benchmark. we introduce new task type: x determines r. Unlike previous settings where latent variables are independent of the intervention variable, this task explicitly specifies dependency between and r from the onset. Specifically, the value of is sampled from a Gaussian distribution where the mean and standard deviation are computed functions of æ. This construction creates a mediator effect (a + r + y in addition to direct effect of x y.
Table 12 presents an example of function from this dataset. The implementation defines parameters and based on the input æ, and subsequently samples This dataset comprises 600 examples in the code domain.
We evaluated 1-..2.5-1..B-Instieee and Claude-3.5 3.5-oonett)))) on this new dataset. The results are presented in Table 13 We observe trend consistent with the main findings in Table I RL demonstrates superior generalization performance on this new causal structure involving dependencies between æ and r. Notably, the small RL-train trained model exceeds the performance of GPT-4o by significant margin in this setting.
its SFT and RLVR variants, and proprietary LLMs (GPT-4o
24

---

Published as a conference paper at ICLR 2026
def generated_func__pe _arpunn_______00000___ (x, seed_value) random. seed (seed_value)
min_r -50
max_r = 50
mu = x + 1.08 + 6.68
sigma max (1, abs (x) 0.08 3.47)
int (round (mu sigma random. gauss (0, 1)
= max (min_,, min (max_,, x))
if x >= 14: result (x r) *
else:
if r <= x 6:
result = (x + r) // 2
else:
result (r x)
return result if result else (r
Table 12: An example code function from the x_determinex_ dataset, where the latent variable acts as mediator dependent on T.
Model
F1
Qwen2.5-1.5B-Imss Instrucct
24.5
45.6
Swen2.5-1.5B-Insttuce
58.2
Slaude335-Soomee
85.1
GPT-4o
44.0
Table 13: Evaluation results the d_ddtenmnees___ dataset. The RL-trained model demonstrates stronger generalization to the mediator causal structure compared to SFT and GPT-4o.
N MULTI-JUDGE VALIDATION OF
ANALYSIS
To solidify the reliability of the planning and execution scores used in our analysis, we performed both human validation and multi-judge comparison to ensure the metrics reflect genuine reasoning quality rather than stylistic variance.
Specifically, we uniformly sampled 30 examples from the in-distribution task eixe) and exam- ples from the out-of-distribution task (multi r), for total of 60 examples. We independently applicd both manual human scoring and model-based scoring using Claude-4.5-Sommet, while maintaining the exact same grading rubric used for the o4-mini judge in $
calculated the Pearson correlation between each pair of the three rating subjects: (1) Human, (2) 04-mini, and (3) Claude-4.5-Sonnet. Tables a4d 15 present the correlation matrices for planning and execution scores, respectively. The consistently high correlations suggest strong alignment between human and automated judges, validating the generality and robustness of the behavioral analysis reported in $
25

---

Published as a conference paper at ICLR 2026
Table 14: Pearson correlation matrix for Plan-
Table 15: Pearson correlation matrix for Execu-
ning scores.
tion scores.
Human
04-mini
Sonnet
Human
04-mini
Sonnet
Human
1.00
0.76
0.63
Human
1.00
0.86
0.74
04-mini
0.76
1.00
0.80
04-mini
0.86
1.00
0.80
4.5-Sonnet
0.63
0.80
1.00
4.5-Sonnet
0.74
0.80
1.00
26


Reviews:
[{"review_id": "AHeUm6Cl2b", "reviewer": "Reviewer_ZkHM", "summary": "The paper investigates whether large language models (LLMs) can perform counterfactual reasoning, which requires the causal sequence of abduction, intervention, and prediction. The authors argue that existing LLM evaluations on counterfactual reasoning often overlook the abduction step, inferring hidden latent variables from factual observations, which is essential in Pearl’s framework.\n\nTo make abduction explicit and verifiable, the paper introduces a counterfactual reasoning benchmark in the form of code-based tasks. Each task corresponds to a function $Y = f(X, R_1, R_2, \\ldots)$ where $X$ is the input and $R$ represents latent variables sampled inside the function. Given factual observations $X = x$ and $Y = y$, the goal is to infer the support set of the counterfactual $Y$ had $X$ been $x’$. Experiments with open-source models (1.5B–72B) and commercial reasoning models reveal that they consistently fail at counterfactual reasoning due to an inability to perform abduction.\n\nNext, the paper studies whether fine-tuning can induce counterfactual reasoning. Two approaches are compared: Supervised Fine-Tuning (SFT) and Reinforcement Learning with Verifiable Reward (RLVR). Both methods enable strong performance on in-distribution code counterfactual tasks. However, RLVR generalizes significantly better, to functions $f$ with unseen structural patterns and to a natural language counterfactual dataset (GSM8K-style math word problems constructed from causal graphs), while SFT collapses to near-zero performance.", "questions": "**Q1**. In line 101, the paper states: “infer r based on the observation $y = -1$ (abduction).”\nShould this instead be “infer $r$ based on the observation $x = 1, y = -1$”?\nAlso, does abduction always consider both x and y as observations in this benchmark?\n\n**Q2**. See **W2**", "limitations": "", "rating": 6, "confidence": 3, "soundness": 3, "presentation": 3, "contribution": 2, "strengths": "**S1**. The paper highlights the crucial role of inferring latent variables R (abduction) in counterfactual reasoning. This step is often ignored in existing LLM counterfactual evaluations. The paper provides clear motivation and concrete illustrations for why abduction must be explicitly evaluated, and how current methods implicitly avoid it.\n\n\n**S2**. The proposed code-based benchmark is both systematic and innovative. By embedding latent randomness into executable coding functions, the authors create a counterfactual reasoning task with verifiable ground truth. The methodology can offer insights that could be extended to broader counterfactual reasoning tasks.", "weaknesses": "The definition of counterfactual reasoning used in the paper is narrower than the standard understanding in causal inference.\n\n**W1**. In Pearl’s framework, abduction requires inferring the posterior distribution $P(R \\mid x, y)$, followed by computing the counterfactual distribution $P(Y_{x'} | x, y) = \\sum_R P(Y_{x'} | r)P(r \\mid x, y)$. In contrast, the benchmark in this paper focuses on identifying the **support set** of latent variables consistent with the observation, and then predicting the **support set** of counterfactual outcomes. It is suggested to clarify that the benchmark evaluates support-set inference, not full counterfactual distributions.\n\n**W2**.\nAlthough the paper claims to move beyond graphical approaches, every task ultimately reduces to the functional form $Y = f(X, R_1, R_2, \\ldots, R_n)$, without causal dependencies between $X$ and $R$ and other observed variables. As a result, the causal graph collapses to a simple structure $X \\rightarrow Y$. Does the benchmark proposed in the work include any tasks with richer causal structures, either in the code setting or the natural language setting?", "quality": null, "clarity": null, "significance": null, "originality": null, "strengths_and_weaknesses": "", "was_revised": false, "final_justification": "", "rebuttal": "", "claims_and_evidence": "", "methods_and_evaluation_criteria": "", "theoretical_claims": "", "experimental_designs_or_analyses": "", "relation_to_broader_scientific_literature": "", "essential_references_not_discussed": "", "other_strengths_and_weaknesses": "", "other_comments_or_suggestions": "", "questions_for_authors": "", "summary_of_paper": "", "summary_of_recommendation": "", "technical_quality": "", "clarity_of_presentation": "", "potential_impact": "", "robotics_focus": "", "quality_of_limitations": "", "questions_for_rebuttal": "", "reasons_to_accept": "", "reasons_to_reject": "", "questions_to_authors": "", "extra_scores": {}}, {"review_id": "ga2uGWzcw1", "reviewer": "Reviewer_V1ez", "summary": "This paper highlights that current LLMs perform poorly in identifying counterfactuals within coding tasks. Moreover, the effectiveness of supervised fine-tuning (SFT) remains limited, as it fails to generalize to unseen scenarios. Finally, the authors demonstrate that reinforcement learning (RL) achieves strong performance and shows promising potential for generating counterfactual examples.", "questions": "Questions and Suggestions:\n1 I suggest that the authors provide additional analysis or, if possible, a theoretical guarantee to better explain and support their findings.\n2 I recommend adding a preliminary section before Section 3 to clearly define the problem and formalize the task setup.\n3 The paper would also benefit from including a discussion of previous work on counterfactual example generation. I list several relevant papers below for reference:\n1 Mishra, Ashish, Gyanaranjan Nayak, Suparna Bhattacharya, Tarun Kumar, Arpit Shah, and Martin Foltin. \"Llm-guided counterfactual data generation for fairer ai.\" In Companion Proceedings of the ACM Web Conference 2024, pp. 1538-1545. 2024.\n2 Nguyen, Van Bach, Paul Youssef, Christin Seifert, and Jörg Schlötterer. \"Llms for generating and evaluating counterfactuals: A comprehensive study.\" arXiv preprint arXiv:2405.00722 (2024).", "limitations": "", "rating": 4, "confidence": 4, "soundness": 3, "presentation": 2, "contribution": 2, "strengths": "Strength:\n1 The topic is interesting.\n2 The experiments are abundant.\n3 The introduction of the template-based generation approach is clear and concise. The inclusion of a concrete example effectively clarifies the goal of the task.", "weaknesses": "Weakness:\n1 Although this paper demonstrates the differences among algorithms in counterfactual reasoning, it fails to provide an in-depth analysis of the observed phenomena. In other words, the work reads more like an experimental report than a research paper. For instance, the authors claim that reinforcement learning (RL) exhibits strong generalization ability, yet offer no explanation or supporting analysis for this claim.\n2 The paper lacks a clear definition of counterfactual examples, which makes it difficult to understand the exact task at first. In fact, the task only becomes clear upon reading Section 3.", "quality": null, "clarity": null, "significance": null, "originality": null, "strengths_and_weaknesses": "", "was_revised": false, "final_justification": "", "rebuttal": "", "claims_and_evidence": "", "methods_and_evaluation_criteria": "", "theoretical_claims": "", "experimental_designs_or_analyses": "", "relation_to_broader_scientific_literature": "", "essential_references_not_discussed": "", "other_strengths_and_weaknesses": "", "other_comments_or_suggestions": "", "questions_for_authors": "", "summary_of_paper": "", "summary_of_recommendation": "", "technical_quality": "", "clarity_of_presentation": "", "potential_impact": "", "robotics_focus": "", "quality_of_limitations": "", "questions_for_rebuttal": "", "reasons_to_accept": "", "reasons_to_reject": "", "questions_to_authors": "", "extra_scores": {}}, {"review_id": "hgJGaQkTkx", "reviewer": "Reviewer_yTEV", "summary": "The paper proposes a new benchmark for evaluating counterfactual reasoning in large language models. By framing tasks as executable code and math problems, it tests whether models can perform the full causal reasoning cycle (abduction, intervention, and prediction). Using this setup, the authors find that LLMs, regardless of size, struggle especially with the abduction step. They introduce an LLM-as-a-judge method to rate reasoning quality in terms of planning and execution, revealing that reinforcement learning with verifiable rewards (RLVR) induces more consistent causal reasoning than supervised fine-tuning (SFT). The work provides a structured framework for diagnosing reasoning failures in LLMs.", "questions": "1. How could the proposed framework be adapted to naturalistic or real-world reasoning tasks? Any datasets/benchmarks that could be added?\n\n2. How did the authors validate the accuracy and consistency of the o4-mini LLM-as-a-judge beyond rubric standardization? Was any human–LLM agreement test or multi-judge comparison performed to confirm that planning and execution scores reflect genuine reasoning quality rather than stylistic variance?\n\n3. Any intuition about which parts of the reinforcement pipeline are responsible for the improved results, i.e., the emergence of structured reasoning?", "limitations": "", "rating": 8, "confidence": 3, "soundness": 3, "presentation": 3, "contribution": 3, "strengths": "The paper is original in defining executable counterfactuals, i.e., a new, code-based benchmark that captures causal reasoning process (abduction, intervention, prediction). The technical quality is strong, combining formal causal modeling with large-scale experiments comparing model types and training methods (SFT vs. RL).  In terms of clarity, the presentation is clear and well-structured, using intuitive examples. The significance comes from establishing a scalable framework for testing reasoning in LLMs.", "weaknesses": "The evaluation is limited to synthetic and code-based tasks, leaving unclear how the framework extends to real-world reasoning. Adding at least one natural dataset or human-grounded task would strengthen generalizability.\n\nThe LLM-as-a-judge lacks calibration against human evaluators. Without inter-rater validation or multi-judge comparison, reliability of the planning and execution scores remains uncertain.", "quality": null, "clarity": null, "significance": null, "originality": null, "strengths_and_weaknesses": "", "was_revised": false, "final_justification": "", "rebuttal": "", "claims_and_evidence": "", "methods_and_evaluation_criteria": "", "theoretical_claims": "", "experimental_designs_or_analyses": "", "relation_to_broader_scientific_literature": "", "essential_references_not_discussed": "", "other_strengths_and_weaknesses": "", "other_comments_or_suggestions": "", "questions_for_authors": "", "summary_of_paper": "", "summary_of_recommendation": "", "technical_quality": "", "clarity_of_presentation": "", "potential_impact": "", "robotics_focus": "", "quality_of_limitations": "", "questions_for_rebuttal": "", "reasons_to_accept": "", "reasons_to_reject": "", "questions_to_authors": "", "extra_scores": {}}]

Author rebuttal:

Decision: Accept (Poster)