DSPy
A framework for programming language models with optimisable modules instead of hand-written prompts.
DSPy reframes the work: instead of hand-tuning prompt strings, you declare modules with typed inputs and outputs and let DSPy compile and optimise the prompts against a metric and examples.
It is a genuinely different mental model (closer to programming than prompting) and it shines when you have data to optimise against and care about squeezing out quality systematically.
Where it fits
A fit when prompt quality is critical, you have examples to optimise against, and you want that tuning done by a compiler rather than by hand.
Where it does not fit
The learning curve and the need for evaluation data make it heavy for a simple, one-off prompt.
Alternatives to DSPy
The closest options on the map, and where each fits instead.
-
LangGraph Graph orchestration
Reach for LangGraph when an agent needs real branching (loops, retries, human-in-the-loop pauses) and you want that control flow written down explicitly.
Unlike DSPy Maturity: established
-
Pydantic AI Type-safe agent framework
A strong fit for Python teams who want agent code that is statically typed and whose outputs are validated by construction.
Pairs with
Commonly used alongside it.
