arXiv:2610.38311cs.SEOct 2026

Manuscript Offprint

arXiv:2610.38311

Detecting Incorrect LLM Explanations for Automated Program Repair

Lam Nguyen Tung, Chenxi Gu, Xiaoning Du, Haoye Tian, Aldeida Aleti, Neelofar Neelofar

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

Lam Nguyen Tung

Monash University

Melbourne, Australia

lam.nguyentung@monash.edu

Chenxi Gu

Monash University

Melbourne, Australia

chenxi.gu@monash.edu

Xiaoning Du

Monash University

Melbourne, Australia

xiaoning.du@monash.edu

Haoye Tian

Aalto University

Espoo, Finland

haoye.tian@aalto.fi

Aldeida Aleti

Monash University

Melbourne, Australia

aldeida.aleti@monash.edu

Neelofar Neelofar

RMIT University

Melbourne, Australia

neelofar.neelofar@rmit.edu

Abstract—LLM-generated explanations are important in automated program repair (APR), as they enable developers to understand repair rationale and assess patch quality. Their correctness can directly affect how developers respond to repairs. For instance, incorrect explanations may signal unreliable repairs that fail to fix bugs. Thus, detecting incorrect explanations is essential to help developers focus on reliable repairs. However, manual detection is impractical due to the growing number of LLM-generated repairs. Automated detection is therefore necessary to filter explanations presented to developers.

Prior methods mainly detect incorrect responses of general question-answering LLMs, not APR explanations. They often sample responses and identify contradictions among them. In APR, they face two limitations: (1) to identify contradictions, they often rely on external verifiers, which may not exist or lack APR-specific reasoning; (2) their sampling techniques, e.g., paraphrasing or same-input re-prompting, tend to produce superficial or redundant samples. Such methods may reproduce the original incorrect explanation, failing to expose it via contradictions.

We propose MetaReJ, a new metamorphic testing approach and the first detection method for incorrect APR explanations. To avoid reliance on external verifiers, MetaReJ adopts a metamorphic argumentative strategy inspired by debate and viva examination to challenge the LLM's explanation. Using novel metamorphic relations (MRs), MetaReJ recursively questions the LLM under equivalent and non-equivalent repair scenarios and captures contradictions in its responses. To mitigate superficial sampling, MetaReJ leverages program transformations. It transforms the original buggy program into different variants that either preserve or alter the underlying bug. It then samples explanations by asking the LLM how to fix the transformed variants. This technique produces more diverse and non-redundant samples, making it easier to expose contradictions. Such contradictions are encoded as MR violations. If the LLM's responses violate the MRs, MetaReJ flags the original explanation as incorrect. To evaluate MetaReJ, we constructed a manually-labeled dataset of 1,756 explanations of multiple LLM-based APR systems. Experiments show that MetaReJ achieves up to 0.43 in MCC, outperforming prior methods by 333.3% in MCC.

Index Terms—Program Repair, Explanation, Metamorphism

I. INTRODUCTION

Large language models (LLMs) have advanced automated program repair (APR), achieving state-of-the-art (SOTA) re-pair success rates of up to 70% on existing benchmarks [1]–[3]. Despite this, developers still prefer to remain involved in the repair process, mainly due to the lack of trust in fully automated repairs [4], [5]. Building such trust requires developers to understand not only the generated patch, but also the rationale behind it [6], [7]. LLM-provided explanations offer a useful mechanism for communicating the LLM's repair rationale to developers [8]. This helps developers assess the quality of the generated repairs [9]. The correctness of explanations may influence how developers act on the repairs. For example, incorrect explanations indicate unreliable repairs that fail to fix bugs and should be disregarded. Hence, detecting incorrect explanations is essential in LLM-based APR. However, it is overwhelming for developers to detect them manually, as the number of LLM-generated repairs continues to grow extensively [1], [2]. This creates a need for automated detection of incorrect explanations. Such automation reduces the number of explanations presented to developers, alleviates review burden, and facilitates the repair process.

No available method detects incorrect APR explanations. Most methods identify if the final answers of LLMs in general question-answering tasks are incorrect. These methods often sample multiple responses and identify if these responses contradict one another [10], [11]. For example, SelfCheckGPT [10] re-prompts the LLM with the same query and compares the new responses with the original using semantic similarity metrics or external LLMs. MetaQA [11] and DrHall [12] paraphrase the response and identify contradictions among the paraphrased versions.

Unfortunately, existing methods are not well-suited or effective for APR explanations. We identify two key limitations. First, methods like SelfCheckGPT rely on external verifiers to identify contradictions. In APR, such verifiers often do not exist or lack APR-specific knowledge. Second, existing methods sample explanations by re-prompting LLMs with the same input or by paraphrasing the explanation. Such sampled explanations are often low-diversity or only superficially different at the word level. They may preserve incorrectness rather than revealing it through contradictions [11].

