∇
A model can only get better from its own work if something better than its own guesses tells it which work was good. This chapter studies every way to build that signal, from self-critique and self-play to verifier-filtered self-training, self-judged rewards, research agents, and recursive self-improvement, and proves where each loop saturates or collapses.
Chapter 26 · Section 26.1 · 85 min

Self-refinement and reflection

This chapter is about self-improvement, a model getting better by learning from its own outputs. It ends the part of the book on agents. Chapter 24 built models that act in a loop of tool calls, and Chapter 25 gave them memory that outlasts one context window. A system that can act and remember can also judge its own work and train on it. Whether that really improves the model shapes how labs spend compute while a model answers, how they build training data, and how they train reasoning models. One idea runs through the whole chapter. A model can improve on its own outputs only when something tells it which outputs were good, and that something must know more than the model's own guesses.

The chapter reuses several tools from the chapter on reasoning. A verifier is a checker that scores a model's answers, best-of-nn keeps the highest-scoring of nn samples, and pass@kk is the chance that at least one of kk samples is right (§18.2). Reinforcement learning with verifiable rewards trains a model on answers that a program can check (§18.3 and §18.4). And §18.7 described a revision by two numbers, how often it fixes a wrong answer and how often it breaks a right one.

This section studies the simplest such loop, self-refinement, which means letting a language model check its own answer and then rewrite it. The model answers, reads what it wrote, says what is wrong with it, and writes a new answer. The loop needs no training and no new data, only more calls to the same model. So it is the first thing people try when a model makes mistakes.

The published evidence seems to contradict itself. GPT-3.5 answered multiple-choice questions about everyday knowledge from the CommonSenseQA benchmark and was right 75.8% of the time. Then it was asked to review its answer and fix any problems it found. After one round of this its accuracy was 38.1% (Huang et al. 2024). Asked to double-check, it lost half its accuracy. Yet Self-Refine, a loop in which a model critiques and rewrites its own output, reports a gain of about 20 points on average over seven tasks (Madaan et al. 2023). Both results were measured carefully, and both are true.

They fit together once you split the loop into its two jobs. The critic decides whether the current answer is wrong. The reviser rewrites the answers the critic flagged. This section shows that the critic decides almost everything. Revision pays only when the critic flags wrong answers much more often than right ones, and the better the model already is, the sharper the critic must be.

Self-refinement carries the chapter's argument in its simplest form. Here the thing that must know more than the model's own guesses is the critic. We open up the revision step of §18.7 into a small model of critique and revision, and prove exactly when it raises accuracy. We define the generation-verification gap, the accuracy a checker adds when it keeps only the samples it accepts, which the rest of the chapter reuses. Then we read the published results through that lens, build a loop that does not cheat, and end with how labs train models to correct themselves.

Two results that seem to disagree

The table puts the numbers side by side. Every row compares a model's first attempt with its output after it critiqued and revised its own work, with no help from outside. GSM8K is a set of grade-school math word problems. Constrained Generation asks for a short passage that uses 20 to 30 given words, scored by the fraction of the words it uses. Dialogue Response asks for the next turn in a conversation, scored by how often a GPT-4 judge prefers it when shown both versions without being told which is which.

task (model)first attemptafter self-correctionwhat is measuredsource
CommonSenseQA (GPT-3.5)75.838.1accuracy, one roundHuang et al., Table 3
GSM8K (GPT-4)95.591.5accuracy, one roundHuang et al., Table 3
GSM8K math (GPT-4)92.993.1solve rate, up to 4 roundsMadaan et al., Table 1
Constrained Generation (GPT-4)15.045.0fraction of the words usedMadaan et al., Table 1
Dialogue Response (GPT-4)25.474.6share of comparisons preferredMadaan et al., Table 1

With GPT-4, the same loop adds 30 points of word coverage and two tenths of a point on math. The difference lies in how hard each output is to check. Checking whether a passage contains each of 20 words is easy, and a model does it well. Spotting the one slipped sign in a confident chain of arithmetic is hard. On the math problems, ChatGPT's feedback said "everything looks good" 94% of the time (Madaan et al. 2023). So revision helped where the output could be checked against the request, and failed where the critic had to recognize the one right answer. The dialogue row also measures a preference rate rather than an accuracy, so it is not directly comparable with the others.

The intuition fits in one sentence. A revision step changes only the answers the critic flags, so it helps exactly when the flagged answers are mostly wrong ones. Here is that sentence with real numbers.

The example already holds two lessons. What matters about a critic is how much more often it flags wrong answers than right ones. And the more right answers you start with, the more there are to break, so a strong model needs a sharper critic than a weak one. The rest of this section turns those two sentences into a theorem and then tests the theorem on published tables.

Three kinds of self-correction

The phrase self-correction has been used for setups that differ in the one way that matters, which is where the critic's information comes from. Huang et al. 2024 drew the line that the field now uses.

Oracle stopping always looks good, and a short calculation shows why. Under oracle stopping a right answer is never touched again, so nothing is ever broken. Say the first attempt is right with probability p1p_1, and each revision fixes a wrong answer with probability pfixp_{\text{fix}}. A problem is still wrong after mm attempts only if the first attempt and all m−1m - 1 revisions failed. So the probability of being right after mm attempts is

pm=1−(1−p1)(1−pfix)m−1,p_m = 1 - (1 - p_1)(1 - p_{\text{fix}})^{m-1},

which can only go up. With p1=0.8p_1 = 0.8 and pfix=0.5p_{\text{fix}} = 0.5, three revisions give 1−0.2×0.53=0.9751 - 0.2 \times 0.5^3 = 0.975. What the reviser would do to a right answer never matters, because it never sees one.

Huang et al. measured both versions with GPT-4 on GSM8K, with at most two rounds of revision. With oracle stopping, accuracy rose from 95.5% to 97.5%. Without it, the same model and the same three prompts (answer, critique, revise) gave 91.5% after one round and 89.0% after two. The 8.5 points between 97.5 and 89.0 are the work of the oracle.

Several earlier positive results on reasoning used the labels to decide when to stop. They include the question-answering experiments of Reflexion, an agent loop met later in this section, and RCI, a prompting method that recursively criticizes and improves an answer (Kim et al. 2023). Without the labels, the gains on reasoning disappeared in Huang et al.'s experiments. A loop that stops on the evaluation labels has leaked the test set into the method. So the first question to ask of any self-correction result, and the one an interviewer will ask you, is whether the loop knew when it was right.

