Explainable Fault Localization for Programming Assignments via LLM-Guided Annotation

Fang Liu, Tianze Wang, Li Zhang, Zheyu Yang, Jing Jiang, Zian SunarXiv 2025 · DOI

Introduction

In the context of computer science education, providing timely and precise feedback on programming assignments is a significant challenge. While Online Judge (OJ) systems are widely used, they typically offer only binary feedback (e.g., "Accepted" or "Wrong Answer"), leaving students to struggle with identifying the root cause of their errors. Automated Fault Localization (FL) aims to address this by pinpointing buggy code segments. However, traditional spectrum-based methods often lack the granularity required for educational settings, and direct application of Large Language Models (LLMs) frequently suffers from the "Number Problem"—an inability to accurately map logic errors to specific line numbers.

To bridge this gap, we introduce FLAME (Fault Localization via LLM-guided Annotation and Model Ensemble), a framework designed to provide explainable and highly accurate fault localization for student submissions.

The FLAME Framework

FLAME moves away from the traditional approach of asking LLMs for line numbers. Instead, it treats fault localization as a code-annotation task, leveraging the superior text-processing capabilities of modern LLMs.

Overview of the FLAME framework illustrating the three stages: Information Collection, LLM-Guided Annotation, and Weighted Multi-Model Voting.

The framework operates in three distinct stages:

  1. Assignment-Specific Information Collection: FLAME aggregates the faulty code, the problem description, failed test cases, and a "reference program"—a successful student submission retrieved from a historical database. This provides the necessary context for the LLM to understand the intended logic.
  2. LLM-Guided Annotation: This is the core innovation of FLAME. Rather than predicting a list of integers, the LLM is prompted to return an annotated version of the source code. It inserts a specific marker (// @@) at the end of suspected lines, followed by a natural language explanation of the bug. This method bypasses the numerical reasoning weaknesses of LLMs.
  3. Weighted Multi-Model Voting: To mitigate individual model hallucinations and biases, FLAME employs an ensemble of state-of-the-art models, including Claude 3.7 Sonnet, DeepSeek-V3, and DeepSeek-R1. Their annotations are aggregated through a weighted voting strategy to produce a final ranked list of suspicious lines.
An example of a program annotated by FLAME, showing the use of the // @@ marker to provide a specific fix suggestion for a logic error.

Experimental Evaluation

The effectiveness of FLAME was evaluated on two datasets: PADEFECTS, a new dataset of 1,932 real-world student submissions from university-level courses, and Defects4J, a standard industry benchmark for Java.

Key Results

  • Superior Accuracy: On the PADEFECTS dataset, FLAME demonstrated a significant performance leap, localizing 207 more faults at Top-1 than the strongest baseline (ChatGPT-4 Log). It achieved a 62.7% Top-1 accuracy on Data Structures assignments, vastly outperforming traditional spectrum-based methods like Ochiai (10.6%).
  • Generalization: FLAME's performance extended beyond the classroom; it achieved a 53.7% Top-1 accuracy on the industry-standard Defects4J benchmark, outperforming all existing baselines.
  • Educational Utility: Beyond localization, the natural language explanations generated by FLAME were rated as highly informative by human evaluators (scoring ~6.4/7 on a Likert scale), suggesting its potential as an automated teaching assistant.

Discussion and Limitations

The success of FLAME stems from the "Annotation > Prediction" paradigm. By allowing LLMs to "point" at code using text, the framework avoids the misalignment issues common in line-number prediction. Furthermore, the ensemble approach ensures that the strengths of different models (e.g., DeepSeek-R1's reasoning vs. Claude's instruction following) are combined effectively.

However, limitations remain. FLAME's performance can degrade on extremely large codebases (exceeding 1,900 lines) where architectural complexity obscures local logic errors. Additionally, the framework relies on the availability of auxiliary information like problem statements and test cases, which may not always be present in "in-the-wild" software development scenarios.

Conclusion

FLAME represents a significant step forward in making automated fault localization both accurate and explainable. By reframing the problem as an annotation task and leveraging model ensembles, it provides students with actionable feedback that goes beyond simple line numbers, fostering a more effective learning environment.

Summary updated

BibTeX
@misc{liu2025explainable,
  author = {Fang Liu and Tianze Wang and Li Zhang and Zheyu Yang and Jing Jiang and Zian Sun},
  title = {{Explainable Fault Localization for Programming Assignments via LLM-Guided Annotation}},
  year = {2025},
  eprint = {2509.25676},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.25676},
}
Figure