DSPy Documentation
by DSPy (Stanford NLP)
Declare what your LLM should do, write a metric, and let an optimizer compile the prompts for you.
Overview
DSPy is a Python framework from Stanford NLP that replaces hand-written prompt strings with structured programs: you declare a task as a typed signature, compose signatures into modules, and let an optimizer generate and tune the underlying prompts against a metric you define. The documentation is organized as Overview, Getting Started, Diving Deeper, Tutorials, API Reference, Community and FAQ, and the getting-started path builds a haiku program up from roughly four lines of Python before layering on tools, metrics and optimization. The module catalogue covers Predict, ChainOfThought, ReAct, CodeAct, ProgramOfThought, MultiChainComparison, Parallel, Refine and BestOfN; the optimizer catalogue covers MIPROv2, GEPA, SIMBA, COPRO, BootstrapFewShot with its random-search and finetune variants, BetterTogether, InferRules and the KNN few-shot family. Around forty tutorials are grouped into building programs, optimizing them, reflective prompt evolution with GEPA, experimental RL optimization, deployment and observability, and real-world examples such as multi-hop RAG, entity extraction, financial analysis and MCP tool use. The project is MIT-licensed, has been developed publicly since January 2023, carries roughly 36,600 GitHub stars and 439 contributors, and is currently on the 3.3 beta line with commits landing this week. It is documentation rather than a course: there is no video, no assessment and no fixed sequence, so you learn by running the tutorials against your own task.
At a Glance
- Topic
- Frameworks
- Level
- Advanced
- Format
- Documentation
- Cost
- Free
- Duration
- Self-paced; ~4-6 hours to work the getting-started and optimization paths
- Provider
- DSPy (Stanford NLP)
- Hands-on
- Yes — code/exercises
- Certificate
- None
What You’ll Learn
- ✓Declare LLM tasks as typed signatures instead of hand-written prompt strings
- ✓Compose Predict, ChainOfThought and ReAct modules into multi-step programs
- ✓Write evaluation metrics that an optimizer can actually optimize against
- ✓Run MIPROv2, GEPA and SIMBA to compile and tune prompts automatically
- ✓Build multi-hop RAG and entity-extraction pipelines from the tutorial set
- ✓Wire MCP tools, caching, streaming and async into a DSPy program
- ✓Save, reload and deploy a compiled program, with tracing for debugging
Highlights
- •Optimizers replace prompt engineering — the docs argue a small tuned model can match a hand-prompted frontier one
- •Roughly forty runnable tutorials, including GEPA reflective prompt evolution and experimental RL optimization
- •MIT-licensed and developed in the open since January 2023; ~36,600 GitHub stars and 439 contributors
- •Maintained by Stanford NLP, with the 3.3 beta line current and active commits
- •Honest caveat: practitioners writing publicly about DSPy describe a steep on-ramp — the abstractions force a different way of thinking before anything gets easier
Who It’s For
Best For
- ✓Engineers whose prompt strings have become unmaintainable across a multi-step pipeline
- ✓Teams that want to swap model providers without rewriting every prompt
- ✓Researchers and practitioners doing systematic prompt optimization against a metric
- ✓Anyone building RAG or agent pipelines that must be evaluated, not just demoed
Prerequisites
- •Solid Python, including type hints and class composition
- •Prior experience shipping at least one LLM application end to end
- •Comfort defining an evaluation metric and a small labelled dataset for it
FAQ
What is DSPy Documentation?
The official documentation for DSPy, the Stanford NLP framework for programming language models instead of prompting them. It teaches signatures, modules and automatic prompt optimizers, backed by roughly forty runnable tutorials. Work through it and you can build a multi-step LLM pipeline whose prompts are compiled and tuned against a metric rather than hand-written and hand-tweaked.
Is DSPy Documentation free?
DSPy Documentation is free to access.
What level is DSPy Documentation for?
DSPy Documentation is aimed at a advanced audience. Recommended background: Solid Python, including type hints and class composition, Prior experience shipping at least one LLM application end to end, Comfort defining an evaluation metric and a small labelled dataset for it.
How long does DSPy Documentation take?
Expect roughly Self-paced; ~4-6 hours to work the getting-started and optimization paths. Most learners work through it at their own pace.
What will I learn from DSPy Documentation?
You'll learn: Declare LLM tasks as typed signatures instead of hand-written prompt strings; Compose Predict, ChainOfThought and ReAct modules into multi-step programs; Write evaluation metrics that an optimizer can actually optimize against; Run MIPROv2, GEPA and SIMBA to compile and tune prompts automatically; Build multi-hop RAG and entity-extraction pipelines from the tutorial set; Wire MCP tools, caching, streaming and async into a DSPy program; Save, reload and deploy a compiled program, with tracing for debugging.
Topics
Sources
This page was written from 4 sources, 2 on domains other than dspy.ai.