DSPy is a declarative programming framework designed for building complex language model applications. It treats model interactions as modular, composable programs, allowing developers to define task logic through typed class schemas rather than relying on manually written prompts. By organizing workflows into hierarchical, reusable Python objects, the framework enables the construction of sophisticated AI systems that manage state and execution flow independently.
The framework distinguishes itself through an automated optimization engine that iteratively refines prompt instructions and few-shot demonstrations. By evaluating candidate programs against defined metrics and feedback loops, it systematically improves performance without requiring manual prompt engineering. This process is supported by a programmatic evaluation harness that measures output quality using custom metrics and model-based judges, ensuring consistent behavior across multi-stage pipelines.
Beyond core orchestration, the system provides a robust interface for structured data extraction and tool integration. It includes mechanisms for wrapping Python functions as tools, executing iterative reasoning loops, and adapting model outputs into validated data structures. These capabilities are complemented by comprehensive state management and persistence utilities, which allow for the versioning and tracking of program configurations throughout the development lifecycle.