The finding is general, as §18.7 also reported. Without labels, every model that Huang et al. 2024 tested ended below its first attempt on every benchmark after two rounds (Tables 3 and 4). GPT-3.5 on CommonSenseQA went from 75.8% to 38.1% after one round and 41.8% after two, and Llama-2-70B-chat on GSM8K went from 62.0% to 43.5% and then 36.5%.

The widget runs one reviser under three stopping rules. The reviser fixes half of the wrong answers it revises and breaks half of the right ones.

  • With oracle labels, only wrong answers go back for revision, and the critic is never consulted.
  • With a self-judged stop, an answer the critic accepts is final. A flagged answer is revised and judged again.
  • With fixed rounds, the critic judges every answer in every round.

One slider sets the first-attempt accuracy, and the other sets the critic's quality cc, between 0 and 1. The critic's detection rate, the chance it flags a wrong answer, is (1+c)/2(1 + c)/2. Its false-alarm rate, the chance it flags a right answer, is (1−c)/2(1 - c)/2. So c=0c = 0 is a coin flip and c=1c = 1 is a perfect critic.

Why do oracle-stopped self-correction results look so much better than intrinsic ones?
One reviser fixes half the wrong answers it revises and breaks half the right ones, under three stopping rules.
Loading interactive figure…

With a coin-flip critic, a first attempt at 0.8, and three rounds, the oracle-stopped loop reaches the 0.975 computed above. The self-judged loop falls to 0.65, and fixed rounds fall to about 0.54. The reviser is identical in all three. Only the choice of which answers it sees has changed.

Counting the answers that flip

Two accuracies hide how they were reached. A loop that fixes 10 answers and breaks 10 shows no change, yet it rewrote 20 answers. To see what a loop does, count the answers that flip in each direction. Kumar et al. 2024 report five numbers for a loop with two attempts, and this section uses them throughout.

The identity holds problem by problem. Expand the right side of c2i−c1i=(1−c1i)c2i−c1i(1−c2i)c_{2i} - c_{1i} = (1 - c_{1i})c_{2i} - c_{1i}(1 - c_{2i}) to get c2i−c1ic2i−c1i+c1ic2ic_{2i} - c_{1i}c_{2i} - c_{1i} + c_{1i}c_{2i}, which is the left side. Averaging over ii gives it for the fractions. In plain words, Δ\Delta is the net change, and the two flip fractions say how it was made.

The flips separate two kinds of bad critic that look alike in Δ\Delta. A timid critic that rarely flags anything shows small flips in both directions. A critic that cannot tell right from wrong shows large flips that cancel or go negative. The same paper gives a real case, which §18.7 read as fix and break rates. Its authors asked Gemini 1.5 Flash to check its work on 500 problems from MATH, a benchmark of competition mathematics, and its accuracy went from 52.6% to 41.4%. It fixed 4.6% of all problems and broke 15.8%, so it broke more than three right answers for every wrong one it fixed. When you report a self-correction experiment, report both flip fractions, not only the net change.

Warm-up

Self-correction metrics from transcripts

Write self_correction_metrics(first, second). The two inputs are arrays of the same length, of booleans or of 0/1 integers. Entry ii of first says whether problem ii was right at the first attempt, and entry ii of second whether it was right at the second. Return a dict with seven keys.

  • acc1, acc2, and delta, the two accuracies and their difference acc2 - acc1.
  • i_to_c and c_to_i, the two flip fractions, each as a fraction of all problems.
  • p_fix, the fraction of first-attempt wrong answers that are right at the second attempt, and p_break, the fraction of first-attempt right answers that are wrong at the second.

When a conditional rate has an empty group (no wrong first answers, say), return float('nan') for it instead of raising an error.

Tests, hints, verified solutions, and AI help, with Pro at $7.99 a month.

A critic decides whether revision helps

§18.7 modeled revision with two numbers. Each revision fixes a wrong answer with probability pfixp_{\text{fix}}, the fix rate, and breaks a right one with probability pbreakp_{\text{break}}, the break rate. Write pmp_m for the probability that the answer is right after mm attempts. A right answer stays right unless it is broken, and a wrong answer becomes right if it is fixed, so

pm+1=(1−pbreak) pm+pfix (1−pm).p_{m+1} = (1 - p_{\text{break}})\,p_m + p_{\text{fix}}\,(1 - p_m).

Each round moves accuracy a fixed fraction of the remaining way toward the plateau p⋆=pfix/(pfix+pbreak)p^\star = p_{\text{fix}}/(p_{\text{fix}} + p_{\text{break}}), the accuracy at which fixes and breaks cancel. So revision raises accuracy exactly when the first attempt starts below the plateau, p1<p⋆p_1 < p^\star. For the Gemini model above, p^fix=4.6/47.4=0.097\hat p_{\text{fix}} = 4.6/47.4 = 0.097 and p^break=15.8/52.6=0.300\hat p_{\text{break}} = 15.8/52.6 = 0.300, so its plateau is 0.097/0.397=0.240.097/0.397 = 0.24, far below its 52.6% start.

That model treats revision as one opaque step. A real loop has the two parts named at the start, a critic that decides whether something is wrong and a reviser that rewrites what the critic flagged. Opening the step up shows where the fix and break rates come from, and so which part to improve.

The critic is a binary classifier whose positive class is "this answer is wrong". In the language of the confusion matrix from §0.11, pdetp_{\text{det}} is its true positive rate and pfap_{\text{fa}} its false positive rate. Watch the direction when you compare it with a grader that accepts answers, such as the answer checkers of §18.3. For such a grader, a false positive means accepting a wrong answer, so pdet=1−FPRp_{\text{det}} = 1 - \mathrm{FPR} and pfa=FNRp_{\text{fa}} = \mathrm{FNR}.

The theorem below needs one more word. The odds of a probability pp are p/(1−p)p/(1 - p), so a model that is right 80% of the time has odds of 4 to 1.

In plain words, revision pays when two ratios multiplied together beat the odds that the first answer was already right. The first ratio says how much more often the critic flags wrong answers than right ones. The second says how much more reliably the reviser fixes than breaks.

∂ Proof of when critique-then-revise helps

