DSPy, from Stanford, treats prompting as an optimisation problem. You declare what you want as signatures and modules, supply examples, and DSPy compiles the actual prompt. When the model changes, you recompile rather than rewrite.
Reach for it when
- Your prompts are long, brittle and hand tuned
- You have examples and a metric to optimise against
- You change models often
Look elsewhere when
- You have one simple prompt that already works
- You need to read and edit the prompt by hand
What the lessons will cover
- 01Install and setup
- 02Signatures
- 03Modules
- 04Predict and ChainOfThought
- 05Metrics
- 06Optimisers and compiling
- 07Evaluation
- 08An optimised pipeline
Others in data and rag
Common questions
Is DSPy free to use?
DSPy is open source and free to run yourself. You still pay whichever model provider you point it at, and this tutorial is free with no signup.
Do I need to know Python to use DSPy?
Basic Python is enough. Functions, dictionaries and imports cover most of what DSPy asks of you.
When should I not use DSPy?
You have one simple prompt that already works. You need to read and edit the prompt by hand.
Lessons for DSPy are being written. Meanwhile the LangGraph tutorial covers the same ground: state, tools, loops, memory and human approval. Most of it carries straight over.
Start the LangGraph tutorial →