6 Optimizing prompt instructions
This chapter covers
- DSPy’s instruction optimization
- The
COPRO,MIPROv2,InferRules,SIMBA,GEPA, andEnsembleoptimizers - 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 prompts, we can look at the other side of DSPy optimization: crafting prompt instructions. We discuss the optimizers DSPy provides to support this work: 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 language model (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 multistep applications, so the findings may not be relevant to simpler cases (such as the airline classifier) or even to other complex applications, because each can be a bit different. We’ll look at optimizing complex workflows in chapter 7, but for now, we introduce the optimizers and demonstrate how they can be applied in more straightforward scenarios.