Item 1. Condition on the state after attempt mm. A right answer stays right unless it is flagged and then broken, which happens with probability pfaqbreakp_{\text{fa}}q_{\text{break}}, since flagging and breaking are successive independent events. A wrong answer becomes right only if it is flagged and then fixed, with probability pdetqfixp_{\text{det}}q_{\text{fix}}. An unflagged wrong answer stays wrong. By the law of total probability,

pm+1=(1−pfaqbreak) pm+pdetqfix (1−pm),p_{m+1} = (1 - p_{\text{fa}}q_{\text{break}})\,p_m + p_{\text{det}}q_{\text{fix}}\,(1 - p_m),

which is the recurrence of §18.7 with pfix=pdetqfixp_{\text{fix}} = p_{\text{det}}q_{\text{fix}} and pbreak=pfaqbreakp_{\text{break}} = p_{\text{fa}}q_{\text{break}}. Setting pm+1=pmp_{m+1} = p_m gives the fixed point p⋆p^\star. Subtracting p⋆p^\star from both sides gives pm+1−p⋆=(1−pfix−pbreak)(pm−p⋆)p_{m+1} - p^\star = (1 - p_{\text{fix}} - p_{\text{break}})(p_m - p^\star). Applying this m−1m - 1 times from p1p_1 gives the closed form.

Item 2. Substitute into p⋆=pfix/(pfix+pbreak)p^\star = p_{\text{fix}}/(p_{\text{fix}} + p_{\text{break}}) and divide the numerator and the denominator by pfa>0p_{\text{fa}} > 0. This turns pdetqfixp_{\text{det}}q_{\text{fix}} into Λqfix\Lambda q_{\text{fix}} and pfaqbreakp_{\text{fa}}q_{\text{break}} into qbreakq_{\text{break}}.

Item 3. Write s=pfix+pbreaks = p_{\text{fix}} + p_{\text{break}}. Subtracting p1p_1 from the closed form gives pm−p1=(p⋆−p1)(1−(1−s)m−1)p_m - p_1 = (p^\star - p_1)\big(1 - (1 - s)^{m-1}\big). For 0<s<20 < s < 2 we have ∣1−s∣<1|1 - s| < 1, so (1−s)m−1<1(1-s)^{m-1} < 1 for every m≥2m \ge 2 and the second factor is positive. Hence pm>p1p_m > p_1 for all m≥2m \ge 2 exactly when p⋆>p1p^\star > p_1. For the odds form, multiply p1<pfix/sp_1 < p_{\text{fix}}/s by s>0s > 0 and expand,

p1pfix+p1pbreak<pfix  ⟺  p1 pbreak<(1−p1) pfix  ⟺  p1 pfaqbreak<(1−p1) pdetqfix.p_1 p_{\text{fix}} + p_1 p_{\text{break}} < p_{\text{fix}} \iff p_1\,p_{\text{break}} < (1 - p_1)\,p_{\text{fix}} \iff p_1\,p_{\text{fa}}q_{\text{break}} < (1 - p_1)\,p_{\text{det}}q_{\text{fix}} .

Dividing both sides by the positive number (1−p1) pfaqbreak(1 - p_1)\,p_{\text{fa}}q_{\text{break}} gives p1/(1−p1)<Λqfix/qbreakp_1/(1-p_1) < \Lambda q_{\text{fix}}/q_{\text{break}}.

Item 4. With pfa=0p_{\text{fa}} = 0 we have pbreak=0p_{\text{break}} = 0, so p⋆=1p^\star = 1 and s=pfix∈(0,1]s = p_{\text{fix}} \in (0, 1]. The closed form becomes pm=1−(1−p1)(1−pfix)m−1p_m = 1 - (1 - p_1)(1 - p_{\text{fix}})^{m-1}, which increases with mm and tends to 1. ∎

The theorem has four consequences worth knowing by heart.

  • A critic with no false alarms always helps. It never touches a right answer, so accuracy climbs toward 1. Oracle stopping is exactly this critic, and item 4 is the formula from the start of the section.
  • A critic that flags at random needs a remarkable reviser. A random critic has Λ=1\Lambda = 1, and so does "always revise". The condition becomes qfix/qbreak>p1/(1−p1)q_{\text{fix}}/q_{\text{break}} > p_1/(1-p_1). A model that is right 80% of the time then needs a reviser that fixes a wrong answer four times as reliably as it breaks a right one.
  • Better models need sharper critics. The smallest likelihood ratio that helps is Λ⋆=p11−p1⋅qbreakqfix\Lambda^\star = \frac{p_1}{1 - p_1}\cdot\frac{q_{\text{break}}}{q_{\text{fix}}}. With qfix=qbreakq_{\text{fix}} = q_{\text{break}}, a 50% model needs Λ>1\Lambda > 1, an 80% model Λ>4\Lambda > 4, a 90% model Λ>9\Lambda > 9, and GPT-4 at 92.9% on GSM8K Λ>13.1\Lambda > 13.1. A critic that says "everything looks good" almost every time rarely flags anything, so revision barely moves accuracy either way. That is what Self-Refine saw on math, where ChatGPT's feedback said so 94% of the time and GPT-4's accuracy moved by 0.2 points.
  • Once a critic discriminates, false alarms matter most. Near the current critic, lowering the false-alarm rate by one point raises the plateau Λ\Lambda times as much as raising the detection rate by one point. For large changes the advantage of cutting false alarms is even bigger. The derivation below proves both.
∂ Why false alarms matter more than missed errors

Differentiate p⋆=pfix/(pfix+pbreak)p^\star = p_{\text{fix}}/(p_{\text{fix}} + p_{\text{break}}), with pfix=pdetqfixp_{\text{fix}} = p_{\text{det}}q_{\text{fix}} and pbreak=pfaqbreakp_{\text{break}} = p_{\text{fa}}q_{\text{break}}. By the quotient rule,

∂p⋆∂pdet=qfix pbreak(pfix+pbreak)2,∂p⋆∂pfa=−qbreak pfix(pfix+pbreak)2.\frac{\partial p^\star}{\partial p_{\text{det}}} = \frac{q_{\text{fix}}\,p_{\text{break}}}{(p_{\text{fix}} + p_{\text{break}})^2}, \qquad \frac{\partial p^\star}{\partial p_{\text{fa}}} = -\frac{q_{\text{break}}\,p_{\text{fix}}}{(p_{\text{fix}} + p_{\text{break}})^2}.

