Iterative Self-Correction via Execution Feedback

This direction is merged into another direction: iterative code refinement. Its last version stays readable and citable here.

Version 1 of 145 papers47 conceptsfrozen 2026-10-04

Large Language Models (LLMs) are remarkably proficient at generating code, but they frequently hit a "one-shot wall." When tasked with complex programming, scientific simulation, or formal logic, even the most capable models often produce code that is syntactically invalid or logically flawed.

The emerging research direction across these 45 papers moves away from treating code generation as a single-pass translation task. Instead, it treats the LLM as an agent within a closed-loop system. By executing generated code and feeding the resulting error messages, tracebacks, or symbolic logs back into the model, these systems allow the AI to "debug" its own work. This iterative refinement mimics the human development process, shifting the goal from "writing perfect code" to "converging on a functional solution."

The Mechanism of the Feedback Loop

The core intuition behind this research is that while an LLM might not know the exact API call or syntax for a niche library, it is highly capable of interpreting the error message produced when that call fails.

In a typical self-correction pipeline, the system follows four distinct stages:

  1. Generation: The model produces an initial code snippet based on a prompt.
  2. Execution: The code is run in a sandboxed environment (e.g., a Python interpreter, a SQL engine, or a PDDL solver).
  3. Feedback: If the code fails, the system captures the raw terminal output, compiler errors, or runtime exceptions.
  4. Refinement: The model receives its original code plus the error log and is asked to provide a fix.

Weixiang Yan and colleagues formalize this shift in CodeTransOcean by introducing the Debugging Success Rate (DSR@K). This metric prioritizes functional correctness—whether the code actually works—over surface-level text similarity to a ground-truth solution.

Distinguishing Syntax from Logic

A key challenge in this field is determining what kind of error occurred. Xia Jiang and Yaoxin Wu demonstrate in their work on DRoC that simple syntax errors (like a missing parenthesis) can be fixed through internal self-debugging. However, fundamental logic flaws or "hallucinated" APIs often require the system to trigger external knowledge retrieval.

To handle these deeper logical issues, researchers like Dong Huang and Qingwen Bu developed CodeCoT. This framework integrates "Chain-of-Thought" reasoning with iterative self-examination, where the model generates its own test cases to verify its logic before the code is even deployed. Similarly, Shihan Dou and Haoxiang Jia found that providing models with a structured taxonomy of potential errors allows them to fix nearly 30% of buggy code without any additional training.

Bridging the Symbolic and Neural Gap

This iterative approach is particularly powerful when bridging the gap between natural language and formal symbolic systems. LLMs often struggle with the rigid requirements of planning languages like PDDL or action languages like $BC+$.

In SPAR, Songhao Huang and Sunan Huang use a functional syntax checker to provide targeted feedback to the LLM, enabling it to generate executable robot logic with over 95% success. Adam Ishay and Joohyung Lee 0002 take this further in LLM+AL, using a symbolic reasoner as the "judge" in the loop. If the reasoner finds the generated logic unsatifiable, the error is fed back to the LLM to revise its translation.

Applications in Autonomous Science

The most striking evidence for the efficacy of execution feedback comes from "self-driving laboratories." In these settings, the LLM isn't just writing code for a human; it's writing code to control physical or simulated experiments.

  • Laser Design: Renjie Li and Ceyao Zhang used LLM4Laser to automate semiconductor design, where the model iteratively refined simulation scripts based on raw terminal errors.
  • Materials Discovery: In MAPPS, Lan Zhou and Lianhao Zhou utilized a self-reflection loop to ensure generated code correctly interfaced with complex physics libraries.
  • Clinical Modeling: Evgeny Saveliev and Thomas Pouplin created CliMB, which allows clinicians to build predictive models by capturing Python exceptions and tracebacks to refine data processing pipelines autonomously.

Why It Works: The Power of Context

The success of these methods suggests that the "knowledge" required to fix a bug is often present in the model, but it remains latent until triggered by a specific failure. As Cuiyun Gao notes in a systematic review, execution feedback provides a "grounding" mechanism that breaks the cycle of hallucination. By processing a real-world error message, the model is forced to reconcile its internal representation with the objective constraints of the compiler or environment.

Ultimately, this research direction suggests that the future of AI-assisted engineering lies not in larger models that never make mistakes, but in agentic architectures that are better at learning from the mistakes they inevitably make.

Papers in this version

History & citationVersion 1 · 2026-10-04

Merged into another direction · Permanent link

View frozen version 1

Cite this direction

Latest version (a living page):

@misc{lacuna_iterative_self_correction_via_execution__fd873a76,
  title = {Iterative Self-Correction via Execution Feedback},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/iterative-self-correction-via-execution-feedback/rdr_fd873a76cde34254b8a74b1acf8d7b87},
  note = {Latest version of a living research direction; cite a version for a fixed text. Accessed 2026-11-23},
}

This exact version (version 1, frozen text):

@misc{lacuna_iterative_self_correction_via_execution__fd873a76_v1,
  title = {Iterative Self-Correction via Execution Feedback},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/iterative-self-correction-via-execution-feedback/rdr_fd873a76cde34254b8a74b1acf8d7b87/v/1},
  note = {Version 1, frozen 2026-10-04. Accessed 2026-11-23},
}