DSPy (Declarative Self-improving Python) is an open-source framework originally from Stanford NLP (now maintained with Databricks involvement) that replaces handcrafted prompt strings with composable Python modules. Developers define input/output signatures and DSPy automatically compiles and optimizes prompts or fine-tunes weights using a small set of labeled examples via bootstrapping. It is suited for building robust RAG pipelines, classifiers, multi-hop reasoning chains, and agent loops that need to be maintainable and auto-optimized across model updates. Key features: - Declarative signatures replace manual prompt engineering - Automatic prompt optimization via bootstrapping from labeled examples - Support for fine-tuning model weights as an optimization target - Modular pipeline composition: chains of typed LLM modules - Built-in support for RAG, multi-hop reasoning, and agent loops - Model-agnostic: works with OpenAI, Anthropic, local models, and more
Free and open-source (MIT license). Available on PyPI and GitHub (github.com/stanfordnlp/dspy).
