NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Generating High-Precision Feedback for Programming Syntax Errors using Large Language Models

Tung Phung, José Cambronero, Sumit Gulwani, Tobias Kohn, Rupak Majumdar, Adish Singla, Gustavo Soares · DOI · OpenReview

Abstract

Novice programmers frequently struggle with cryptic syntax error messages provided by standard compilers and interpreters. While Large Language Models (LLMs) offer a potential solution for generating personalized feedback, their tendency to hallucinate incorrect fixes or explanations poses a significant risk in educational settings. This paper introduces PyFiXV, a novel framework that leverages LLMs to generate high-precision feedback. By implementing a "simulated student" validation mechanism, PyFiXV ensures that generated explanations are actionable and correct, allowing educators to tune the balance between feedback quality and coverage.

1. Introduction

Syntax errors represent a primary hurdle for students learning to code. Standard error messages, such as "Unexpected EOF while parsing," often fail to provide the conceptual bridge necessary for a student to understand their mistake. While human tutors can provide the necessary context and guidance, they cannot scale to meet the demands of massive introductory programming courses or global online learning platforms.

Recent advancements in Large Language Models (LLMs) like OpenAI’s Codex have opened new avenues for automated tutoring. However, the deployment of LLMs in education is hindered by the "hallucination" problem—the generation of plausible-sounding but technically incorrect information. In a learning environment, providing a student with a wrong explanation is often more detrimental than providing no feedback at all. To address this, we present PyFiXV, a system designed to prioritize high precision through a multi-stage generation and validation pipeline.

2. The PyFiXV Framework

PyFiXV decomposes the feedback generation process into three distinct stages, moving from code repair to natural language explanation and, finally, to rigorous validation.

2.1 Stage 1: Generating the Fixed Program ($P_f$)

The system first attempts to repair the student's buggy program ($P_b$). Using Codex-Edit, PyFiXV generates multiple candidate fixes. The system then selects the candidate that is both syntactically correct and maintains the highest structural similarity (smallest edit distance) to the original code, ensuring the fix remains relevant to the student's initial logic.

2.2 Stage 2: Generating the Explanation ($\mathcal{X}$)

Once a valid fix is identified, the system generates a natural language explanation. This is achieved through Codex-Complete using few-shot prompting. The prompt includes the buggy code, the fixed code, and examples of expert-written feedback to guide the LLM in producing a clear, pedagogical explanation of the error.

2.3 Stage 3: The "Simulated Student" Validation

The core innovation of PyFiXV is its validation stage. To ensure the explanation is high-quality and actionable, the system uses an LLM to "act" as a student. This simulated student is given the original buggy program and the generated explanation as an instruction. If the explanation is accurate and clear, the LLM should be able to successfully produce the fixed program ($P_f$). If the simulated student fails to recreate the fix, the feedback is rejected as potentially confusing or incorrect.

This mechanism acts as a "precision knob." By requiring the simulated student to succeed across multiple trials or under stricter conditions, educators can ensure that the feedback provided to real students is highly reliable.

3. Experimental Evaluation

3.1 Datasets

The performance of PyFiXV was evaluated using two distinct Python datasets:

  • TigerJython: 240 programs from an educational IDE used in secondary schools (Python 2).
  • Codeforces: 240 programs from a competitive programming platform (Python 3).

To support the few-shot prompting, the authors utilized an annotated dataset ($D_{shot}$) containing 480 programs paired with expert-written feedback.

3.2 Results

PyFiXV demonstrated a significant improvement over baseline methods in terms of precision:

  • Precision: On the TigerJython dataset, default compiler error messages provided helpful guidance in only 5% of cases. In contrast, PyFiXV achieved a precision of 76%.
  • Coverage: Despite the strict validation filter, the system provided high-quality feedback for 31.2% of TigerJython cases and 64.2% of Codeforces cases.
  • Validation Effectiveness: The "simulated student" approach proved far superior to simpler rule-based filters (such as explanation length), effectively catching subtle hallucinations that would otherwise mislead students.

4. Discussion and Future Work

PyFiXV formalizes the trade-off between precision and coverage in educational AI. By prioritizing precision, the system ensures that when it speaks, it is almost certainly correct—a critical requirement for maintaining student trust.

Currently, the system is limited to syntax errors. Future research will explore semantic errors, which involve logic flaws in code that otherwise runs successfully. Additionally, as LLMs continue to evolve, the framework can be adapted to newer models (e.g., GPT-4), potentially increasing coverage while maintaining the high precision standards established by the simulated student validation method. Finally, the authors envision a hybrid "human-in-the-loop" system where feedback rejected by the AI is routed to human tutors, combining the efficiency of LLMs with the ultimate reliability of human experts.

Summary updated

BibTeX
@inproceedings{phung2023generating,
  author = {Tung Phung and José Cambronero and Sumit Gulwani and Tobias Kohn and Rupak Majumdar and Adish Singla and Gustavo Soares},
  title = {{Generating High-Precision Feedback for Programming Syntax Errors using Large Language Models}},
  booktitle = {EDM},
  year = {2023},
}
Figure