The ratio of their sizes is qbreakpfix/(qfixpbreak)=pdet/pfa=Λq_{\text{break}}p_{\text{fix}}/(q_{\text{fix}}p_{\text{break}}) = p_{\text{det}}/p_{\text{fa}} = \Lambda. So near the current critic, a small cut in false alarms moves the plateau Λ\Lambda times as far as the same small gain in detection.

For large changes, look at the shape of p⋆p^\star. As a function of pfap_{\text{fa}} alone, p⋆=pfix/(pfix+qbreakpfa)p^\star = p_{\text{fix}}/(p_{\text{fix}} + q_{\text{break}}p_{\text{fa}}) has the form a/(a+bx)a/(a + bx), which is convex (it curves upward). So a large cut in false alarms raises the plateau by more than the derivative predicts. As a function of pdetp_{\text{det}} alone, p⋆=qfixpdet/(qfixpdet+pbreak)p^\star = q_{\text{fix}}p_{\text{det}}/(q_{\text{fix}}p_{\text{det}} + p_{\text{break}}) has the form x/(x+c)x/(x + c), which is concave (it curves downward). So a large gain in detection raises it by less than the derivative predicts.

In practice this tells you where to spend effort. Before you build a self-review step, measure the critic's two rates on answers you have labeled and compute Λ\Lambda. Then compare Λqfix/qbreak\Lambda q_{\text{fix}}/q_{\text{break}} with the odds p1/(1−p1)p_1/(1-p_1). If it falls short, work on false alarms first. Interviewers often ask exactly this, in the form "your model is 90% accurate, should it check its own work?".

The cell checks the theorem by simulation. It runs critic-gated revision on 100,000 independent problems and compares the simulated accuracy after each round with the closed form. It does this for the example above, for a critic with no false alarms, and for a sharp critic of the kind unit tests provide.

Python · cell 1

The simulated and exact rows agree to within a few thousandths, the sampling noise at this size. The worked example sinks toward 0.714. The critic without false alarms climbs toward 1. The unit-test critic, with Λ=0.9/0.05=18\Lambda = 0.9/0.05 = 18, climbs toward its plateau p⋆=0.45/0.465=0.968p^\star = 0.45/0.465 = 0.968.

In the next widget you move the critic's two rates and the first-attempt accuracy, and each preset also sets the reviser's qfixq_{\text{fix}} and qbreakq_{\text{break}}. The left panel shows accuracy after each round of revision, with the plateau p⋆p^\star dashed. The right panel shades, for each likelihood ratio and first-attempt accuracy, whether revision helps or hurts. The presets are a prompted critic, oracle stopping, unit tests, and the measured rates of SCoRe, a trained self-correction method described at the end of the section.

When does asking a model to check its own work raise accuracy, and when does it lower it?
Each round a critic flags answers it thinks are wrong, and only flagged answers are revised.
Loading interactive figure…

The preset starts at Λ=1.5\Lambda = 1.5, and five rounds take accuracy from 0.80 down to 0.58. Raising detection to 0.5 gives 0.65, and lowering false alarms to 0.1 gives 0.72. The derivative alone would favor detection here, since a 0.1 cut in false alarms is worth only about 1.5×0.1=0.151.5 \times 0.1 = 0.15 of detection, less than 0.2. The cut wins anyway, because the plateau is convex in the false-alarm rate and concave in the detection rate. Neither change is enough. This reviser breaks more often than it fixes (qbreak=0.6q_{\text{break}} = 0.6 against qfix=0.4q_{\text{fix}} = 0.4), so the critic would need Λ>4×1.5=6\Lambda > 4 \times 1.5 = 6.

Core

When does a critic make revision pay?

Write three functions for critic-gated revision.

  • critic_chain(p1, p_det, p_fa, q_fix, q_break, m) returns pmp_m from the closed form, for any m≥1m \ge 1, so m=1 returns p1. It must handle pfa=0p_{\text{fa}} = 0, and the case pfix+pbreak=0p_{\text{fix}} + p_{\text{break}} = 0, without dividing by zero.
  • revision_helps(p1, p_det, p_fa, q_fix, q_break) returns True exactly when pm>p1p_m > p_1 for every m≥2m \ge 2.
  • min_likelihood_ratio(p1, q_fix, q_break) returns the threshold Λ⋆\Lambda^\star, so that revision helps exactly when Λ>Λ⋆\Lambda > \Lambda^\star. Return inf when no critic can help, which happens when qfix=0q_{\text{fix}} = 0 or p1=1p_1 = 1. Otherwise return 0.0 when p1=0p_1 = 0.

The starter's critic_chain revises every answer, flagged or not, and counts rounds with the wrong exponent. Those are the mistakes to fix.

Tests, hints, verified solutions, and AI help, with Pro at $7.99 a month.

The generation-verification gap

A critic can be used in a second way. Instead of rewriting the answers it rejects, sample several answers and keep only the ones it accepts. This is rejection sampling. Its close cousin best-of-nn keeps the one answer out of nn that the checker scores highest (§18.2). Filtering is also how the self-training loops later in this chapter build their data. A checker used this way is called a verifier, written gg. Two acceptance rates describe it. Its true positive rate TPRg\mathrm{TPR}_g is the chance that it accepts a right answer, and its false positive rate FPRg\mathrm{FPR}_g is the chance that it accepts a wrong one. What does filtering buy?

Start with numbers. A generator is right 80% of the time. Its verifier accepts 90% of right answers and 20% of wrong ones. Out of 100 samples it accepts 72 right ones and 4 wrong ones, so the kept answers are right 72/76=94.7%72/76 = 94.7\% of the time. Filtering raised accuracy by 14.7 points without touching the generator.

∂ Proof of the precision of a filter

By Bayes' rule, prec⁡=P(right∣accepted)=P(accepted∣right) P(right)/P(accepted)=p TPRg/A\operatorname{prec} = \mathbb{P}(\text{right}\mid\text{accepted}) = \mathbb{P}(\text{accepted}\mid\text{right})\,\mathbb{P}(\text{right})/\mathbb{P}(\text{accepted}) = p\,\mathrm{TPR}_g/A. Then

prec⁡−p=p TPRg−pAA=p(TPRg−p TPRg−(1−p) FPRg)A=p(1−p)(TPRg−FPRg)A.\operatorname{prec} - p = \frac{p\,\mathrm{TPR}_g - pA}{A} = \frac{p\big(\mathrm{TPR}_g - p\,\mathrm{TPR}_g - (1-p)\,\mathrm{FPR}_g\big)}{A} = \frac{p(1-p)(\mathrm{TPR}_g - \mathrm{FPR}_g)}{A}.

