6 Optimizing prompt instructions
This chapter covers
- DSPy’s instruction optimization
- The COPRO, MIRPOv2, InferRules, SIMBA, GEPA, and Ensemble optimizers
- How DSPy uses grounding to create better instructions
- How DSPy applies Hill Climbing, Bayesian Optimization, and Genetic Algorithms
Now that we’ve covered optimizing the demonstrations included in the prompts, we can look at the other side of DSPy optimization, crafting the prompt instructions. We’ll discuss the optimizers DSPy provides to support this: COPRO, MIPROv2, InferRules, SIMBA, and GEPA. Each optimizes prompts in a different way, so they are all worth trying for your projects.
SIMBA and GEPA were introduced in DSPy version 3, and are now generally considered the strongest optimizers, though this depends on the type of task and the LM. None is strictly stronger than the others, and it’s common to try multiple optimizers before determining the best prompt for each task. Some evaluations have compared different optimizers, but most have looked at complex multi-step applications, so the findings may not be relevant to simpler cases (such as the airline classifier) or even other complex applications, as each can be a bit different. We’ll look at optimizing complex workflows in chapter 7, but for now, we’ll introduce the optimizers and demonstrate how they can be applied in more straightforward scenarios.