potentialpaper

Code as Explanations: Executable and Verifiable LLM Explanations

Nhi Nguyen, Shauli Ravfogel, Rajesh Ranganath

NeurIPS 2026

Edit this page

Or clone it with git

Run in a terminal:

Needs Git LFS. To push, use an API key from your profile as the password.

Or let your agent set it up

It checks and sets up everything: signing in, git, the clone, credentials and an SSH key.

TL;DR. We propose code as a compact and executable alternative to free-text explanations, enabling direct verification of model behavior at a dataset level.

Abstract. As large language models (LLMs) increasingly make consequential decisions and solve problems alongside humans, we must understand how models arrive at their conclusions. Understanding how an LLM behaves requires observing it across multiple inputs, yet free-text explanations such as chain-of-thought (CoT) are generated per instance and cannot be easily verified on new inputs. We propose {code explanations to address the mismatch in how LLM explanations are generated versus how they are evaluated: a program explains LLM behavior across a dataset of inputs, and its execution enables automatic verification. We define Consistency metric that measures the fraction of inputs on which the program reproduces the LLM's outputs, and use it to evaluate and select candidate programs. Across three open-source code-capable LLMs and eight tasks, we find that LLMs can produce highly consistent code explanations in several settings. Code explanations are also 6$\times$ to 100$\times$ shorter than CoT, and better align with model behavior in 9 out of 24 settings. However, consistency is significantly lower on tasks with more complex linguistic components, where generated programs reproduce model outputs no more frequently than an uninformative explanation baseline, and these programs often rely on longer hard-coded patterns. In experiments with Claude Opus 5.5, providing the model with consistency feedback and code execution improves explanation consistency across tasks, but consistency remains significantly lower on more complex tasks. Our findings establish executable code as a novel, verifiable, and compact approach to explaining LLM behavior and highlight verification feedback as a promising direction for improving explanation consistency. The code for this paper is at https://github.com/rajesh-lab/code-as-explanations.

Are you an author? Claim this paper to see who's reading it, with views and other statistics, and to write about it here.

Claim this paper
How does this paper connect to your work? Write how you built on it, compared with it or reproduced it, or add a summary, a critique or errata.
Or make it interactive:
Start writing

edit · history

DateVersionSubmitted toPDFEvidence
4 May 2026NeurIPS 2026submittedNeurIPS 2026Accept (poster)reviews ↓[1]PDF[1]
Missing a version?

NeurIPS 2026

Accept (poster) · 3 reviews · OpenReview

Updated 25 Nov 2026, 03:47 UTC.

Program Chairs · DecisionOpenReview ↗
Decision
Accept (poster)
Read decision
Meta-review

The paper proposes using LLM-generated code as a compact, automatically verifiable explanation of LLM behavior, evaluated across 3 model families and 8 tasks. I have read the authors' rebuttal in full.

The rebuttal directly addressed the concerns raised in the initial review. Held-out evaluation showed the original selection procedure was not materially inflating consistency scores, and a majority-class baseline preserved the paper's main trends. The correct/incorrect consistency breakdown found no systematic tendency for programs to only explain correct predictions. The cross-model experiment showed cross-model consistency close to, and in most settings at least as high as, self-explanation consistency; while this leaves the paper's specific self-explanation framing not fully established, the authors' broader claim - that consistency evaluation is useful regardless of whether the explanation is self-generated or post-hoc - is supported by this result. The free-text comparison showed code explanations are substantially more compact (roughly 70x by character count) without consistently sacrificing sufficiency relative to free-text, directly testing the paper's central comparative claim.

Reviewer YMY7 reviewed the free-text comparison and raised their score from 3 to 4, confirming it tests the paper's central claim. Reviewer asX3 reviewed the held-out split, majority baseline, and correct/incorrect breakdown in detail and raised their score from 4 to 5, confirming these resolved their methodological concerns, including reproducibility of the hidden-state analysis. Reviewer AGBF did not respond to a direct, targeted invitation to assess the rebuttal during the discussion period; their original rating (3, Borderline reject) does not reflect the new evidence, particularly the cross-model and no-hard-code experiments that were direct responses to their questions. I am disclosing this explicitly: I have factored the substance of AGBF's original concerns into my own assessment above, but do not have their confirmation on whether the new evidence resolves them.

I recommend Accept (poster). Two of three reviewers independently reviewed the rebuttal evidence in detail and moved to accept; the rebuttal's methodological fixes (held-out evaluation, stronger baseline) are sound and corroborated, and the remaining open question - whether the paper's framing around self-explanation specifically, versus explanation more generally, is fully earned by the cross-model result - is a scoping/framing issue for the authors to address in camera-ready (e.g., tempering the self-explanation framing given the cross-model finding) rather than a basis for rejection. I encourage the authors to incorporate all rebuttal experiments (held-out evaluation, majority baseline, free-text comparison, cross-model results, correct/incorrect breakdown) into the camera-ready version, and to explicitly discuss the cross-model finding as evidence that the framework applies to post-hoc explanation broadly, not only self-explanation.

Final justification

See meta review above. In brief: the rebuttal resolved the selection-bias and weak-baseline concerns, and Reviewers YMY7 and asX3 independently confirmed the rebuttal addressed their concerns, raising scores to 4 and 5, respectively. Reviewer AGBF did not respond to confirm or dispute the new evidence relevant to their specific concerns (cross-model, hard-coding); I have weighed this evidence myself and consider it sufficient to support acceptance, with the self-explanation framing flagged as a camera-ready revision point rather than a blocking issue. Recommending Accept (poster).

Area Chair w6Ae · Meta-reviewOpenReview ↗
Read meta-review
Meta-review

The paper proposes using LLM-generated code as a compact, automatically verifiable explanation of LLM behavior, evaluated across 3 model families and 8 tasks. I have read the authors' rebuttal in full.

The rebuttal directly addressed the concerns raised in the initial review. Held-out evaluation showed the original selection procedure was not materially inflating consistency scores, and a majority-class baseline preserved the paper's main trends. The correct/incorrect consistency breakdown found no systematic tendency for programs to only explain correct predictions. The cross-model experiment showed cross-model consistency close to, and in most settings at least as high as, self-explanation consistency; while this leaves the paper's specific self-explanation framing not fully established, the authors' broader claim - that consistency evaluation is useful regardless of whether the explanation is self-generated or post-hoc - is supported by this result. The free-text comparison showed code explanations are substantially more compact (roughly 70x by character count) without consistently sacrificing sufficiency relative to free-text, directly testing the paper's central comparative claim.

Reviewer YMY7 reviewed the free-text comparison and raised their score from 3 to 4, confirming it tests the paper's central claim. Reviewer asX3 reviewed the held-out split, majority baseline, and correct/incorrect breakdown in detail and raised their score from 4 to 5, confirming these resolved their methodological concerns, including reproducibility of the hidden-state analysis. Reviewer AGBF did not respond to a direct, targeted invitation to assess the rebuttal during the discussion period; their original rating (3, Borderline reject) does not reflect the new evidence, particularly the cross-model and no-hard-code experiments that were direct responses to their questions. I am disclosing this explicitly: I have factored the substance of AGBF's original concerns into my own assessment above, but do not have their confirmation on whether the new evidence resolves them.

I recommend Accept (poster). Two of three reviewers independently reviewed the rebuttal evidence in detail and moved to accept; the rebuttal's methodological fixes (held-out evaluation, stronger baseline) are sound and corroborated, and the remaining open question - whether the paper's framing around self-explanation specifically, versus explanation more generally, is fully earned by the cross-model result - is a scoping/framing issue for the authors to address in camera-ready (e.g., tempering the self-explanation framing given the cross-model finding) rather than a basis for rejection. I encourage the authors to incorporate all rebuttal experiments (held-out evaluation, majority baseline, free-text comparison, cross-model results, correct/incorrect breakdown) into the camera-ready version, and to explicitly discuss the cross-model finding as evidence that the framework applies to post-hoc explanation broadly, not only self-explanation.

Final justification

See meta review above. In brief: the rebuttal resolved the selection-bias and weak-baseline concerns, and Reviewers YMY7 and asX3 independently confirmed the rebuttal addressed their concerns, raising scores to 4 and 5, respectively. Reviewer AGBF did not respond to confirm or dispute the new evidence relevant to their specific concerns (cross-model, hard-coding); I have weighed this evidence myself and consider it sufficient to support acceptance, with the self-explanation framing flagged as a camera-ready revision point rather than a blocking issue. Recommending Accept (poster).

1 comment
Authors · CommentOpenReview ↗

We thank the AC for your detailed meta-review. We appreciate your summary of the paper’s strengths and the specific analyses that would strengthen the work. We performed all three requested experiments, and the results support our original conclusions.

Held-out evaluation. We perform program selection and evaluation using disjoint dataset splits instead of on the same dataset. The held-out results change only modestly and preserve all main conclusions on consistency trends. We will adopt this selection and evaluation procedure in the revised paper (asX3, AGBF).

Comparison to free-text explanations. We compare code explanations with collections of chains of thoughts across entire datasets by adapting our consistency metric to be comparable with self-consistency sufficiency. Code explanations are, on average, 70x shorter at the dataset level, but neither explanation type consistently outperforms the other in sufficiency. We will include this as a main experiment and highlight improving code consistency as an important future research direction (YMY7, AGBF).

Self-explanation vs task induction. We report consistency separately on correct and incorrect predictions and do not find a systematic tendency for programs to explain only correct outputs. We also included cross-model explanation experiments and show that our framework extends to post-hoc explanations generated by another model (YMY7, AGBF).

On compactness, we will clarify that long, hard-coded programs on complex tasks are a limitation of the current code generation method, not of executable explanations as a framework, and improving code consistency remains an important future direction (asX3, AGBF). We also include an ablation on the number of in-context examples, which does not change the main conclusions (AGBF).

We hope these additional analyses and planned revisions address your concerns, and we appreciate your consideration.

Reviewer AGBFOpenReview ↗
Rating
3/6
Confidence
3/5
Quality
2/4
Clarity
3/4
Significance
2/4
Originality
2/4
Contribution type
general
Ethical concerns
NO or VERY MINOR ethics concerns only
Read review
Summary

This paper proposes using executable code (Python programs) as an alternative to free-text explanations for understanding LLM behavior. The key idea is that code explanations are executable and can be automatically verified against model outputs, unlike free-text explanations which require perturbation-based evaluation. The authors introduce a "code explanation consistency" metric (fraction of dataset examples where the program's output matches the model's output), a best-of-100 generation procedure, and study when three open-source LLMs (Gemma3-27B, Qwen2.5-Coder-32B, Llama3.1-70B) can produce consistent code explanations across eight BBH tasks of varying linguistic complexity. Main findings: (1) high consistency is achievable in 6/24 model-task settings but is not the norm; (2) tasks with complex linguistic components are harder; (3) hard-task programs degenerate into lookup tables rather than compact algorithms; (4) model-internal representations do not predict whether code explanations will be consistent.

Strengths and weaknesses

Strengths

  1. The formalization in Section 3 is precise. The consistency metric (Eq. 4) is simple, interpretable, and well-motivated. The normalized version (CONSISTENCY_OVER_RANDOM, Eq. 5) enables cross-task comparison. The generation procedure (Algorithm 1) is straightforward and reproducible.
  2. The four-category grouping (structured logic → logic + simple language → logic + complex language → linguistic reasoning) creates a natural difficulty gradient that produces interpretable results. The finding that consistency degrades along this axis is clean and informative.
  3. Probing whether models "know" when they can produce consistent explanations is exactly the kind of meta-cognitive question the explainability community needs to investigate. The negative result (R² < 0 for all models) is informative, suggesting self-generated explanations lack reliable confidence signals.
  4. The idea of using code as an explanation medium is genuinely insightful.

Weakness

  1. The paper's results are almost tautological: code works as an "explanation" for tasks that are already algorithmic (Navigate = followdirection instructions), and fails for tasks that require actual language understanding. This is not a novel insight. If the code uses hardcoded linguistic patterns (which is what they observe) — it's not an explanation, it's a lookup table. It doesn't generalize and tells you nothing about how the model processes language.
  2. The motivation of the paper is not clear. Why we need dataset level explanation, and what is the benefit of them if we cannot gurantee consistency?
  3. One of the three claimed advantages of code over free-text is "potential compactness" and the ability to provide "compact, human-understandable" explanations, However this is not evaluated properly.
  4. The generation procedure (Algorithm 1) samples 100 candidate programs and selects the one with the highest consistency on the full dataset D. This is best-of-100 selection evaluated on the same data used for selection—there is no held-out evaluation. The reported "max consistency" numbers are optimistically biased.
  5. The paper argues code is better than free-text, but never directly compares. For the same tasks, how faithful are free-text CoT explanations? If free-text is equally (un)faithful, the advantage of code reduces to ease-of-evaluation only.
  6. The paper studies self-explanation (model explains itself). What happens if Model A generates code to explain Model B's behavior? If a different model can explain the behavior equally well (or poorly), it suggests the code explanations are behavioral imitation rather than introspective self-knowledge.
Questions
  1. Have you tried having Model A explain Model B's behaviour? If cross-model explanations are equally (in)consistent, it suggests the difficulty is in program synthesis from examples, not in self-knowledge.
  2. The generation procedure (Algorithm 1) samples 100 candidate programs and selects the one with the highest consistency on the full dataset D. This is best-of-100 selection evaluated on the same data used for selection—there is no held-out evaluation. Doesn't the "max consistency" numbers are optimistically biased?
  3. What happens if you explicitly instruct the model NOT to hardcode input patterns? Does consistency drop, or do models find more general solutions?
Limitations

Yes

Formatting concerns

No concern

1 comment
Authors · RebuttalOpenReview ↗
Rebuttal

We thank the reviewer for the constructive feedback and positive assessment of our formalization, consistency metric, and motivation for studying code explanations. We agree that the paper should better clarify the scope of our claims and further evaluate the practical advantages and limitations of code explanations. We address each concern below.


Code consistency across tasks may appear expected

We agree that it may be intuitive for code explanations to succeed on algorithmic tasks while struggling on complex linguistic tasks. However, because LLMs themselves are programs that can perform complex linguistic tasks, it remains an open question whether they can also generate interpretable programs that consistently capture their behavior in the same tasks. Our empirical evaluation is therefore necessary to answer this question.

We also agree that hard-coded programs are not desirable explanations. However, our main contribution is not a superior explanation generation method, but the introduction of executable explanations as a new direction with two key advantages: compact dataset-level explanations and automatic verification. A single code explanation can explain an entire dataset, while automatic verification enables both the consistency evaluation proposed in this paper and future optimization of explanations, for example, by using consistency feedback and LLM agents to iteratively refine and improve code explanations.

We will clarify this motivation in the revised paper and better position our work as an initial step toward automatically verifiable and compact dataset-level explanations.


Motivation for dataset-level explanations

We agree that consistency, or whether an explanation accurately reflects the model’s internal computation, is the primary requirement for useful explanations, whether instance-level or dataset-level. However, prior work has shown that evaluating whether an explanation reflects a model’s computation necessarily requires assessing the model’s behavior over a distribution of inputs [1], typically through input perturbations [2,3]. This motivates us to study dataset-level explanations directly, as their goal is to capture model behavior over an input distribution, which is already required to assess the explanation’s alignment with the model’s internal computations. While our paper briefly discusses the role of input distributions in evaluating instance-wise explanations, we did not clearly articulate it as the motivation for studying dataset-level explanations. We will revise the paper to make this motivation more explicit.


Comparison with free-text explanations

New experiments: Following your suggestion, we directly compare the faithfulness of code and CoT explanations to the underlying computation in the model. To quantify CoT faithfulness, we use self-consistency sufficiency (SCSuff) [1], which measures whether an explanation sufficiently captures a model’s behavior by having the model generate alternative inputs consistent with the explanation and comparing the resulting output distribution with the original one. To enable direct comparison, we construct the code explanation’s output distribution by assigning 99% probability to its predicted answer and replace the fuzzy-matching score in Eq. (4) with the expected KL divergence used in SCSuff. This allows us to preserve automatic verification for code. Additionally, we quantify the compactness of each explanation type by comparing the token and character counts of the best code explanation with the corresponding aggregate token and character counts of the collection of chains of thought, similar to Section 5.2.

We evaluate four tasks spanning different complexity levels. Table 1 shows that, on average, code explanations are 70x more compact than free-text explanations when explaining dataset-level behaviors. However, neither code nor free-text explanations consistently outperform the other in sufficiency. As we discussed above, however, our goal is not to replace free-text explanations, but to introduce code explanations as a new explanation direction with unique advantages in compactness and automatic verification. These results suggest that there is substantial room for improving code explanation while preserving its compactness advantage.

We agree that this comparison is important and will include it as a main experiment in the revised paper.

Table 1: Code vs. Free-text explanations

Model Task Code # char Code # token Code Suff Text # char Text # token Text Suff
Gemma Navigate 3201 709 0.767 129480 38212 0.815
Qwen 2511 498 0.695 169233 42597 0.322
Llama 2004 438 0.868 200709 50702 0.098
Gemma Hyperbaton 2345 701 0.853 178313 50516 0.901
Qwen 2364 657 0.787 200977 52673 0.431
Llama 2531 610 0.621 200017 50866 0.664
Gemma Disambiguation QA 1201 350 0.867 38626 8831 0.527
Qwen 4585 1166 0.646 245296 55148 0.460
Llama 1194 312 0.328 193526 42813 0.746
Gemma Snarks 5824 1440 0.621 134035 28840 0.713
Qwen 1212 290 0.594 144229 29560 0.288
Llama 2430 610 0.472 143702 29668 0.811

Evaluate consistency on held-out split

We agree with the reviewer that selecting the best code explanation and evaluating it on the same dataset could inflate the reported consistency. To verify whether this affects our conclusions, we repeat the program selection and evaluation using a held-out split. Specifically, we split each dataset in half, select the most consistent code explanation using the first half, and evaluate its consistency on the second half. Table 1 compares the held-out consistency compared with the originally reported consistency.

The held-out consistency results in only modest changes, ranging from -0.14 to 0.04. In addition, 15 of the 24 model-task settings select the same code explanation originally selected in the paper. Importantly, all of our main conclusions remain unchanged, including the overall level of code consistency, the relationship between task complexity and explanation consistency, and the decrease in the compactness of the selected program as task complexity increases.

Although the held-out evaluation does not change our conclusions, we agree that it provides a more accurate estimate of code consistency. We will update Algorithm 1 and recompute all experimental results using this held-out selection and evaluation procedure.

Table 2: Held-out consistency

Model Task Original consistency Held-out consistency
Gemma Web of lies 0.996 0.992
Qwen 0.924 0.936
Llama 0.468 0.504
Gemma Navigate 0.744 0.776
Qwen 0.660 0.704
Llama 0.863 0.895
Gemma Hyperbaton 0.844 0.800
Qwen 0.768 0.760
Llama 0.573 0.520
Gemma Object counting 0.748 0.768
Qwen 0.274 0.266
Llama 0.784 0.760
Gemma Formal fallacies 0.544 0.456
Qwen 0.556 0.552
Llama 0.540 0.552
Gemma Disambiguation QA 0.888 0.880
Qwen 0.585 0.581
Llama 0.407 0.342
Gemma Snarks 0.579 0.528
Qwen 0.539 0.543
Llama 0.548 0.407
Gemma Translation error 0.202 0.122
Qwen 0.376 0.408
Llama 0.398 0.352

Cross-model explanations

Although our framework is motivated by LLM self-explanations, it also applies to post-hoc explanations generated by another model. Following the reviewer’s suggestion, we perform cross-model explanation experiments using Gemma and Qwen to explain each other (Table 3). Cross-model explanations achieve similar consistency to self-explanations, with the largest difference being 0.06. These results suggest that automatic consistency evaluation enables selecting post-hoc explanations that are most consistent with a model’s behavior without requiring privileged access to the model’s internal computation.

We will include this experiment in the revised paper and clarify that our framework is applicable to both self-explanations and post-hoc/cross-model explanations.

Table 3: Consistency with cross-model explanations

Model Task Self-explanation Cross-model explanation
Gemma Web of lies 0.996 0.996
Qwen 0.924 0.924
Gemma Navigate 0.744 0.752
Qwen 0.660 0.720
Gemma Hyperbaton 0.844 0.740
Qwen 0.768 0.820
Gemma Object counting 0.748 0.644
Qwen 0.274 0.274
Gemma Formal fallacies 0.544 0.580
Qwen 0.556 0.572
Gemma Disambiguation QA 0.888 0.868
Qwen 0.585 0.597
Gemma Snarks 0.579 0.562
Qwen 0.539 0.539
Gemma Translation error 0.202 0.307
Qwen 0.376 0.396

Instruct model not to hard code

Following the reviewer’s suggestion, we add the instruction: "Infer the underlying algorithm rather than memorizing or hardcoding the examples. Your solution should generalize to unseen inputs." We evaluate this prompt across the four complex tasks (Table 4). The added instruction does not systematically improve consistency. The largest gain (+0.14 on Gemma-Translation Error) comes from additional phrase-level mappings rather than a more general algorithm, suggesting that prompt engineering alone is insufficient to reduce hard-coding. Further work is needed to optimize code consistency and reduce hard-coding in code explanations on complex tasks.

Table 4: Instruct model not to hard code

Model Task Original prompt No-hard-code prompt
Gemma Formal fallacies 0.544 0.552
Qwen 0.556 0.564
Llama 0.540 0.524
Gemma Disambiguation QA 0.888 0.872
Qwen 0.585 0.548
Llama 0.407 0.378
Gemma Snarks 0.579 0.573
Qwen 0.539 0.590
Llama 0.548 0.554
Gemma Translation error 0.202 0.342
Qwen 0.376 0.376
Llama 0.398 0.281

References

[1] https://arxiv.org/abs/2606.28615

[2] https://dl.acm.org/doi/10.5555/3666122.3669397

[3] https://arxiv.org/abs/2505.05410


Once again, we thank the reviewer for their constructive feedback and believe these additional analyses clarify the strengths and limitations of code explanations and strengthen the paper as an initial step towards automatically verifiable and compact dataset-level explanations.

Reviewer asX3OpenReview ↗
Rating
5/6
Confidence
4/5
Quality
2/4
Clarity
2/4
Significance
3/4
Originality
3/4
Contribution type
general
Ethical concerns
NO or VERY MINOR ethics concerns only
Read review
Summary

This paper measure whether language models can explain their behavior by generating Python programs that reproduce their answers. Across three models and eight reasoning tasks, the authors find that these programs can closely match model behavior on some structured tasks, but often fall back on shortcuts, memorized examples, or weak heuristics for language-heavy tasks. Overall, executable code provides a concrete way to test explanations, while revealing that current models can produce reliable behavioral explanations only in limited settings.

Strengths and weaknesses

Strength:

One of the strength in this paper is turning explanations into executable programs, making behavioral agreement directly testable rather than subjective. Its evaluation covers three models, eight tasks, and many generated programs, while clearly separating task accuracy from fidelity to the model. The figures and complete appendix programs are especially valuable because they transparently reveal a meaningful spectrum, from reusable algorithms to shortcuts and memorization, highlighting some of the successes and failures as good contribution.

Weaknesses:

  • The metric does not establish truthful reasoning. Code consistency measures whether a program reproduces the model’s outputs, not whether it represents the internal process that produced them.
  • The reported scores are not clean estimates. Programs are generated from examples in the dataset, evaluated on the full dataset, and the best of 100 is selected using those same results. This can reward memorization and make the strongest results appear more reliable than they would be on new inputs.
  • The evaluation lacks sufficiently strong baselines. Because the current baseline assumes uniformly distributed model outputs, it does not determine whether the generated programs capture meaningful behavior beyond majority prediction or demonstration memorization. This makes the reported consistency improvements difficult to interpret.
Questions

What exactly is the experimental unit in the hidden-state analysis? Please clarify the number of unique prompts and hidden-state vectors, whether repeated versions of the same prompt can appear in different cross-validation folds, and how ridge regularization and feature scaling were selected.

What evidence shows that this is self-explanation rather than ordinary task induction? Using existing predictions, please report consistency separately when the target model is correct and incorrect.

Limitations

Not completely. The limitations should acknowledge evaluation overlap and selection bias, weak baselines, the absence of self vs external controls, and that behavioral agreement does not establish truthful internal reasoning. The authors should also mention the narrow task/probe scope and the risks of executing or overtrusting the generated code.

Final justification

The held-out selection/evaluation split, majority-class baseline, and correct-versus-incorrect consistency analysis directly address my main methodological concerns, while the additional hidden-state details resolve my reproducibility question. I have raised my score accordingly.

Formatting concerns

N/A

1 comment
Authors · RebuttalOpenReview ↗
Rebuttal

We thank the reviewer for their feedback and positive assessment of our framework, experiments, and analysis. We address your concerns below, and will incorporate the suggested clarifications and additional experiments in the revised version.


Truthfulness vs. Consistency

The reviewer correctly points out that code consistency does not guarantee that a program truthfully reflects a model’s internal reasoning. This is not a claim we intended to make. Throughout the paper, we evaluate the behavioral consistency between code explanations and the original LLM, and do not claim that such consistency guarantees truthfulness to the model’s reasoning. However, behavioral consistency is an important prerequisite for truthful reasoning, especially in black-box settings where we cannot directly access model internals [1].

We agree that the title could be interpreted more broadly than intended, and will revise it to remove the word “truthfully” to better reflect the scope of our paper.


Evaluate consistency on held-out split

We agree with the reviewer that selecting the best code explanation and evaluating it on the same dataset could inflate the reported consistency. To verify whether this affects our conclusions, we repeat the program selection and evaluation using a held-out split. Specifically, we split each dataset in half, select the most consistent code explanation using the first half, and evaluate its consistency on the second half. Table 1 compares the held-out consistency compared with the originally reported consistency.

The held-out consistency results in only modest changes. The maximum decrease in consistency is 0.14, while most differences range between -0.09 and 0.04. In addition, 15 of the 24 model-task settings select the same code explanation originally selected in the paper. Most importantly, all of our main conclusions remain unchanged, including the overall level of code consistency, the relationship between task complexity and explanation consistency, and the decrease in the compactness of the selected program as task complexity increases.

Although the held-out evaluation does not change our conclusions, we agree that it provides a more accurate estimate of code consistency. Thus, in the revised version, we will update Algorithm 1 and recompute all experimental results using this held-out selection and evaluation procedure.

Table 1: Held-out consistency

Model Task Original consistency Held-out consistency
Gemma Web of lies 0.996 0.992
Qwen 0.924 0.936
Llama 0.468 0.504
Gemma Navigate 0.744 0.776
Qwen 0.660 0.704
Llama 0.863 0.895
Gemma Hyperbaton 0.844 0.800
Qwen 0.768 0.760
Llama 0.573 0.520
Gemma Object counting 0.748 0.768
Qwen 0.274 0.266
Llama 0.784 0.760
Gemma Formal fallacies 0.544 0.456
Qwen 0.556 0.552
Llama 0.540 0.552
Gemma Disambiguation QA 0.888 0.880
Qwen 0.585 0.581
Llama 0.407 0.342
Gemma Snarks 0.579 0.528
Qwen 0.539 0.543
Llama 0.548 0.407
Gemma Translation error 0.202 0.122
Qwen 0.376 0.408
Llama 0.398 0.352

Self-explanation vs. Task induction

The reviewer raises an important point that generated programs might simply solve the task instead of explaining the LLM. In Figure 2, we report task accuracy alongside code consistency to show that consistency is not determined solely by accuracy; for example, Llama on Web of lies achieves high accuracy but low consistency, whereas Gemma on Disambiguation QA shows the opposite phenomenon.

Following the reviewer’s suggestion, we also report consistency separately on examples where the LLM is correct and incorrect (Table 2). We observe no systematic tendency for the selected code explanations to only explain the model's correct predictions. About half of the settings have higher consistency on incorrect examples, while the other half have higher consistency on correct examples.

There are four settings where consistency on incorrect examples is zero. However, only one of these cases also achieves perfect consistency on correct examples. Furthermore, all four cases are settings with high task accuracy (> 0.92), which suggests a possible alternative interpretation: the generated program captures the model’s behavior on the vast majority of the examples where the model performs the task correctly, but fails to capture the rare cases when the model makes mistakes.

Nevertheless, these cases represent 16% of the experimental settings, suggesting that stratified consistency is a useful diagnostic measure for whether the selected program is simply solving the task instead of explaining the target model. Thus, we plan to report these metrics in the paper, and discuss incorporating them as a penalty in the program selection procedure to discourage explanations that only explain the model’s correct predictions.

Table 2: Consistency on examples where the LLM is correct/incorrect

Model Task Consistency on correct examples Consistency on incorrect examples
Gemma Web of lies 1.000 0.983
Qwen 1.000 0.000
Llama 0.490 0.000
Gemma Navigate 0.751 0.556
Qwen 0.635 0.857
Llama 0.884 0.813
Gemma Hyperbaton 0.845 0.800
Qwen 0.780 0.444
Llama 0.571 0.578
Gemma Object counting 0.773 0.000
Qwen 0.262 0.279
Llama 0.817 0.000
Gemma Formal fallacies 0.535 0.595
Qwen 0.551 0.583
Llama 0.536 0.581
Gemma Disambiguation QA 0.896 0.884
Qwen 0.592 0.582
Llama 0.333 0.444
Gemma Snarks 0.556 0.720
Qwen 0.556 0.488
Llama 0.576 0.481
Gemma Translation error 0.209 0.200
Qwen 0.314 0.506
Llama 0.373 0.408

Uniform random vs Majority-class baseline

We thank the reviewer for suggesting the majority-class baseline and agree that it is a stronger baseline than uniform random. We computed the majority-class baseline for every model-task setting and reevaluated our analyses using consistency over majority baseline (Table 3).

The majority baseline is noticeably stronger than the uniform random baseline for some tasks, particularly Navigate (+0.10) and Translation error (+0.14). One exception reported in the paper (lines 223-226) also changes: Gemma on Disambiguation QA is no longer highly consistent under this stronger baseline. Importantly, however, our main conclusions remain unchanged: For the first four (simpler) tasks, at least one model still achieves more than 25% improvement over the baseline, whereas for all four more complex tasks, all models remain below 25% improvement. Thus, the overall consistency trends reported in the paper are unchanged.

Since the majority-class baseline is stronger and tailored to each model’s output distribution, we will replace the uniform random baseline with the majority-class baseline throughout the revised paper.

Table 3: Majority-class baseline

Model Task # Output Majority answer proportion Consistency over majority baseline
Gemma Web of lies 2 0.508 0.488
Qwen 0.524 0.400
Llama 0.532 -0.064
Gemma Navigate 2 0.616 0.128
Qwen 0.660 0.000
Llama 0.605 0.258
Gemma Hyperbaton 2 0.536 0.308
Qwen 0.512 0.256
Llama 0.573 0.000
Gemma Object counting 17 0.104 0.644
Qwen 0.101 0.173
Llama 0.104 0.680
Gemma Formal fallacies 2 0.528 0.016
Qwen 0.556 0.000
Llama 0.520 0.020
Gemma Disambiguation QA 3 0.868 0.020
Qwen 0.536 0.048
Llama 0.407 0.000
Gemma Snarks 2 0.511 0.067
Qwen 0.534 0.006
Llama 0.542 0.006
Gemma Translation error 6 0.307 -0.105
Qwen 0.376 0.000
Llama 0.237 0.161

Hidden-state analysis experimental details

In Figure 4, each data point corresponds to a last-token hidden state of a prompt used to generate code explanations (step 3 of Algorithm 1). We construct P=10P = 10 prompts for each of the eight datasets, resulting in 80 hidden-state vectors for each model. For each prompt, we sample M=10M = 10 programs and assign the best consistency score to the data point corresponding to that prompt. The first and second rows of Figure 4 visualize the same hidden-state vectors, only differing in whether the targets/colors are Consistency or Consistency over baseline. Each column corresponds to a different model, so no prompt appears across multiple columns. The ridge regression experiments use standard 5-fold cross-validation with random fold assignment, default StandardScaler from the scikit-learn library, and Ridge(alpha=1.0).

We will add these implementation details to the paper to improve reproducibility and clarify the interpretation of the analysis.


References

[1] https://aclanthology.org/2024.acl-long.329/


We thank the reviewer again for the constructive feedback and believe these additional analyses strengthen the paper’s methodology and empirical evaluation.

Reviewer YMY7OpenReview ↗
Rating
4/6
Confidence
3/5
Quality
2/4
Clarity
3/4
Significance
3/4
Originality
3/4
Contribution type
general
Ethical concerns
NO or VERY MINOR ethics concerns only
Read review
Summary

Motivated by the limitations of LLM-generated free-text explanations to be instance-wise and non-executable, this work proposes using LLM-generated code as explanations, which are executable and can be applied at the dataset level. The authors introduce a consistency metric that measures how often a program reproduces the model's outputs, along with a framework that samples multiple candidate programs and selects the most consistent one. Results show that LLMs can produce highly consistent code explanations only for certain tasks, with performance degrading on linguistically more complex tasks. The authors further explore whether model-internal representations encode when a consistent code explanation will be produced, but find that they do not.

Strengths and weaknesses

Strengths

This work proposes using LLM-generated code as explanations instead of free-text, motivated by the fact that code is executable and can be directly verified against model outputs at both the instance and dataset level. The proposed idea is well motivated and addresses current research gaps. They introduce CONSISTENCY, a metric measuring how often a generated program reproduces the model's outputs over a dataset, they also run comprehensive experiments across three model families and eight tasks of varying linguistic complexity, evaluates code explanation consistency systematically.

Weaknesses

The proposed angle is novel and well-motivated, but most experiments demonstrate when code explanations fail rather than demonstrate their usefulness. Two of four research questions get negative or weak answers: "strong consistency is not the norm", "only a partial positive answer to Q1" (L214–215), and hidden states give a "negative answer to Q4" (L273–274). So the framing promises more than the evidence supports. Negative results are valuable, and more specifically:

  1. No free-text baseline. The paper repeatedly claims code is "at least as capable as free-text explanations" (L122; Section 3.1), yet never compares the two empirically. How do free-text explanations perform on the tasks where code fails? Even a comparison on a task subset, or using another faithfulness metric, would substantiate this central claim, which is currently asserted but not tested.

  2. Limited practical value. For Q1, code explanations are consistent mainly on simpler tasks, but likely free-text (e.g., CoT) is already sufficient. Meanwhile, compactness is claimed as a advantage, yet Section 5.2 shows programs become less compact and rely on hard-coding on complex tasks. This weakens the usefulness of the code explanations.

  3. Shallow analysis of the failures. The two proposed causes (L256–260) for Q3 are stated but not investigated. A case study correlating code generations with task characteristics would turn diagnostic observations into actionable insight, like identifying recurring failure patterns such as missing hierarchical/abstracted structures.

  4. The abstract, intro, and conclusion repeatedly state the findings, these could be shortened for some sections.

Questions

Q1. Regarding the two possible explanations for low consistency on complex tasks (L61–63, L286–288, L297-301): do the authors have any arguments supporting each, or preference about which is more likely? Is there any preliminary evidence pointing toward one over the other?

Q2. Why is the generated code framed as a "sparse program" (L91–93)? The rest of the paper makes no further claims about sparse vs. dense computation, and this part of the related work seems only weakly connected to the main text. Could the authors clarify why are the codes "sparse" and how the sparse-program framing relates to the main text?

Q3. There is no analysis or justification for the chosen hyperparameters (P = 10 example sets, N = 20 in-context examples, M = 10 explanations per set; L196–197). N in particular seems important, since the number of in-context examples could directly affect both generalization and the tendency to hard-code. Was N = 20 chosen for a specific reason, and could the authors provide an ablation showing how consistency varies with N and maybe other hyperparameters?

Q4. Tasks are grouped by linguistic complexity (L192), but how is this complexity actually measured? If the grouping is assigned subjectively rather than via a systematic metric, the answer to (Q2) becomes unstable: the observed drop in consistency may not stem from linguistic complexity, but from other characteristics of the specific tasks or datasets. Could the authors clarify the criteria used, or provide an objective complexity measure to support this?

Limitations

Yes

Final justification

The rebuttal addressed my main concerns. The new comparison against free-text explanations tests the paper's central claim, and the other clarifications resolve my remaining questions. I raise my score from 3 to 4.

Formatting concerns

No

2 comments
Authors · RebuttalOpenReview ↗
Rebuttal

We thank the reviewer for the positive assessment of our motivation and evaluation. We agree that the paper should better establish the advantages of code explanations empirically and clarify the scope of our conclusions. We address each concern below.


Comparison with free-text explanations

We agree with the reviewer that an empirical comparison between code and free-text explanations would strengthen the paper.

New experiments: Following your suggestion, we directly compare the faithfulness of code and CoT explanations to the underlying computation in the model. To quantify CoT faithfulness, we use self-consistency sufficiency (SCSuff) [1], which measures whether an explanation sufficiently captures a model’s behavior by having the model generate alternative inputs consistent with the explanation and comparing the resulting output distribution with the original one. To enable direct comparison, we adapt our code consistency metric by constructing the code explanation’s output distribution by assigning 99% probability to its predicted answer, and replacing the fuzzy-matching score in Equation (4) with an expected KL divergence used in SCSuff. This allows direct comparison between code and free-text explanations while preserving automatic verification for code. Additionally, we quantify the compactness of each explanation type by comparing the token and character counts of the best code explanation with the corresponding aggregate token and character counts of the collection of chains of thought, similar to Section 5.2.

We evaluate four tasks spanning different complexity levels (Navigate, Hyperbaton, Disambiguation QA, and Snarks). Table 1 shows that, on average, code explanations are 70x more compact than free-text explanations when explaining dataset-level behaviors. However, neither code nor free-text explanations consistently outperform the other in sufficiency: code explanations achieve higher sufficiency in exactly half of the settings. As we will discuss next, however, our goal is not to replace free-text explanations, but to introduce code explanations as a new explanation direction with unique advantages in compactness and automatic verification. These results suggest that there is substantial room for improving code explanation generation while preserving its compactness advantage.

We agree that this comparison is important and will include it as a main experiment in the revised paper. We will include results on all tasks, a description of SCSuff and the corresponding adaptation of code consistency, and a broader discussion of the practical strengths and limitations of code explanations.

Table 1: Code vs. Free-text explanations

Model Task Code # char Code # token Code Suff Text # char Text # token Text Suff
Gemma Navigate 3201 709 0.767 129480 38212 0.815
Qwen 2511 498 0.695 169233 42597 0.322
Llama 2004 438 0.868 200709 50702 0.098
Gemma Hyperbaton 2345 701 0.853 178313 50516 0.901
Qwen 2364 657 0.787 200977 52673 0.431
Llama 2531 610 0.621 200017 50866 0.664
Gemma Disambiguation QA 1201 350 0.867 38626 8831 0.527
Qwen 4585 1166 0.646 245296 55148 0.460
Llama 1194 312 0.328 193526 42813 0.746
Gemma Snarks 5824 1440 0.621 134035 28840 0.713
Qwen 1212 290 0.594 144229 29560 0.288
Llama 2430 610 0.472 143702 29668 0.811

Practical values of code explanations

The reviewer notes that code explanations succeed mainly on simpler tasks, where free-text explanations may already suffice. Our new comparison above shows that while chain-of-thought explanations do not dominate code explanations over all simpler tasks, they can be more sufficient than our code explanations in several settings.

Our main contribution, however, is not to propose a drop-in replacement for free-text explanations. Rather, we introduce executable explanations as a new direction with two key advantages: compact dataset-level explanations and automatic verification. A single code explanation can explain an entire dataset, making it significantly more compact than sample-level free-text explanations, as shown in Table 1. Moreover, automatic verification enables both the consistency evaluation proposed in this paper and future optimization of explanations, for example, by using consistency feedback and LLM agents to iteratively refine and improve code explanations. Such optimization approaches are difficult for free-text explanations as they are not easily verifiable.

We will clarify this motivation for introducing code explanations in the revised paper and better position our negative findings as identifying opportunities for improving LLM explanations in future research.


Low consistency analysis and task complexity

We agree with the reviewer that a deeper taxonomy of when code explanations succeed or fail would improve the practical value of the paper. Our grouping by linguistic complexity is intended as a preliminary exploration, and the tasks were grouped before any consistency analysis using subjective intuitions about which steps are involved in solving each task. We agree that a more systematic complexity measure would provide stronger evidence for the relationship between code consistency and task complexity. However, a comprehensive taxonomy of failure modes and case studies across a broader range of tasks would require substantially more analysis than fits within the scope of this paper. In the revised paper, we will discuss this limitation of our task grouping criteria and highlight more systematic studies of task complexity and failure modes as important directions for future work.

Regarding the two possible explanations for the observed low consistency, we believe the first is more likely in our setting: LLMs are not trained to directly produce executable self-explanations from a single-turn few-shot prompt. One piece of supporting evidence is that code consistency is imperfect even on the simplest tasks, suggesting that the challenge is not solely due to task complexity. Since code explanations are automatically verifiable, it is possible to optimize them, for example, by iteratively asking an LLM agent to refine the generated program based on its consistency score. Therefore, the observed relationship between low consistency and task complexity may be alleviated with better optimization.

We will include this discussion in the revised paper and highlight optimization of executable explanations as an important direction for future work.


Connection between sparse programs and code explanations

The reviewer points out that we did not discuss sparse programs past the related work. We agree that the connection between sparse programs and code explanations can be better clarified in the main text. By sparse programs, we mean a human-understandable symbolic program composed of a small number of basic operations, in contrast to the dense matrix computations performed by LLMs (after all, an LLM implemented in PyTorch is also a program). Our motivation is that explaining an LLM can be viewed as approximating the behavior of a dense computation with a compact, symbolic program. We will clarify this connection and consistently use the term human-understandable program throughout the paper to avoid confusion.


Hyperparameter choices

The reviewer asks about our choices of hyperparameters. As mentioned above, our goal is not to optimize the code explanation generation procedure, but to evaluate a simple generation strategy as a starting point for studying executable explanations. For the number of in-context examples, we choose N=20N = 20 as a representative number of few-shot settings that can provide sufficient context about the model's behavior for the LLM to generate general code explanations.

Following the reviewer’s suggestion, we evaluate Qwen with varying N∈{5,20,30}N \in \\\{5, 20, 30\\\}. Consistency changes on several tasks: for example, consistency on Object counting improves substantially with fewer in-context examples (+0.496), whereas consistency on Hyperbaton decreases for both smaller and larger NN values (-0.224). These results confirm that the choice of NN can affect code consistency, but neither increasing nor decreasing NN consistently improves it across tasks. Importantly, the paper’s main conclusions, including the low consistency on the four more complex tasks, stay unchanged. We will include this ablation in the revised paper and leave a more comprehensive study of hyperparameter optimization to future work.

Table 2: Consistency with different numbers of in-content examples

Model Task N = 20 (original) N = 5 N = 30
Qwen Web of lies 0.924 0.924 0.924
Navigate 0.660 0.748 0.748
Hyperbaton 0.768 0.564 0.544
Object counting 0.274 0.774 0.331
Formal fallacies 0.556 0.564 0.556
Disambiguation QA 0.585 0.552 0.540
Snarks 0.539 0.562 0.551
Translation error 0.376 0.376 0.376

References

[1] https://arxiv.org/abs/2606.28615


Once again, we appreciate the reviewer’s constructive feedback. We believe these additional experiments better establish the strengths and current limitations of code explanations, and strengthen the paper as an initial step towards automatically verifiable and compact dataset-level explanations.

Reviewer YMY7 · CommentOpenReview ↗

Thank you to the authors for the detailed rebuttal and the additional experiments. The new experiments and other clarifications resolve my remaining questions. I have raised my score accordingly.

From OpenReview, CC BY 4.0. Authors as signed there; shown unedited.

Missing a submission?

Loading the discussion…