Since p(1−p)>0p(1 - p) > 0 and A>0A > 0, the sign of prec⁡−p\operatorname{prec} - p is the sign of TPRg−FPRg\mathrm{TPR}_g - \mathrm{FPR}_g, which proves all three equivalences at once. ∎

In plain words, any verifier that accepts right answers more often than wrong ones makes the kept answers more accurate than the raw ones. The gain is largest for middling pp and vanishes as pp approaches 0 or 1.

Now compare filtering with revision. A critic's flag is a rejection, so as a verifier it has TPRg=1−pfa\mathrm{TPR}_g = 1 - p_{\text{fa}} and FPRg=1−pdet\mathrm{FPR}_g = 1 - p_{\text{det}}. Then TPRg>FPRg\mathrm{TPR}_g > \mathrm{FPR}_g is the same as pdet>pfap_{\text{det}} > p_{\text{fa}}, that is, Λ>1\Lambda > 1.

The evidence later in this section confirms this twice. In an interview it is the answer to "why does best-of-nn with a mediocre verifier help when self-revision with the same verifier hurts?".

Song et al. 2024 turned this gain into the central measure of self-improvement. In words, the gap is how much better the answers get when the model's own samples are kept, or weighted, according to a verifier's scores. Their definition allows any way of using the scores, not only a pass or fail filter.

In plain words, the gap is the utility gained by keeping or weighting the model's samples by the verifier's scores. The relative gap measures that gain as a fraction of the room left to improve.

For a utility of 0 or 1 and a filter on one prompt, the gap is exactly prec⁡−p\operatorname{prec} - p from the theorem. The relative gap divides it by the room left, gap⁡rel=(prec⁡−p)/(1−p)=p(TPRg−FPRg)/A\operatorname{gap}_{\text{rel}} = (\operatorname{prec} - p)/(1 - p) = p(\mathrm{TPR}_g - \mathrm{FPR}_g)/A. In the 80% example above, the gap is 0.147 and the relative gap is 0.147/0.2=0.740.147/0.2 = 0.74. The relative version matters because the absolute gap of every verifier shrinks to 0 as p→1p \to 1. The relative gap instead tends to 1−FPRg/TPRg1 - \mathrm{FPR}_g/\mathrm{TPR}_g, a property of the verifier alone.

Why does the gap close? Filtering removes the errors the verifier can see, so what remains is more and more made of the errors it cannot see. The cell makes this a three-line model. Wrong answers come in two kinds. The verifier accepts detectable ones with probability 0.1, and undetectable ones as often as right answers. Each round keeps what the verifier accepts and trains the generator to reproduce exactly that mix.

Python · cell 2

The gap goes from 0.218 to 0.034 to 0.004, and accuracy stalls at 0.857, far short of 1, although the verifier is excellent on the errors it can see. On what is left, the verifier has TPRg=FPRg\mathrm{TPR}_g = \mathrm{FPR}_g, which is Λ=1\Lambda = 1, and the theorem says no amount of filtering helps. Only new information moves the plateau, such as a stronger verifier, ground-truth answers, tests, or tools. The rest of this chapter keeps asking where that new information comes from.

Core

The gap a verifier opens

A generator is right with probability p. A verifier accepts right answers with probability tpr and wrong ones with probability fpr. Write three functions.

  • filter_precision(p, tpr, fpr) returns the accuracy of the accepted answers.
  • gv_gap(p, tpr, fpr) returns the gap, that accuracy minus p.
  • relative_gap(p, tpr, fpr) returns the gap divided by 1−p1 - p.

Each returns float('nan') when nothing is ever accepted. relative_gap also returns nan when p=1p = 1, since there is no room left to improve.

Tests, hints, verified solutions, and AI help, with Pro at $7.99 a month.

Self-Refine, a loop that critiques and rewrites

The cleanest loop of this kind runs entirely at test time, while the model answers, with no training. It uses one model in three roles. Each role is set up by a few-shot prompt, a prompt that contains a handful of worked examples of that step. One prompt drafts, one gives feedback, and one rewrites. This is Self-Refine (Madaan et al. 2023).

In the language of the theorem, the feedback step is the critic, and its stop signal is the critic's verdict that nothing is wrong. So Self-Refine is critic-gated revision with a self-judged stop. It also shows the reviser every earlier draft and critique, so the rounds are not quite independent.

The paper's ablation shows how much rides on the critic. The authors replaced the specific, actionable feedback with generic feedback such as "improve the efficiency", and then with no feedback at all (Madaan et al. 2023, Table 2). Code Optimization with ChatGPT fell from 27.5 to 26.0 to 24.8. Sentiment Reversal with ChatGPT fell from 43.2 to 31.2 to 0. Acronym Generation with GPT-3.5 fell from 56.4 to 54.0 to 48.0. The same critique-and-revise move, run offline against written principles and then trained into the weights, is how Constitutional AI makes training data for harmlessness (§19.2).

Why do the gains pile up on some tasks and vanish on others? The next cell runs two toy tasks, each with Self-Refine's cap of 4 rounds and its stop signal.

  • Constrained generation. An answer must contain K=20K = 20 concepts, and the draft covers each with probability 0.6. The critic checks a list. It reports each missing concept with probability 0.9, invents a complaint about a present concept with probability 0.05, and stops when it has nothing to report. The reviser adds each reported concept with probability 0.9. While rewriting, it drops each unreported concept with probability 0.03.
  • Arithmetic. A first attempt is right 75% of the time. The critic flags 15% of wrong answers and 3% of right ones, so it says "looks good" about 94% of the time, as ChatGPT's math feedback did. The reviser fixes a flagged wrong answer with probability 0.6 and breaks a flagged right one with probability 0.5.
Python · cell 3

Coverage climbs from 0.600 to 0.976, while arithmetic accuracy moves from 0.745 to 0.759. Two things separate the tasks, and both are in the theorem. First, coverage is many cheap checks, each with a high likelihood ratio, and there are plenty of errors to find, since the first draft misses 40% of the concepts. Second, the arithmetic critic finds only 15% of the slips, so there is little to gain in the first place. And with three right answers for every wrong one, the right answers it breaks give back half of what its fixes gain.

