GEPA is DSPy’s reflective prompt optimizer. It runs a program, reads scores and feedback, proposes revised instructions, and tests candidate programs.
The official walkthrough uses a haiku-writing agent. Its metric can return a dspy.Prediction containing both score and feedback. The feedback explains a failure so the next instruction proposal has more to work with than a number.
What each part does
- The task model runs the program being improved.
- The reflection model studies examples, results, and feedback to propose instructions.
- The training set supplies examples for those updates.
- The validation set guides candidate selection.
- A final test set stays outside both steps.
The walkthrough uses dspy.GEPA, a separate reflection_lm, and a light optimization budget. Its compile call passes both trainset and valset. Omitting validation deliberately allows the training examples to guide selection too.
Try this after the classifier baseline
Turn a recurring classification error into specific feedback. An article mentioning an AI product may still be about an unrelated subject. Feedback should identify that policy error and the evidence for it.
Run one bounded optimization experiment. Compare the saved baseline and candidate on the same untouched examples. Inspect both corrected mistakes and newly introduced mistakes.
Record task-model calls, reflection calls, elapsed time, and total cost. A cheaper task model can still require an expensive search.
Caveat: the walkthrough’s improvements belong to its haiku task and settings. They do not predict gains for this classifier.
Use the optimizer selection guide to compare GEPA with demonstration-based approaches. Return to the learning path.