What problem does it solve?
dspy removes brittle manual prompt engineering and ad-hoc LM calls by providing a declarative, modular programming model for language models that makes pipelines reproducible, testable, and optimizable.
Core Features & Use Cases
- Declarative Signatures & Modules: Define inputs and outputs with typed signatures and compose Predict, ChainOfThought, ProgramOfThought, and ReAct modules into reusable pipelines.
- Automatic Prompt Optimization: Improve performance using built-in optimizers (BootstrapFewShot, MIPRO, BootstrapFinetune) and custom metrics for few-shot and instruction tuning.
- RAG & Agent Integration: Build retrieval-augmented generation, multi-stage QA, and agentic systems with retrieval, reranking, and tool use while exporting optimized modules for production.
- Use Case: Create a multi-hop RAG system that generates search queries, retrieves supporting documents, reranks passages, and produces concise, validated answers for research or customer support.
Quick Start
Use dspy to declare a QA signature, wire a retriever and a ChainOfThought generator, and run a question through the pipeline to get a concise, validated answer.