Advanced

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

DeveloperStanford NLP
TypeCode
LanguagesPython
Open sourceYes
LicenseMIT
First release2023
Suggested levelAdvanced
Use casesRAG, workflows, data
Self-hostableYes
Business modelFree
Cloud offeringNo
Multi-agentNot disclosed
MCP supportYes
Bring your own modelYes
Official siteOfficial site · Documentation · Repository

GitHub

Repositorystanfordnlp/dspy
GitHub stars38,734
Forks3,442
Latest code activityOctober 22, 2026
Latest release3.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

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

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.