DSPy is Stanford’s framework for programming — not prompting — language models, with 38,000+ stars on GitHub, turning fragile hand-written prompts into modular, self-optimizing Python programs.
Hand-tuned prompts break every time you change models or data. DSPy (Declarative Self-improving Python, from Stanford NLP) replaces them with code: you declare what a step should do with a Signature, compose steps into Modules such as chain-of-thought or ReAct agents, and let DSPy’s optimizers automatically compile the prompts and few-shot demonstrations that make your program hit its metric. The framework grew out of a line of peer-reviewed research, most recently GEPA (2025), a reflective prompt-evolution optimizer reported to outperform reinforcement learning approaches for prompt optimization. Because programs are model-agnostic Python, the same pipeline can be re-optimized when you swap the underlying LM. DSPy is widely used for serious RAG pipelines, agent loops and classifiers where quality must be measured and improved systematically rather than vibes-tested. Documentation lives at dspy.ai, and the project is actively maintained as of October 2026.
DSPy is free and open source under the MIT license. The only cost is inference: you pay your chosen model provider’s API rates, or nothing when running local models.
Developers and researchers building production LM systems — RAG, agents, classification — who want prompts that are optimized by data and metrics instead of maintained by hand.