Pattern: evaluator–optimizer

In one sentence

One LLM generates, a second evaluates the output against explicit criteria and returns specific feedback, and the generator revises, looping until the output passes or a round limit is hit.

Analogy: A writer and an editor: the editor marks specific problems against the style guide, the writer revises, and the piece ships when the editor signs off or the deadline hits.

The loop converges only if feedback is specific and the evaluator is reliable; the round cap bounds cost and latency.

How it works

  • Two signs of fit: written human feedback improves the output, and an LLM can produce that feedback.
  • The best evaluation signal is external and deterministic: tests, compilers, schema validation, word counts.
  • Next best: a separate evaluator prompt with a rubric, often on a different model (LLM-as-a-judge).
  • Asking the same model "are you sure?" with no new information often fails to help, or hurts.
  • Each round costs at least two calls: log the score per round and cap at 2–4.

Check yourself

Answer to mark it learned; your answers aren't scored.

Your evaluator returns feedback like "improve clarity and flow". Drafts change every round, but scores bounce 3 → 4 → 3 and rarely pass. Best fix?

Go deeper

Full explanation

Evaluator–optimizer is a loop between two roles. The generator (optimizer) produces a draft. The evaluator checks it against explicit criteria and returns a verdict plus specific feedback ("line 3 switches from formal to casual", not "could be better"). The generator revises with that feedback, and the loop repeats until the evaluator passes it or a round limit hits, typically 2–4.

Anthropic names two signs of fit: a human's written feedback demonstrably improves the output, and an LLM can produce that same kind of feedback. Literary translation, constrained writing and multi-round search ("is the evidence complete yet?") qualify.

The loop is only as good as its evaluation signal:

  • Best: external, deterministic checks such as tests, compilers, schema validation or a word count (Code-based graders & assertions).
  • Good: a separate evaluator prompt with a rubric, often on a different model (LLM-as-a-judge).
  • Weak: the same model asked "are you sure?" with no new information. Research shows intrinsic self-correction on reasoning often fails to help and can make answers worse.

Each round costs at least two calls, so log the score per round; if round 3 rarely beats round 2, cap at 2.

Code Translation loop with a rubric evaluator and round cap
pythonTranslation loop with a rubric evaluator and round cap
from openai import OpenAI
from pydantic import BaseModel

client = OpenAI()
GEN_MODEL = "gpt-4.1"        # any strong writer
EVAL_MODEL = "gpt-4.1-mini"  # separate prompt, ideally another model: fewer shared blind spots

class Verdict(BaseModel):
    passed: bool
    score: int           # 1-5 on the rubric; log it per round
    feedback: list[str]  # specific, located fixes, never "make it better"

RUBRIC = "Latin-American Spanish, tú form; idioms by meaning; keep formality and product names."

def generate(prompt: str) -> str:
    r = client.chat.completions.create(model=GEN_MODEL, messages=[{"role": "user", "content": prompt}])
    return r.choices[0].message.content

def evaluate(source: str, draft: str) -> Verdict:
    r = client.chat.completions.parse(model=EVAL_MODEL, response_format=Verdict, messages=[
        {"role": "system", "content": f"Grade the translation strictly. Rubric: {RUBRIC}"},
        {"role": "user", "content": f"SOURCE:\n{source}\n\nTRANSLATION:\n{draft}"}])
    return r.choices[0].message.parsed

def translate(source: str, max_rounds: int = 3) -> str:
    prompt, best = f"Translate to Spanish. {RUBRIC}\n\n{source}", (0, "")
    for _ in range(max_rounds):              # hard cap bounds cost and latency
        draft = generate(prompt)
        verdict = evaluate(source, draft)
        best = max(best, (verdict.score, draft))
        if verdict.passed:
            return draft
        fixes = "\n- ".join(verdict.feedback)
        prompt = f"Revise the draft. Fix exactly these issues:\n- {fixes}\n\nSOURCE:\n{source}\n\nDRAFT:\n{draft}"
    return best[1]                           # out of rounds: best-scored draft, not the last one
Real example

A travel company localizes ~2,000 marketing strings per release into Latin-American Spanish. Single-pass translation kept literal idioms ("hit the road" → "golpear el camino") and mixed tú and usted. They added an evaluator with a 4-point rubric (idiom meaning, tú form, brand names untouched, length within 120% of the source so it fits the UI) and up to 3 rounds. ~70% passed in round 1, ~25% in round 2, and the rest went to a human reviewer. The human edit rate dropped from ~30% to ~8% of strings.

Trade-offs +3 · −3

+ You gain

  • Measurable quality gains on tasks with clear criteria, without changing the model.
  • Feedback is explicit and loggable, so you can see why an output changed.
  • Plugs in real verifiers (tests, compilers, validators) as the strongest evaluator.

− You pay

  • Each round is at least 2 sequential calls: latency and cost grow with rounds.
  • A miscalibrated evaluator optimizes toward its own quirks, not toward quality.
  • Revisions can regress: fixing one criterion breaks another that was passing.

Use it when

Quality criteria are explicit, an evaluator (tests, rules or a rubric-driven LLM) can check them reliably, and a round of feedback measurably improves the output: translation nuance, constrained writing, code against tests, multi-round search.

Avoid it when

There's no reliable evaluator, one pass already meets the bar, or the latency budget can't absorb 2–6 sequential calls. Never use self-critique as a substitute for ground truth.

Numbers to know 4
  • Self-Refine (2023): iterative self-feedback improved task performance by ~20% absolute on average across 7 tasks.
  • Reflexion (2023): feedback from test runs lifted HumanEval pass@1 to 91%, versus 80% for GPT-4 alone.
  • Huang et al. (2023): without external feedback, self-correction did not improve reasoning benchmarks and sometimes lowered accuracy.
  • Rule of thumb: cap at 2–4 rounds; most of the gain usually lands in the first one or two revisions.
Common pitfalls 4
  • Vague feedback (improve clarity): the generator can't act on it and the loop oscillates. Require specific, located fixes.
  • The same model and prompt grading its own work: shared blind spots, rubber-stamp passes. Use external checks or a separate evaluator.
  • Returning the last draft instead of the best-scored one: later revisions can be worse.
  • Never validating the evaluator against humans: you optimize toward its quirks. Rule of thumb: check agreement on ~100 labelled examples first.
Interview questions 3

Answer out loud first, then reveal.

When does an evaluator–optimizer loop actually improve output?Show answer

When two things hold: the criteria are explicit, and the feedback adds information the generator didn't use the first time. The strongest case is an external signal (failing tests, a compiler error, a schema violation), which is why coding agents iterate so well. A separate evaluator with a rubric also works for things like translation tone. What doesn't work reliably is asking the same model are you sure? on reasoning; studies found that can make answers worse. So I log score per round and cap where the curve flattens.

How do you keep the loop from running forever or making things worse?Show answer

Three guards. A hard round cap, usually two or three, sized from the per-round score curve on my eval set. Keep the best-scored draft, not the last one, because revisions regress: a tone fix can break a constraint that was fine. And stop on no progress: if the score doesn't rise or the feedback repeats, return best-so-far or escalate to a human. I also budget latency explicitly, since three rounds can mean six sequential calls.

How is this different from using an LLM judge in offline evals?Show answer

Same kind of component, different place. Offline, the judge measures the system and its errors skew a metric. In the loop it sits in the request path, so its errors ship: a judge that rewards verbosity makes every answer longer. It also has to be fast and cheap enough to run per request. And I can't reuse that same judge to evaluate the system afterwards, because it would be grading its own homework; I keep an independent judge or human labels for evals.