Self-Refine's own appendix makes the same point from the other side. When an outside signal said which math answers were wrong, so that only those were refined, the gain for GPT-3.5 went from 0 to 4.8 points (Madaan et al. 2023, Table 9). That is oracle stopping again. So when someone proposes a refine loop, ask first how checkable the task is.

Reflexion, lessons written in words

An agent, as §24.1 defines it, is a model in a loop that observes, thinks, and acts until a task is done. Reflexion (Shinn et al. 2023) wraps that loop in an outer loop of whole attempts, called trials, and carries a lesson written in words from each failed trial to the next. §24.4 defined it and compared it with plain retries. Here is the recap in the terms this section needs.

Three roles, usually played by one model, share a memory. An actor attempts the task and produces a trajectory, the record of everything it did in one trial. An evaluator scores the trajectory, with the environment's success signal, a hand-written rule, an exact match against a reference, or unit tests the model wrote itself. After a failure, a self-reflection step writes a short lesson ("I assumed I was holding the mug, but I never picked it up") into a memory that keeps the last one to three lessons. The next trial reads the memory, and the loop stops when the evaluator reports success or a cap on trials is reached.

No weights change. The lesson does the job a gradient update would do in reinforcement learning, but it lives in the prompt, which is why the authors call it verbal reinforcement. It is a small case of the episodic memory of §25.3, a store of past experiences that an agent reads back. §24.4 asked what a lesson adds over a retry. This section asks a different question. In this section's terms the evaluator is the critic, so the way to read Reflexion's results is to ask which evaluator each experiment used.

  • Decision-making on AlfWorld, 134 household tasks in a text game. The environment reports only whether a task is complete, so a hand-written rule flags a trial that loops or runs past 30 actions. A completed task ends the loop and is never flagged, so this evaluator raises no false alarms. With it the agent completed 130 of 134 tasks over 12 trials, as §24.4 reported.
  • Question answering on HotpotQA, questions that need facts from two Wikipedia articles. Between trials, the answer was graded by exact match against the reference answer, so the loop knew which answers were wrong. By the definitions at the start of this section this is oracle stopping, and Huang et al. list it as such.
  • Programming on HumanEval and MBPP, two benchmarks of short Python functions checked by hidden unit tests. The evaluator is a suite of at most six unit tests that the model writes itself and filters for valid syntax. The hidden tests are used once, on the final program, so the reported pass@1 (the fraction of problems whose final program passes) is honest. Reflexion reached 91.0% on HumanEval against 80.1% for GPT-4 alone, but 77.1% on MBPP against the same 80.1%.

The precision theorem explains the difference. Among programs that passed the model's own tests, 1.4% were wrong on HumanEval and 16.3% on MBPP (Shinn et al. 2023, Table 2). So the self-tests had a precision of 98.6% on one benchmark and 83.7% on the other. With base accuracies near 80% on both, the self-tests opened a large gap on HumanEval and only a small one on MBPP. There, a wrong program that passed its own tests ended the loop early, and the loop finished 3 points below the baseline.

An ablation on the 50 hardest HumanEval problems, translated to Rust, told the same story (Shinn et al. 2023, Table 3). The base model scored 0.60, written reflections without tests 0.52, tests without written reflections 0.60, and both together 0.68. Reflection without a test signal is intrinsic self-correction, and it hurt. An interviewer who asks why Reflexion works on code wants this answer, the tests, and the false positives that limit them.

The next exercise turns the leak that Huang et al. found in the literature into an interview coding problem.

Interview

A Reflexion loop that never peeks at the hidden tests

A toy code model must implement clamp(x), which limits x to the range 0 to 10. The setup gives you four things.

  • CANDIDATES, a dict from candidate names to functions.
  • generate(task, memory, rng), which returns the name of a sampled candidate. It never returns a name already in memory, unless every candidate has been tried.
  • self_tests(task), the model's own unit tests as (input, expected) pairs. Some may be wrong or incomplete.
  • hidden_tests(task, name), the benchmark's tests, which return True when the named candidate is correct.

Write reflexion(task, max_trials, seed) in five steps, for any max_trials of at least 1.

  1. Create one rng = np.random.default_rng(seed).
  2. For at most max_trials trials, generate a candidate and run the self-tests on it. Stop at the first candidate that passes all of them.
  3. After each failure, append a reflection {"candidate": name, "failed": [indices of failing self-tests]} to memory.
  4. If no candidate passes, the final answer is the one that failed the fewest self-tests, the earliest of those on a tie.
  5. Only then call hidden_tests once, on the final answer, and return (final_name, trials_used, hidden_pass).

The starter is the leaky version. It runs, and it reports a better score than the honest loop, which is exactly the problem.

Tests, hints, verified solutions, and AI help, with Pro at $7.99 a month.

What the evidence says

Kamoi et al. 2024 surveyed the self-correction literature with the same distinctions this section draws. Their conclusions are worth memorizing.

That the critic, not the reviser, is the bottleneck has been measured directly. Tyen et al. 2024 built BIG-Bench Mistake, a set of step-by-step reasoning traces written by the PaLM 2 model, with the first logical error in each marked by people. They asked models to find the error. The best model, GPT-4, located it with 52.87% accuracy overall. Then they gave models the true location and let them backtrack, which means re-sampling the mistaken step and continuing from there.

Stechly, Valmeekam & Kambhampati 2024 measured the critic itself. GPT-4 generated solutions to four formal problems, and the same model verified them, with exact external checkers as ground truth. The problems were Game of 24 (combine four numbers with arithmetic to make 24), graph coloring, and two planning puzzles. The puzzles are Blocksworld and Mystery Blocksworld, which is the same puzzle with its words disguised. The cell converts their verifier statistics (Table 2) into this section's critic rates, where a rejection counts as a flag.

Python · cell 4

The same paper asked whether critique is needed at all, and found that it adds little. It asked the identical question again until the exact checker accepted an answer. With 15 samples, the same budget as the 15 rounds of feedback, it was ahead of the loop that was told "wrong", or within a point of it, in three domains, and behind it on Game of 24. The scores were 40% against 38% on graph coloring, 68% against 60% on Blocksworld, 9% against 10% on Mystery Blocksworld, and 28% against 36% on Game of 24. With 25 samples it beat that loop in every domain, and Game of 24 reached 42%. Its prompts also stay short, since they never carry earlier attempts. That is filtering with FPRg=0\mathrm{FPR}_g = 0, whose precision is 1 by the theorem. It succeeds whenever any sample is right, which is the coverage of §18.2.

