Manuscript Offprint

arXiv:2608.30581

Automated Testing of LLM-Based Post Hoc Explainers Using Model Checking as an Oracle

Dennis Gross, Helge Spieker

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Dennis Gross 1,2^{1,2}[0009-0001-5734-0538] and Helge Spieker 2^{2}[0000-0003-2494-4279]

1^{1} Institut für Kommunikations- und Prüfungsforschung gGmbH

2^{2} Simula Research Laboratory, Oslo, Norway

Corresponding author: dennis@artigo.ai

Abstract. Large language models (LLMs) are used as post hoc explainers of sequential decision-making policies, producing natural-language explanations of why an action was chosen. However, LLMs often generate plausible but incorrect statements, and no existing approach systematically tests whether such explanations are faithful to the underlying environment. Two classic software testing challenges stand in the way: there is no oracle for the correctness of an explanation, and the test inputs, natural language queries about a policy's behavior, lack the structure needed for systematic test case generation. We address both. Probabilistic model checking provides the test oracle, computing exact reference results against which LLM answers are graded automatically. A taxonomy of post hoc query categories structures the input space around the environment-level facts from which policy explanations are composed; test cases generated from it are prioritized by question-specific diagnostic difficulty scores. Across seven MDP environments, the testing separates three open-weight LLMs: a reasoning model passes 85% of test cases, a mid-size model 70%, and a 1B model falls below the random baseline, while prioritization surfaces significantly harder cases than random selection. Our results indicate how trustworthy LLM-generated explanations are in model-free settings, where the same LLMs are used but no oracle exists to verify them.

Keywords: Software testing · Large language models · Probabilistic model checking · Explainable reinforcement learning · Test oracle.

1 Introduction

Sequential decision-making tasks are at the core of applications in domains such as gaming [10], manufacturing [13], and healthcare [11]: an agent repeatedly observes the current state of its environment, selects an action, and thereby stochastically influences the successor state to reach a fixed objective. Such tasks are formally modeled as Markov decision processes (MDPs) [29]. We focus on MDPs with finitely many states and actions, and on memoryless policies, which base each decision solely on the current state rather than on the history of past states and actions. The consequences of a single decision unfold over subsequent steps. Policies are typically obtained automatically, e.g., via deep reinforcement

D. Gross et al.

learning (RL) [27], so the rationale behind an individual choice is often not accessible to the human user: the learned policy is a neural network whose internal computations are not human-interpretable. To address this, large language models (LLMs) have recently been employed as post hoc explainers that analyze a decision after the fact, rather than making the policy interpretable by design [6]: after the policy has made a decision, the LLM is prompted to produce a natural language explanation of why that action was chosen in the given state.

However, LLMs are known to produce plausible-sounding but incorrect statements [28], which raises a software testing problem: before such explanations can be trusted, the LLM-based explainer must itself be tested. Testing it is challenging for two reasons. First, there is no test oracle [4]: judging whether an explanation is correct requires knowing the true properties of the environment and policy. Second, the input space is unstructured: it is unclear which kinds of explanation queries exist and which concrete queries are worth posing. Consequently, while prior work has evaluated LLM-generated explanations [23,35] and even used them to improve policy performance [14], no existing approach systematically tests whether an LLM actually understands the underlying environment and produces explanations faithful to it.

In this paper, we present an automated approach for testing LLM-based post hoc explainers of sequential decision-making policies. We address the oracle problem via probabilistic model checking [3]: given a formal model of the environment and a property specified in a temporal logic such as PCTL [19], a model checker exhaustively analyzes the state space and computes, for instance, the exact probability of reaching a goal or violating a safety condition. These results are exact and carry formal guarantees, and thus serve as a reliable oracle against which the LLM's answers are graded automatically. To structure the test input space, we introduce a taxonomy of post hoc query categories, which guides generating targeted test queries, for example, which actions in a state are optimal or whether a state is safety-critical, and shows, per category, where different LLMs succeed or fail. These queries target the environment-level facts, such as optimality and safety, from which any post hoc explanation of a policy's decision is composed. Since not every state is equally informative for every query, we prioritize test inputs by a question-specific diagnostic score, such as the fraction of non-optimal actions, and select the highest-ranked states for testing. Our approach requires a formal model of the environment, but this restriction applies only to testing, not to its implications: the formal model provides a measurement instrument for the LLM's reasoning capabilities. Test results obtained in this controlled setting thereby indicate how trustworthy LLM-generated explanations are in model-free settings, where the same LLMs are applied but no oracle exists to verify them.

References (44)