Favicon of DSPy

DSPy

Open-source Python framework for building modular LLM systems, with typed outputs, tool-using agents, and automatic prompt optimization. MIT licensed.

Screenshot of DSPy website

DSPy is a Python framework for developers building AI applications whose tasks need clear inputs, predictable output types, and measurable results. You define what a language model should produce, then compose those tasks into a larger program. It's open source under the MIT license.

Its central abstraction is a signature: a task description with typed inputs and outputs. That can describe extracting contact details from an email, assigning a support ticket to a team, or identifying claims in an article. Separate modules determine how the model handles the task, so the same definition can work with direct generation, step-by-step reasoning, or an agent that calls tools.

DSPy's optimizers use examples and a scoring function to improve prompts automatically. The framework also includes algorithms for optimizing model weights. This makes it relevant to developers comparing approaches against a defined metric, including classification, retrieval-augmented generation, and agent workflows. Optimized programs can be saved for reuse.

Programs use ordinary Python control flow to connect multiple model calls. Agents can call Python functions for knowledge-base searches or calculations, and image inputs support tasks such as chart analysis. DSPy works with OpenAI models, whose inference runs through a cloud service; the Python framework is the application layer. Its reusable task definitions let developers change execution strategies without rewriting the task itself.

Similar to DSPy