DSPy is an open-source Python framework developed by Stanford NLP researchers and released in 2023. It lets developers declare pipelines that use large language models as programs rather than hand-written prompts, and then automatically improves those prompts and model weights with optimization algorithms. Its core building blocks are signatures that define inputs and outputs, modules that encapsulate reasoning strategies, and optimizers that refine prompts using examples and evaluation metrics.
The name is presented as an abbreviation of Declarative Self-improving Python, and the framework grew out of the earlier Demonstrate-Search-Predict (DSP) research. DSPy is used for retrieval-augmented generation, classification, information extraction, and agent pipelines, and is often applied to obtain consistent, structured outputs across different LLMs.