DSPy is a framework for programming—not prompting—language models. Instead of writing brittle prompts that break with model updates, you write modular Python code that DSPy compiles into optimized prompts or finetunes.
Think of it as moving from "prompt engineering" to "prompt programming."
GEPA (Generalized Evolutionary Prompt Adaptation) is DSPy's reflective prompt optimizer. It works by:
- Running your program on training examples
- Analyzing which attempts succeed and which fail
- Reflecting on patterns in successes/failures
- Evolving the prompt to incorporate winning strategies
As the DSPy documentation puts it: GEPA can "precompute reasoning" to come up with a good plan for future task instances.
This notebook (dspy-gepa-tutorial.ipynb) provides hands-on experience with DSPy's GEPA optimizer through two practical examples:
- Optimize a simple
dspy.ChainOfThoughtprogram on AIME (American Invitational Mathematics Examination) problems - Learn how GEPA automatically discovers effective problem-solving strategies
- See 10%+ improvement in accuracy through optimization
- Build a
dspy.ReActagent with access to a Python code execution tool - Learn how GEPA can optimize when and how agents use tools
- Understand the interplay between reasoning and tool use
- Python 3.13+
- OpenAI API key
- Basic familiarity with Python
- Install dependencies with uv:
uv sync- Start MLFlow UI (in a separate terminal):
mlflow ui --port 5000 --backend-store-uri sqlite:///mlruns.db- Open the notebook and run the cells:
jupyter notebook dspy-gepa-tutorial.ipynbBy the end of this notebook, you'll understand:
- How to define DSPy programs with Signatures and Modules
- How to create evaluation metrics (including feedback metrics for GEPA)
- How to use GEPA to automatically optimize prompts
- How to build and optimize tool-using agents
- How to track experiments with MLFlow
