Skip to content
AgenticAIWiki
  1. Learn
  2. Part 8
  3. 41. Workflow patterns
  4. 41.5

Lesson 41.5 · 5 of 5 · 6 min read · Reviewed 24 Nov 2026

Evaluator-optimizer

By the end, you can

  • Set up a generate, evaluate, revise loop.
  • Know when evaluator-optimizer is worth its cost.

In evaluator-optimizerEvaluator-optimizer: A pattern where one call produces an output and another evaluates it and asks for improvements, in a loop., a generator produces a draft, an evaluator judges it against explicit criteriaExplicit criteria: Concrete, checkable rules in a prompt that define what a good answer is, instead of vague words like "good" or "concise"., and the generator revises using the feedback. The loop runs until the evaluator approves.

Example

Translating legal text: the generator translates, the evaluator checks terminology against a glossary and flags any clause whose meaning shifted, and the generator fixes those clauses.

When it fits

Two signs this pattern will help:

  1. You can write down clear evaluationEval: A repeatable test that measures how well an AI system performs on a set of cases with defined success criteria. criteria. “Make it better” is not a criterion; “every defined term matches the glossary” is.
  2. A human giving the same feedback would actually improve the result.

Design notes

  • Always cap the rounds. Without a limit, a picky evaluator and a stubborn generator can loop forever.
  • Ask the evaluator for specific, actionable feedback, not just a score.
  • The evaluator can be a different prompt, a different model, or deterministic code (a test suite is an excellent evaluator for generated code).

Choosing among the five

Start with one call. Add the simplest pattern that fixes a measured problem. Reach for an agentAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done. only when even the steps cannot be decided in advance.

Key points

  • One call generates; another evaluates against explicit criteria and gives feedback.
  • The loop repeats until approval or a round limit.
  • Works when clear criteria exist and feedback measurably improves the result.
Hands-on labRuns in the Playground

Loop a generator and evaluator with a cap

Build an evaluator-optimizer loop with explicit criteria, actionable feedback and a hard round limit.

You will have: A loop that fixes a translation against a glossary, plus a second run that hits the round cap and returns the best draft.

Steps

  1. Read the glossary and the stand-in generator: it fixes only the terms the feedback names.
  2. Write evaluate(draft) as deterministic code: list every source term whose required translation is missing.
  3. Loop: generate, evaluate, feed back the specific missing terms, until approved or the round cap.
  4. Run a second time with a stubborn generator that ignores feedback, and stop at the cap.
  5. Print the rounds used and the outcome for both runs.

Done when

  • The normal run is approved in 4 rounds, one glossary term fixed per round.
  • The stubborn run stops at the cap of 5 rounds and says so.
  • Feedback names specific terms, not just a score.

Open in the Playground No API key needed.

Starter code (Python)
GLOSSARY = {"supplier": "fournisseur", "liability": "responsabilité", "termination": "résiliation"}
source = "The supplier accepts liability until termination."

def generate(feedback, previous, stubborn=False):
    draft = previous or "Le prestataire accepte la faute jusqu'à la fin."
    if stubborn:
        return draft
    # fixes one named term per round, like a real model often does
    if feedback:
        term = feedback[0]
        wrong = {"supplier": "prestataire", "liability": "faute", "termination": "fin"}[term]
        draft = draft.replace(wrong, GLOSSARY[term])
    return draft

def evaluate(draft):
    # TODO: return the glossary terms whose required translation is missing from the draft
    return []

def loop(max_rounds=5, stubborn=False):
    draft, feedback = None, []
    # TODO: generate, evaluate, stop on approval or at max_rounds
    return "TODO"

print(loop())
Show a solution
GLOSSARY = {"supplier": "fournisseur", "liability": "responsabilité", "termination": "résiliation"}
source = "The supplier accepts liability until termination."

def generate(feedback, previous, stubborn=False):
    draft = previous or "Le prestataire accepte la faute jusqu'à la fin."
    if stubborn:
        return draft
    # fixes one named term per round, like a real model often does
    if feedback:
        term = feedback[0]
        wrong = {"supplier": "prestataire", "liability": "faute", "termination": "fin"}[term]
        draft = draft.replace(wrong, GLOSSARY[term])
    return draft

def evaluate(draft):
    return [term for term, fr in GLOSSARY.items() if term in source.lower() and fr not in draft]

def loop(max_rounds=5, stubborn=False):
    draft, feedback = None, []
    for rnd in range(1, max_rounds + 1):
        draft = generate(feedback, draft, stubborn)
        feedback = evaluate(draft)
        print(f"  round {rnd}: missing {feedback or 'nothing'}")
        if not feedback:
            return f"approved in {rnd} rounds: {draft}"
    return f"hit the {max_rounds}-round cap; returning best draft for review"

print("normal:", loop())
print("stubborn:", loop(stubborn=True))
Quick checkYou add an evaluator-optimizer loop to a translation step. What must you also add?
How sure are you?
Pick an answer and how sure you are

Finished the chapter? Take the chapter check.