Express AI tasks as typed Python modules instead of ad hoc prompts. Includes optimizers that tune prompts and weights against your metrics.
Overview
DSPy is a Python framework for building modular programs on top of language models rather than hand-tuning single prompts. The name reflects declarative, self-improving Python: you define tasks with structured signatures and wire them with modules such as predictors, chain-of-thought, ReAct loops, and custom pipelines.
Signatures describe typed inputs and outputs for each step, which keeps tasks portable and easier to refactor. Modules swap execution strategies—direct completion, reasoning steps, tool use, or multimodal fields—without rewriting the underlying task definition.
Optimizers compile programs against user-provided metrics and training examples, automatically adjusting prompts or configurations. Research-backed algorithms such as GEPA are part of the toolkit for improving quality on classification, retrieval-augmented generation, agents, and multimodal flows.
The project targets Python 3.10+ and integrates bundled language-model backends. Documentation and community channels support adoption in research and production-style AI engineering.
Key features
- Typed task signatures
- Composable modules and agents
- Prompt and program optimizers
- ReAct and tool calling
- Multimodal signature fields
- Metric-driven compilation
- RAG and classifier pipelines
- Python 3.10+ package
Use cases
- Structured LLM classifiers
- RAG pipelines with tuning
- Agent loops with tools
- Event or entity extraction
- Fact-checking multi-step flows