What problem does it solve?
Building robust, modular AI systems often requires brittle manual prompt engineering, ad-hoc chains, and time-consuming tuning; dspy provides a declarative layer and automated optimization to make LM-based pipelines predictable, maintainable, and improvable with data.
Core Features & Use Cases
- Declarative Signatures & Modules: Define tasks as signatures and compose reusable modules such as Predict, ChainOfThought, ReAct, and ProgramOfThought to express complex workflows.
- Automatic Prompt & Few-Shot Optimization: Improve prompts and demonstrations programmatically using optimizers like BootstrapFewShot, MIPRO, and BootstrapFinetune.
- RAG, Agents, and Pipelines: Build retrieval-augmented systems, tool-using agents, multi-stage pipelines, reranking, and verification loops for production reliability.
- Evaluation and Integration: Includes evaluation utilities, custom metrics, LM provider configuration (OpenAI, Anthropic, local models), saving/loading optimized modules, and patterns for batching, caching, and monitoring.
- Use Case: Create an optimized RAG question-answering system that retrieves documents, reranks passages, and iteratively improves prompts from labeled QA data.
Quick Start
Use dspy to define a signature and assemble a RAG pipeline that retrieves documents, composes context, and returns concise answers.