In this tutorial, we explore how GEPA, a reflective prompt-evolution framework, can enhance language model performance on arithmetic word problems. Starting from a weak seed prompt, we build a small deterministic benchmark, define a structured evaluator, and feed actionable feedback to GEPA to help it understand why a candidate prompt fails. We also evolve a multi-component prompt where both instructions and output format rules adapt. Finally, we compare baseline and optimized prompts on a held-out validation set and analyze the improvement.
Installing GEPA and LiteLLM
We install the necessary libraries and configure the API key, task model, and reflection model. The task model solves the arithmetic problems, while the reflection model refines the prompt. The optimization budget is set to 100 metric calls.
Creating a Deterministic Benchmark
We generate 18 arithmetic problems spanning four categories: discounts, travel distance, wallet calculations, and chained operations. Each problem has a programmatically computed correct answer. The set is shuffled and split into 12 training and 6 validation items.
Defining the Evaluator and Feedback
We construct a function that builds the system prompt from candidate instructions and format rules, calls the task model, and parses the output. The evaluator returns a score (1.0, 0.5, or 0.0) along with structured feedback explaining errors—wrong answer, format violation, or reasoning slip. This feedback is passed to GEPA for iterative improvement.
Running the Optimization
With the configuration in place, we run GEPA to evolve the prompt over multiple generations, using the training set for evaluation and feedback. The reflection model analyzes performance and suggests edits to both instructions and format rules.
Validating the Optimized Prompt
After optimization, we test the new prompt on the held-out validation set. The optimized prompt shows a significant increase in exact correct answers and average score compared to the baseline, demonstrating the effectiveness of reflective evolution with structured feedback.