Code as Explanations: Executable and Verifiable LLM Explanations
Not on the map. Why?
Abstract (arXiv)
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× to 100× 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.
Key facts. No citing papers in the map yet (data through 24 Nov 2026). Builds on 38 of its 51 references that are in the map. Submitted 10 Nov 2026.
Builds on
38 of 51 references.
References · 38
- 2017Attention Is All You Needcited by 62,125
- 2022Chain-of-Thought Prompting Elicits Reasoning in Large Language Modelscited by 12,963
- 2021Evaluating Large Language Models Trained on Codecited by 8,938
- 2021Program Synthesis with Large Language Modelscited by 3,972
- 2024LiveCodeBench: Holistic and Contamination Free Evaluation of Large Language Models for Codecited by 2,243
- 2022Challenging BIG-Bench Tasks and Whether Chain-of-Thought Can Solve Themcited by 1,957
- 2023Language Models Don't Always Say What They Think: Unfaithful Explanations in Chain-of-Thought Promptingcited by 1,324
- 2024Qwen2.5-Coder Technical Reportcited by 1,301
- 2021Measuring Coding Challenge Competence With APPScited by 938
- 2023Progress measures for grokking via mechanistic interpretabilitycited by 919
- 2024A Survey on Large Language Models for Code Generationcited by 695
- 2024Executable Code Actions Elicit Better LLM Agentscited by 633
26 more
- 2025Reasoning Models Don't Always Say What They Thinkcited by 503
- 2024Sparse Feature Circuits: Discovering and Editing Interpretable Causal Graphs in Language Modelscited by 491
- 2024LiveBench: A Challenging, Contamination-Limited LLM Benchmarkcited by 312
- 2018Learning to Explain: An Information-Theoretic Perspective on Model Interpretationcited by 252
- 2026Scaling Monosemanticity: Extracting Interpretable Features from Claude 3 Sonnetcited by 248
- 2023ClassEval: A Manually-Crafted Benchmark for Evaluating LLMs on Class-level Code Generationcited by 176
- 2024Looking Inward: Language Models Can Learn About Themselves by Introspectioncited by 139
- 2024Language-Specific Neurons: The Key to Multilingual Capabilities in Large Language Modelscited by 138
- 2023Faithfulness Tests for Natural Language Explanationscited by 117
- 2024Are self-explanations from Large Language Models faithful?cited by 110
- 2024Chain of Preference Optimization: Improving Chain-of-Thought Reasoning in LLMscited by 101
- 2024If LLM Is the Wizard, Then Code Is the Wand: A Survey on How Code Empowers Large Language Models to Serve as Intelligent Agentscited by 84
- 2025Audio-CoT: Exploring Chain-of-Thought Reasoning in Large Audio Language Modelcited by 84
- 2023On Measuring Faithfulness or Self-consistency of Natural Language Explanationscited by 82
- 2021Have We Learned to Explain?: How Interpretability Methods Can Learn to Encode Predictions in their Interpretationscited by 63
- 2023The Curious Case of Hallucinatory (Un)answerability: Finding Truths in the Hidden States of Over-Confident Large Language Modelscited by 60
- 2024ICLR: In-Context Learning of Representationscited by 58
- 2023Post Hoc Explanations of Language Models Can Improve Language Modelscited by 52
- 2025Walk the Talk? Measuring the Faithfulness of Large Language Model Explanationscited by 51
- 2024CoD, Towards an Interpretable Medical Agent using Chain of Diagnosiscited by 47
- 2026Reward Hacking Benchmark: Measuring Exploits in LLM Agents with Tool Usecited by 44
- 2025Language Models Fail to Introspect About Their Knowledge of Languagecited by 37
- 2025Mol-LLaMA: Towards General Understanding of Molecules in Large Molecular Language Modelcited by 19
- 2025LLMs Don't Know Their Own Decision Boundaries: The Unreliability of Self-Generated Counterfactual Explanationscited by 19
- 2025Because we have LLMs, we Can and Should Pursue Agentic Interpretabilitycited by 18
- 2026What LLMs explain is not what they believe: Evaluating explanation sufficiency under models' own input beliefscited by 2
Built on by
Not cited yet.
Similar, not cited
Close in wording, no citation either way
- 2025Enabling Global, Human-Centered Explanations for LLMs:From Tokens to Interpretable Code and Test Generation
- 2024Towards More Trustworthy and Interpretable LLMs for Code through Syntax-Grounded Explanations
- 2026Evaluating Language Models on Cross-Language Code Functional Equivalence
- 2025On Code-Induced Reasoning in LLMs
- 2025Can LLMs Reason About Program Semantics? A Comprehensive Evaluation of LLMs on Formal Specification Inference
- 2025Demystifying Errors in LLM Reasoning Traces: An Empirical Study of Code Execution Simulation
- 2025Disproving Program Equivalence with LLMs
- 2025LMR-BENCH: Evaluating LLM Agent's Ability on Reproducing Language Modeling Research