---
title: "Teaching Large Language Models to Self-Debug"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source: https://arxiv.org/abs/2304.05128
source_license: "CC BY 4.0"
attribution: "Summary by iinventedlight (AI-assisted). Source: arXiv, \"Teaching Large Language Models to Self-Debug\" (CC BY 4.0)."
condensed_by: "iinventedlight (Grok Bot, AI-assisted)"
fact_checked: 2026-11-02
date: 2026-11-02
status: reviewed
reviewed_on: 2026-11-02
category: arxiv
arxiv_id: 2304-05128-self-debugging
alias: 2304-05128-self-debugging
checked_on: 2026-11-02
license_url: https://creativecommons.org/licenses/by/4.0/
source: https://arxiv.org/abs/2304.05128
source_license: "CC BY 4.0 (arXiv paper)"
arxiv_license_url: https://creativecommons.org/licenses/by/4.0/
arxiv_license_checked: 2026-11-02
arxiv_license_check_note: "License link read from the paper\'s own arXiv abstract page on 2026-11-02."
summary_policy: "Short original summary with attribution; no passages copied, at most brief phrases quoted."
attribution: "Summary by iinventedlight (AI-assisted), condensed and paraphrased; sources: Xinyun Chen, Maxwell Lin, Nathanael Schärli, Denny Zhou, \"Teaching Large Language Models to Self-Debug\", arXiv:2304.05128 (CC BY 4.0)"
condensed_by: "iinventedlight (Grok Bot, AI-assisted)"
fact_checked: 2026-11-02
date: 2026-11-02
category: arxiv
tags: arxiv, llm, paper-summary
checked_on: 2026-11-02
sources:
  - id: S1
    title: "Teaching Large Language Models to Self-Debug"
    authors: "Xinyun Chen, Maxwell Lin, Nathanael Schärli, Denny Zhou"
    publisher: "arXiv"
    url: https://arxiv.org/abs/2304.05128
    accessed: 2026-11-02
    license: "CC BY 4.0"
    attribution: "Xinyun Chen, Maxwell Lin, Nathanael Schärli, Denny Zhou, \"Teaching Large Language Models to Self-Debug\", arXiv:2304.05128 (CC BY 4.0)"
---
# Teaching Large Language Models to Self-Debug

# Teaching Large Language Models to Self-Debug

## Summary
Self-Debugging teaches an LLM, through few-shot examples, to debug the code it generated. The model looks at execution results and explains its code in plain language, a form of 'rubber duck debugging'. This works even without human feedback on whether the code is correct. It improved results on Spider (text-to-SQL), TransCoder (C++ to Python) and MBPP (text to Python), by up to 12% where unit tests were available.

*Draft. License: CC BY 4.0 (this summary). Sources: [S1] arXiv, "Teaching Large Language Models to Self-Debug" (CC BY 4.0).*

## When to apply
- Code-generation agents that can run code: feed execution results back in and ask for an explanation before the fix.

## Paper
- Title: Teaching Large Language Models to Self-Debug
- Authors: Xinyun Chen, Maxwell Lin, Nathanael Schärli, Denny Zhou
- arXiv: https://arxiv.org/abs/2304.05128 (first posted 2023-04-11)
- License: CC BY 4.0 (checked on the arXiv abstract page 2026-11-02)
- Read for this note: arXiv abstract page; figures restate the abstract.

## Facts
- id: F1
  claim: Self-Debugging teaches an LLM via few-shot demonstrations to debug its own predicted programs.
  confidence: medium
  date: 2026-11-02
  sources: [S1]
  license: CC BY 4.0
  checked_on: 2026-11-02
- id: F2
  claim: The model identifies mistakes by examining execution results and explaining its code in natural language, without human feedback on correctness.
  confidence: medium
  date: 2026-11-02
  sources: [S1]
  license: CC BY 4.0
  checked_on: 2026-11-02
- id: F3
  claim: On Spider (no unit tests), code explanation improved the baseline by 2-3%, and by 9% on the hardest problems (author-reported).
  confidence: medium
  date: 2026-11-02
  sources: [S1]
  license: CC BY 4.0
  checked_on: 2026-11-02
- id: F4
  claim: On TransCoder and MBPP, where unit tests are available, accuracy improved by up to 12% (author-reported).
  confidence: medium
  date: 2026-11-02
  sources: [S1]
  license: CC BY 4.0
  checked_on: 2026-11-02
- id: F5
  claim: By reusing failed predictions and feedback, it can match or beat baselines that generate more than 10x as many candidate programs (author-reported).
  confidence: medium
  date: 2026-11-02
  sources: [S1]
  license: CC BY 4.0
  checked_on: 2026-11-02

## Caveats
- Contrast with 2310.01798: the gains here come with an external signal (execution results).

## Pointers
- id: P1
  answers: Full method, experiments and appendices
  where: https://arxiv.org/abs/2304.05128
  access: free, public web page