The last lesson concerns compute. Self-correction spends extra model calls, so it must be compared with other ways of spending them. Huang et al. 2024 (Table 7) compared two ways to spend 9 responses on GSM8K. In multi-agent debate, three copies of a model answer and then critique each other's answers over two rounds. In self-consistency, the model answers 9 times independently and the majority answer wins. From a single-sample 76.7%, debate reached 83.0% and voting 88.2%. The gain from debate came from combining several answers, not from critique, and at equal cost the critique left it below plain voting. Debate as a way to supervise models stronger than their judges is a different question, taken up in §19.5. In practice, every self-correction loop you build must beat voting or best-of-nn at the same number of calls.

External feedback changes the critic

Every loop that worked so far had a critic that knew something the generator did not. In the theorem's terms, external feedback improves both ratios at once. It raises Λ\Lambda, because a failing test or a contradicting search result is rarely a false alarm. And it raises qfix/qbreakq_{\text{fix}}/q_{\text{break}}, because an error message says where to look.

  • Tools as the critic. CRITIC (Gou et al. 2024) lets the model call tools to check its draft and then revise from what they report. The tools are a search engine for facts, a Python interpreter for math, and a toxicity classifier for safety. On AmbigNQ, a set of open-domain questions with more than one reading, ChatGPT's F1 score (word overlap with the reference answer) went from 64.3 with step-by-step reasoning to 74.9 with CRITIC. It reached only 67.3 when the model had to write its own "evidence" without search. On GSM8K with Text-Davinci-003, solving by writing a program scored 70.1%, CRITIC with the interpreter 72.2%, and the same loop without the interpreter 68.3%, below where it started.
  • Execution results as the critic. Self-Debug (Chen et al. 2023) teaches a model, with few-shot examples, to explain its code line by line and to read the results of running it. Where unit tests exist (code translation and MBPP), it improved accuracy by up to 12%. On Spider, a text-to-SQL benchmark with no tests to run, it improved by 2 to 3%, and by 9% on the hardest problems. With feedback, it matched or beat baselines that sampled more than 10 times as many programs.
  • Execution feedback for training data. The Llama 3 team found that training their 405B model on its own generated code was "not helpful (and can even degrade performance)" (Llama Team 2024, Section 4.3.1). It started to help once they added execution feedback as a source of truth. Errors from a parser, a linter, and model-written unit tests were fed back for revision. Only dialogues that passed every check were kept, and about 20% of solutions had been wrong at first and were then corrected. That is critic-gated revision used to build training data, and §26.4 takes the pipeline apart.

The table sums up the trade-offs. They come down to where the critic's signal comes from and what it costs.

loopwhere the critic's signal comes fromneeds at test timemeasured effectwhat bounds it
prompted self-correctionthe model's own judgmentnothingGPT-4 GSM8K 95.5 to 91.5the model's Λ\Lambda on its own answers
Self-Refinethe model's own feedback on checkable aspectsnothingGPT-4 coverage 15.0 to 45.0, math 92.9 to 93.1how checkable the task is, the first prompt
Reflexionenvironment signal or self-written tests, turned into wordsa trial signalAlfWorld 130 of 134, HumanEval 91.0false positives of the signal
CRITIC, Self-Debugtools, interpreters, unit teststool accessAmbigNQ F1 64.3 to 74.9, up to 12% on codecoverage and correctness of the tools
resampling with an exact checkeran exact checker, no critiquea checkerGame of 24 5% to 42% at 25 samplescoverage, the chance some sample is right
self-consistencyagreement among sampleskk samplesGSM8K 76.7 to 88.2 at 9 sampleserrors the samples share
trained self-correction (SCoRe)a training-time answer checkernothingMATH Δ\Delta from −11.2-11.2 to +4.4+4.4the training distribution

Training a model to correct itself

If prompted critics are the bottleneck, the next idea is to train the model to correct itself. The obvious recipe is supervised fine-tuning (SFT), which trains the model to imitate given text, here traces in which an answer gets corrected. Kumar et al. 2024 showed carefully why it fails. They sampled many two-attempt traces from Gemini 1.5 Flash on MATH and tried two versions.

  • Filtered traces. Keep only traces that turned a wrong first answer into a right one, and fine-tune on them. This is the recipe of §26.3, which keeps a model's own samples that reached a right answer and trains on them, here applied to corrections.
  • Paired traces. Pair a wrong attempt with a right one for the same problem, as a synthetic repair, following Welleck et al. 2022. The authors call this Pair-SFT.

Recall that on 500 test problems the base model went from 52.6% at the first attempt to 41.4% at the second, a Δ\Delta of −11.2-11.2 points. Three rounds of the filtered recipe made the second attempt worse relative to the first (Δ=−14.2\Delta = -14.2). Adding traces where both attempts were right brought it to +0.4+0.4. Pair-SFT reached +1.8+1.8. Pair-SFT with both-right traces learned to change nothing at all, with no flips in either direction.

They traced the failure to two causes. The first is distribution shift. Offline traces correct the base model's mistakes, but once training changes the first attempt, the mistakes the model must fix at test time are different ones. The second is behavior collapse. Producing the best possible first answer and then making minimal edits scores as well on the training data as genuinely correcting. The first is easier to learn, so that is what the model learns. Training on the model's own fresh samples, called on-policy training, fixes the first cause but not the second. Plain reinforcement learning that rewarded only the second attempt collapsed the same way. Both attempts got better together, and the gap between them did not grow.

SCoRe, their method, uses reinforcement learning in two stages. §18.7 quoted its headline result, and here we take the method apart. It needs two terms from §15.7. A policy is the model viewed as a probability distribution over responses. A KL penalty charges the policy for drifting from a frozen reference model. The drift is measured by the KL divergence, a nonnegative number that is zero only when the two distributions are equal.

Why should the bonus have α>1\alpha > 1? Look at what it does to each kind of transition, and to the return as a whole.

Proof. The four values follow by substituting (r^(y1),r^(y2))∈{(1,1),(0,0),(0,1),(1,0)}(\hat r(y_1), \hat r(y_2)) \in \{(1,1), (0,0), (0,1), (1,0)\}. For the average, E[G]=Acc@t1+Acc@t2+α(Acc@t2−Acc@t1)\mathbb{E}[G] = \mathrm{Acc@t1} + \mathrm{Acc@t2} + \alpha(\mathrm{Acc@t2} - \mathrm{Acc@t1}). Substituting Acc@t2=Acc@t1+Δ\mathrm{Acc@t2} = \mathrm{Acc@t1} + \Delta gives 2 Acc@t1+Δ+αΔ2\,\mathrm{Acc@t1} + \Delta + \alpha\Delta. ∎

