What problem does it solve?
DSPy solves the problem of brittle, labor-intensive prompt engineering by letting you define model behavior declaratively and improve it automatically using data and evaluation metrics.
Core Features & Use Cases
- Declarative LM programming with Signatures: define inputs and outputs as reusable task schemas rather than writing one-off prompts.
- Modular multi-step systems: compose Predict, ChainOfThought, ProgramOfThought, ReAct, and retrieval modules into RAG and agent workflows.
- Automatic prompt optimization and few-shot compilation: use teleprompters/optimizers (e.g., BootstrapFewShot, MIPRO, BootstrapFinetune) to search for better instructions using a validation metric.
- Use Case: build a multi-hop RAG agent that retrieves relevant passages, generates an answer, and then optimizes the prompting strategy on labeled question-answer pairs for higher accuracy.
Quick Start
Use DSPy to compile an optimized question-answering module from your training examples by calling the relevant teleprompter compile method and providing a metric that checks answer correctness.