Skip to main content
This guide explains how to use an LLM judge to automatically generate rich textual feedback for GEPA optimization, making it easier to optimize complex tasks where manual feedback rules are hard to codify.

The Pattern

Instead of manually writing feedback rules, use another LLM to evaluate the output and reasoning:

Why Use LLM-as-a-Judge?

  • Subjective quality assessment (writing style, helpfulness, clarity)
  • Complex reasoning evaluation (is the logic sound?)
  • Tasks where rules are hard to codify
  • Analyzing reasoning quality beyond just answer correctness

Complete Example Walkthrough

Full Working Example

See the complete implementation with step-by-step comments

1. Task Signature with Reasoning

2. Judge Signature

3. Optimized Module

4. TypedMetric with Judge

GEPA itself does not own a special feedback_metric hook anymore. The feedback function lives in your TypedMetric implementation, and GEPA enforces that every evaluation returns MetricOutcome::with_feedback(...). That keeps the optimizer generic while preserving full judge-driven behavior.

Key Benefits

The judge identifies when the model got the right answer for the wrong reasons.
The judge recognizes valid methodology even when the final answer is wrong.
The judge notices patterns like:
  • “Model consistently skips showing intermediate steps”
  • “Model confuses similar concepts (area vs perimeter)”
  • “Model doesn’t check units in answers”
GEPA’s reflection can then say:
“Add explicit instruction to show all intermediate steps and verify units”

Cost Considerations

LLM judges double your evaluation cost since every prediction requires both a task LM call and a judge LM call.
Budget accordingly:

Optimization Tips

  • Use a cheaper model for judging (gpt-4o-mini vs gpt-4)
  • Judge only failed examples (not ones that passed)
  • Cache judge evaluations for identical outputs
  • Use parallel evaluation to reduce wall-clock time

Hybrid Approach

Best results often come from combining explicit checks with LLM judging:

Example Evolution

When you run the example, GEPA will evolve prompts based on judge feedback:
1

Baseline

Instruction: “Solve the math word problem step by step”Result: Some solutions skip stepsJudge: “Reasoning incomplete, jumped from step 2 to answer”
2

After GEPA

Instruction: “Solve step by step. Show ALL intermediate calculations. Label each step clearly.”Result: Complete solutions with all steps shownJudge: “Sound reasoning, all steps shown clearly”
The judge’s analysis becomes the signal that drives prompt improvement.

Running the Example

This will show:
  1. Baseline performance
  2. Judge evaluations during optimization
  3. How feedback evolves the prompt
  4. Final test with judge analysis