DSPy: programming, not prompting
DSPy is an open source Python framework (MIT license) that came out of Stanford NLP and lets you program language models instead of hand-tuning prompts. You describe what each step should produce, and optimization algorithms find the best instructions and examples based on your data.
Data as of October 22, 2026
Key figures
| Developer | Stanford NLP |
|---|---|
| Type | Code |
| Languages | Python |
| Open source | Yes |
| License | MIT |
| First release | 2023 |
| Suggested level | Advanced |
| Use cases | RAG, workflows, data |
| Self-hostable | Yes |
| Business model | Free |
| Cloud offering | No |
| Multi-agent | Not disclosed |
| MCP support | Yes |
| Bring your own model | Yes |
| Official site | Official site · Documentation · Repository |
GitHub
| Repository | stanfordnlp/dspy |
|---|---|
| GitHub stars | 38,734 |
| Forks | 3,442 |
| Latest code activity | October 22, 2026 |
| Latest release | 3.4.1 (October 12, 2026) |
GitHub activity checked on October 22, 2026.
The problem DSPy tackles
When you build an app on a large language model, you can lose hours tweaking fragile prompts: change one sentence or upgrade the model, and quality drops. DSPy, which started at Stanford NLP in late 2022 and is now driven by a large open source community, offers another route: write modular Python code and let algorithms work out the best way to talk to the model. Think of it as automated prompt engineering.
Three ideas to grasp
- Signatures: you declare the inputs and outputs of a step (say, a support ticket in, an urgency level and a team out) without writing the prompt.
- Modules: interchangeable strategies for running a signature, such as Predict (direct answer), ChainOfThought (step-by-step chain-of-thought reasoning) or ReAct (reasoning plus tools).
- Optimizers: given examples and a metric, they automatically tune the instructions and examples sent to the model (MIPROv2, BootstrapFewShot, GEPA and others), and can even fine-tune model weights.
Typical uses
DSPy works for anything from a simple classifier to a multi-step RAG pipeline or an agent loop. Common goals: moving to a cheaper model without losing quality, making information extraction more reliable, or keeping a system reproducible when you switch providers. Model calls go through a layer that supports many providers, which makes those switches easier.
Getting started
Install the dspy package with pip (Python 3.10 or later), configure the model you want to use, then write a first signature and run it through a module. The next step is to gather a small set of examples and a metric so you can run an optimizer. The official tutorials follow exactly that path.
Strengths and limits
Strengths: a rigorous, measurable approach, model independence and a foundation in published research.
Limits: the learning curve is real, since you have to think in signatures and metrics; optimization burns through many model calls; and DSPy provides no UI, no hosting and no ready-made multi-agent orchestration.
Alternatives
LangChain and LangGraph for orchestrating agents, Pydantic AI for typed outputs, and Haystack for production RAG pipelines.
Frameworks of the same type
- LlamaIndex · RAG, data, workflows
- Agno · multi-agent, workflows, RAG
- Amazon Bedrock Agents / AgentCore · multi-agent, RAG, workflows
- BeeAI Framework · multi-agent, workflows, RAG
- CAMEL · multi-agent, data, automation
- Haystack · RAG, chatbot, workflows
Frequently asked questions
What does DSPy stand for?
According to the official repository, DSPy stands for Declarative Self-improving Python. You declare what you want, and the system improves itself using examples and a quality metric.
Can DSPy build agents?
Yes. The ReAct module lets you build agents that reason and call tools, including tools exposed through MCP. DSPy's real specialty, though, is optimization: making an existing system more reliable or cheaper to run.
Do I need a lot of data to optimize?
You need at least a handful of representative examples and a way to score answers (a metric). How much more you need depends on the optimizer and on how hard the task is; the documentation covers each case.
Is there a paid version of DSPy?
No. DSPy is fully open source and there's no official paid cloud offering. Your only costs are model calls, and an optimization run can make a lot of them.
Data sources
- github.com
- dspy.ai
- pypi.org
- GitHub — Repository metadata: GitHub
Data as of October 22, 2026
Report an error
Does a figure, a date or a fact look wrong? Tell us: every report is checked.