What problem does it solve?
DSPy replaces brittle, hand-written prompt chains with a declarative way to define LM programs and then optimize them using examples and evaluation metrics.
Core Features & Use Cases
- Declarative signatures for LM tasks: Define inputs/outputs for classification, extraction, QA, and structured generation.
- Composable modules for multi-stage systems: Build pipelines for RAG, agents (ReAct), multi-hop reasoning, and code-assisted computation.
- Automatic prompt optimization: Improve performance with teleprompters like BootstrapFewShot and MIPRO using a user-defined metric.
- Strong practical patterns: Structured outputs, retrieval + generation, reranking, verification loops, and evaluation tooling.
Use it when you need dependable research workflows (e.g., RAG + reranking) or agentic systems that must be improved systematically rather than by repeated manual prompt tweaking.
Quick Start
Tell your AI coding agent: "Install DSPy, define a QA signature, implement a retrieval-augmented module with DSPy.Retrieve and ChainOfThought, then optimize the module with BootstrapFewShot using a correctness metric."