NeurIPS 2026QuestionsPapersAreasAboutMarkdown

Can LLMs explain themselves truthfully with code?

Nhi Nguyen, Shauli Ravfogel, Rajesh Ranganath

NeurIPS page · Open on the map

Category: LLM Agents, Evals & Benchmarks › Benchmark Reliability and Measurement · Type: new method · Keywords: LLM self-explanation, executable code explanations, consistency evaluation, code generation, interpretability

Areas: Evaluation & Benchmarks › Language Model and Agent Benchmarks › Reasoning Trace Analysis; Interpretability › Mechanistic Interpretability › LLM Interpretability

Summary

The paper investigates whether LLMs can consistently explain their behavior with executable code, proposing a procedure that samples multiple candidate programs and selects the most consistent one.

Explained to a 5-year-old

Big computer programs try to answer questions. Sometimes they write short explanations in words, but those words can't be run. This paper asks if the programs can write little computer programs that explain their answers. They check if the programs always give the same answer when run many times. They find that the programs work well sometimes, but often they are not reliable.

Explained to a 5-year-old, longer

Big computer programs are made to answer questions and help people. When they answer, they sometimes write a short sentence to tell why they think that. Those sentences are just words, and you cannot run them to see if they are correct. The paper asks whether the programs can instead write tiny computer programs that explain their answers. These tiny programs can be run by a computer to check if they match the program's behavior. The researchers made a method that creates many possible programs and picks the one that works best. They tested the programs on several different kinds of tasks, some easy and some hard. In easy tasks, the programs often gave the same answer many times, which means they were consistent. In harder tasks, the programs often gave different answers, and their correctness was close to random guessing. The longer programs were not more complicated in structure; they just copied parts of the question. The researchers also looked at the inside of the programs to see if they could tell when the explanations would be reliable, but they found that the internal information did not help predict consistency.

For a technical reader

The paper proposes a consistency-driven generation pipeline that samples multiple code candidates from an LLM and selects the most reliable explanation. It evaluates this pipeline across three open-source models and eight tasks, finding high consistency only in simple settings and near-random performance on linguistically complex tasks. The study also shows that model internal states do not predict when generated code will be consistent, highlighting a gap between model confidence and explanation reliability.

Problem

How can we evaluate LLM explanations in a compact, executable way, and can LLMs produce consistent code explanations of their predictions?

Method

The approach samples multiple candidate programs from the LLM and selects the most consistent one based on automatic verification, evaluating consistency across models and tasks. It uses three open-source code-capable models and eight tasks with varying linguistic difficulty to assess when LLMs produce consistent code explanations.

Results

Models produce highly consistent code explanations only in a subset of settings, but consistency falls to near random guessing on tasks with complex linguistic components, and model-internal representations do not reliably predict when explanations will be consistent.

Contributions

The work introduces code as a compact, executable alternative to free-text explanations, proposes a consistency-based selection procedure for generated programs, and reveals limitations in LLM self-explanation, including the inability of internal representations to forecast explanation consistency.

Practical relevance

Providing executable explanations could improve trust and evaluation in high-stakes applications where LLM justifications need to be automatically verified.

Research questions this paper is counted under

This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. Suggest a correction