# Code as Explanations: Executable and Verifiable LLM Explanations

DevFeed: [Code as Explanations: Executable and Verifiable LLM Explanations](<https://devfeed.tech/articles/code-as-explanations-executable-and-verifiable-llm-explanations-132040.md>)

Original publisher: [Read original article](<https://arxiv.org/abs/2611.14704>)

Author: Nhi Nguyen, Shauli Ravfogel, Rajesh Ranganath

Published: 2026-11-13T05:00:00Z

Content type: article

Language: en

Sources: [arXiv: Artificial Intelligence](<https://devfeed.tech/sources/arxiv-artificial-intelligence.md>), [arXiv: Machine Learning](<https://devfeed.tech/sources/arxiv-machine-learning.md>)

Topics: [Large Language Model](<https://devfeed.tech/topics/llm.md>), [llm-reasoning](<https://devfeed.tech/topics/llm-reasoning.md>), [AI Models](<https://devfeed.tech/topics/ai-models.md>)

Tags: [chain-of-thought](<https://devfeed.tech/tags/chain-of-thought.md>), [claude](<https://devfeed.tech/tags/claude.md>), [claude-opus-5-5](<https://devfeed.tech/tags/claude-opus-5-5.md>), [code](<https://devfeed.tech/tags/code.md>), [code-execution](<https://devfeed.tech/tags/code-execution.md>), [complex](<https://devfeed.tech/tags/complex.md>), [consistency](<https://devfeed.tech/tags/consistency.md>), [cs-ai](<https://devfeed.tech/tags/cs-ai.md>), [cs-cl](<https://devfeed.tech/tags/cs-cl.md>), [cs-lg](<https://devfeed.tech/tags/cs-lg.md>), [dataset](<https://devfeed.tech/tags/dataset.md>), [execution](<https://devfeed.tech/tags/execution.md>), [feedback](<https://devfeed.tech/tags/feedback.md>), [llm](<https://devfeed.tech/tags/llm.md>), [open-source](<https://devfeed.tech/tags/open-source.md>), [program](<https://devfeed.tech/tags/program.md>), [stat-ml](<https://devfeed.tech/tags/stat-ml.md>), [times](<https://devfeed.tech/tags/times.md>), [verification](<https://devfeed.tech/tags/verification.md>)

## AI overview

The paper proposes executable programs as explanations of an LLM's behavior across multiple inputs: execution lets researchers check how often a program reproduces the model's outputs, measured by a Consistency metric. Across three open-source code-capable LLMs and eight tasks, these explanations were highly consistent in several settings, 6-100 times shorter than chain-of-thought, and better aligned with behavior in 9 of 24 settings. Performance fell on tasks with more complex language; there, programs did no better than an uninformative baseline and often used longer hard-coded patterns. In experiments with Claude Opus 5.5, consistency feedback and code execution improved results across tasks, though complex tasks remained harder. These findings are reported in the supplied abstract.

## Source excerpt

arXiv:2611.14704v1 Announce Type: cross 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.