Exhaustively detecting incorrect explanations is a non-trivial task. Hence, we take a step toward mitigating manual review effort and facilitating the APR process. We achieve this by mitigating the two limitations. We propose MetaReJ, a new metamorphic testing method and the first approach for detecting incorrect APR explanations. To mitigate the first limitation, we adopt a metamorphic argumentative strategy to challenge the LLM's explanation. Rather than relying on external verifiers, MetaReJ probes whether the LLM can defend itself under a series of recursive questions without providing contradictory responses. Intuitively, reliable reasoning for generating a correct explanation should transfer to and support these probing questions. In contrast, unreliable reasoning is more likely to surface as contradictions.

This argumentative strategy is inspired by debate and viva examination. A given claim is not directly judged by outside knowledge or understanding. The adopted strategy treats the claim as a premise. The claim-giver then responds to a series of recursive questions to determine whether later responses reinforce or contradict that premise. In this way, the claim-giver is challenged using their own claims, assumptions, or logic. Analogously, we treat the LLM as the claim-giver. The original explanation and patch are considered the claim. MetaReJ questions the LLM to generate sampled explanations and then to verify if these explanations apply to the original program. Metamorphic relations (MRs) are introduced to design such questions and represent the expected responses.

To mitigate the second limitation, we do not apply prior superficial sampling techniques. Instead, we apply diverse, non-redundant transformations at the program level. We transform the original buggy program in terms of syntax or semantics. We then sample explanations by asking the LLM how to fix the transformed programs. These explanations, referred to as follow-up explanations, will inevitably be transformed accordingly. This allows MetaReJ to mitigate the repetition of superficial or redundant sampled explanations.

We encode program transformations in two MRs to generate and evaluate follow-up explanations. [MR1][MR_{1}] Explanations for fixing semantically equivalent programs apply to the original program. [MR2][MR_{2}] Explanations for fixing semantically non-equivalent programs should not apply, as they have different bugs. The LLM is expected to satisfy these MRs.

Given these two MRs, MetaReJ performs the metamorphic argumentative strategy in three steps. First, it transforms the original buggy program using semantic-preserving and semantic-altering transformations. Second, it asks the LLM to generate follow-up explanations for fixing the transformed programs. Third, it asks the same LLM to evaluate if these explanations satisfy the MRs. Our key insight is that the LLM's explanation is incorrect if the LLM's responses are likely to violate the MRs. Such violations mean the LLM contradicts itself about fixing the buggy program, likely to generate an incorrect explanation.

To effectively adopt the metamorphic argumentative strategy, we also explicitly provide the LLM with the original

patch as the context when generating follow-up explanations. This is the critical step: it prepares the LLM to be examined, sets up the premise, and anchors follow-up explanations to the same original patch. By doing so, contradictions can be unambiguously traceable back to the original explanation. Otherwise, the strategy may freely generate follow-up explanations that introduce brand new claims. These explanations are therefore less commensurable with the original one. This makes it difficult to determine if apparent contradictions are truly due to the original explanation or to the new claims. Hence, this weakens the logical foundation of the metamorphic argumentative strategy, as used in debate or viva examination.

As detecting incorrect APR explanations is not trivial, MetaReJ is designed to be high-precision while increasing the chances of detecting them. Its metamorphic argumentative strategy can improve precision by avoiding external verifiers, which introduce a new source of uncertainty that may cause false contradictions. MetaReJ derives contradictions from the LLM's own reasoning, providing stronger evidence of incorrect explanations. The improvement in precision, however, comes with a potential loss in recall. MetaReJ may fail when the LLM is stubborn and consistently defends its incorrect reasoning. By using program transformations, we mitigate the second limitation but also compensate for the loss in recall and further strengthen it by diversifying the sampling.

To evaluate MetaReJ, we create a manually-labeled dataset of APR explanations. These explanations are collected from three SOTA systems: ThinkRepair [13], ReInFix [1], and MORepair [14] on the respective bug datasets used in the original studies. These studies had already mitigated data leakage. We formulated the detection of incorrect explanations as a binary classification problem. Our experiments show that MetaReJ achieves on average Precision of 0.92, Recall of 0.64, and MCC (Matthew Correlation Coefficient [15]) of 0.39. It also outperforms the SOTA methods designed for general question-answering by up to 30.0% in Precision, 536.4% in Recall, and 333.3% in MCC.

Our main contributions can be summarised as follows:

The first benchmark of the correctness of explanations generated by LLM-based APR systems,

  • MetaReJ, the first approach that detects incorrect explanations of LLM-based APR systems,

  • A comprehensive evaluation of MetaReJ on the constructed benchmark, which shows that MetaReJ improves methods designed for general question-answering by up to 30.0% in Precision, 536.4% in Recall, 333.3% in MCC,

• The dataset and implementation are available at https://doi.org/10.5281/zenodo.21059953.

References (40)