Back to all tools

DSPy
Programming — not prompting — LLMs with auto-optimized, declarative modules.
0Open Source
AI Agents
Overview
DSPy is a framework for algorithmically optimizing LLM prompts and weights, replacing hand-crafted prompts with declarative modules that are compiled and auto-optimized.
Key Features
- Declarative signatures instead of brittle prompt strings
- Automatic prompt optimization with teleprompters
- Built-in evaluation and metric-driven tuning
- Supports any LLM via OpenAI-compatible API
- ChainOfThought, ReAct, and MultiChainComparison modules
- Compiled programs that generalize across LLM versions
Real-World Workflows
Build a reliable multi-hop QA system
- 1Define a Signature: 'question -> answer' with context field
- 2Build a multi-hop module using DSPy's ChainOfThought
- 3Provide 20 labeled examples as training data
- 4Run BootstrapFewShot optimizer — DSPy writes the best prompts for you
Getting Started
pip install dspy
import dspy
lm = dspy.LM('openai/gpt-4o')
dspy.configure(lm=lm)
class QA(dspy.Signature):
question: str = dspy.InputField()
answer: str = dspy.OutputField()
cot = dspy.ChainOfThought(QA)
result = cot(question='What is the capital of France?')
print(result.answer)Compare Alternatives
See how DSPy stacks up against similar tools.