In plain words, without the bonus (α=0\alpha = 0) the objective is 2 Acc@t1+Δ2\,\mathrm{Acc@t1} + \Delta. A point of first-attempt accuracy is worth twice a point of improvement, so the easiest way up is a better first answer followed by no edits, which is behavior collapse. With α>1\alpha > 1, the weight 1+α1 + \alpha on Δ\Delta exceeds the weight 2 on first-attempt accuracy. Breaking a right answer (1−α<01 - \alpha < 0) also becomes worse than staying wrong (0). The bonus makes correcting the better strategy on the training set, which the plain objective failed to do.

The same identity hides a trap. In terms of the two accuracies, E[G]=(1−α) Acc@t1+(1+α) Acc@t2\mathbb{E}[G] = (1 - \alpha)\,\mathrm{Acc@t1} + (1 + \alpha)\,\mathrm{Acc@t2}, and for α>1\alpha > 1 the weight on first-attempt accuracy is negative. If the first attempt were trained on the whole return, the policy would learn to answer wrong on purpose and then fix it. That is why SCoRe credits each attempt only with its own reward. The first attempt is trained only to be right. For a given first attempt, the bonus makes a right second answer earn 1+α1 + \alpha more than a wrong one, instead of 1 more. So the bonus strengthens the training signal for the second attempt, and it is the second attempt that gets corrected.

The cell turns the published tables into rates and extrapolates each to later rounds with the constant-rate model. Read the extrapolations as what the rates imply, not as forecasts, since Figure 8 of the paper shows how far they can miss.

Python · cell 5

Every SCoRe row beats its base model on the break rate. On HumanEval SCoRe also nearly doubles the fix rate, from 0.171 to 0.319. Converting a published table into rates is quick. Estimating rates from your own logs of many rounds, with honest error bars, is a small research problem, and the next exercise does it.

Research

Fit fix and break rates from multi-round logs, and predict the plateau

You ran a self-correction loop for RR rounds on NN problems and logged a boolean matrix logs of shape (N, R). Entry logs[i, t] says whether problem i was right after attempt t + 1. Model each problem as a two-state Markov chain, a process that is right or wrong and moves between the two states with fixed probabilities each round. All problems share the same two probabilities.

  • fit_fix_break(logs) returns the maximum-likelihood (p_fix, p_break), pooling the transitions from every round to the next. Use nan for a rate that has no transitions to estimate it from.
  • predict_accuracy(logs, horizon) returns an array of the predicted accuracies after rounds R+1,…,R+horizonR + 1, \dots, R + \text{horizon}, starting from the observed accuracy in the last logged round. Treat a rate that cannot be estimated as 0. If no answer ever changes state, the prediction stays at that accuracy.
  • plateau_interval(logs, n_boot=1000, seed=0) returns a 95% percentile bootstrap interval (lo, hi) for the plateau p⋆p^\star. The bootstrap of §0.11 resamples the data with replacement and recomputes the estimate each time, and the interval runs from the 2.5th to the 97.5th percentile of those estimates. Resample problems (rows of logs), and skip resamples whose plateau is undefined.
Tests, hints, verified solutions, and AI help, with Pro at $7.99 a month.

Checking inside one chain of thought

Reasoning models do most of their self-correction inside a single chain of thought, the step-by-step reasoning a model writes before its answer. These are the "wait, let me re-check" passages of §18.5. This differs from prompted self-correction in two ways, and the theorem explains both.

First, the check is trained. Reinforcement learning with an outcome reward, a reward given only for a correct final answer (§18.3), credits only what the chain ends with. A re-check that catches an error raises the reward and is reinforced. A re-check that talks the model out of a right answer lowers the reward and is suppressed. So training raises Λ\Lambda and qfix/qbreakq_{\text{fix}}/q_{\text{break}} directly, against a true checker.

Second, the check happens before the answer is committed, so a false alarm costs tokens rather than a finished answer. §18.5 also records the caveat that base models already produced these behaviors, and training amplified them.

In PyTorch

The SCoRe objective is a few lines on top of a REINFORCE loss, the basic policy-gradient loss of §15.3. It raises the log-probability of each sampled response in proportion to how much better than average its return was. This sketch follows the equations above, not the authors' code. Like the paper, it credits each attempt only with its own terms, so the bonus never reaches the first attempt. It uses the sampled log-ratio as the KL estimate inside the reward, as in §15.7, and subtracts the batch mean as a baseline.

🔥 In PyTorchfor a machine with PyTorch

Stage 1 keeps the small second-attempt penalty beta1 and gives the first attempt only the strong penalty beta2, as in the definition. Passing g2 back into g1 would put the weight 1−α=−91 - \alpha = -9 on the first attempt's reward and teach it to fail. For α=10\alpha = 10 the four shaped returns are +2+2, 00, +11+11, and −9-9, and the average matches 2 Acc@t1+(1+α)Δ2\,\mathrm{Acc@t1} + (1 + \alpha)\Delta, as the theorem says. In a real run the log-probabilities come from a language model's forward pass on the sampled responses, and the reference model is frozen.

Read more

Watch next

🎬 Adv. LLM Agents MOOC | UC Berkeley Sp25 | Inference-Time Techniques for LLM Reasoning by Xinyun Chen · Berkeley RDIA lecture by the first author of Self-Debug and co-first author of Huang et al. The course page lists both papers as this lecture's readings, so it covers prompted self-correction against execution feedback from the source.
🎬 LLM Agents MOOC | UC Berkeley CS294-196 Fall 2024 | LLM Reasoning by Denny Zhou · Berkeley RDIDenny Zhou, a co-author of 'Large Language Models Cannot Self-Correct Reasoning Yet' (listed in the course syllabus as a reading for this lecture), on reasoning and why prompted self-correction falls short.
🎬 [1hr Talk] Intro to Large Language Models · Andrej Karpathy · starts at 38:02The 'Self-improvement, LLM AlphaGo' chapter (38:02). Self-improvement works where a checkable reward exists and stalls where it does not, which is this chapter's thesis in five minutes.