DSPy: The Framework for Programming—Not Prompting—Language Models
DSPy is Stanford NLP's framework for programming—not prompting—language models. Automatically optimize your LLM pipelines with 35k+ stars on GitHub.
What Is DSPy?
DSPy (Declarative Self-improving Python) is a groundbreaking open-source framework from Stanford NLP that fundamentally rethinks how we build applications with large language models. Instead of writing fragile, hand-crafted prompts and hoping they work, DSPy lets you program your LLM pipelines declaratively and then compiles them into optimized, self-improving programs. With over 35,000 stars on GitHub, it has become one of the most influential tools in the LLM ecosystem.
Why DSPy Matters
Traditional LLM development involves endless prompt engineering — tweaking wording, adding examples, adjusting temperature, all without any guarantee of improvement. DSPy eliminates this by treating prompts as optimizable parameters. You define the structure of your program (inputs, outputs, modules), and DSPy automatically finds the optimal prompts, chain-of-thought patterns, and model calls for your specific task and data.
Key Features
Declarative Modules: Build complex LLM pipelines from reusable components like dspy.Predict, dspy.ChainOfThought, dspy.ReAct, and dspy.MultiChainComparison. Each module encapsulates a specific reasoning pattern.
Automatic Optimization: DSPy includes a compiler that optimizes your program using labeled data. It can tune prompts, few-shot examples, chain-of-thought demonstrations, and even the structure of your program itself.
Multi-Provider Support: Works with OpenAI, Anthropic, Cohere, Google, Together AI, Replicate, Ollama (local), and any OpenAI-compatible endpoint. Switch providers with a single line of code.
Retrieval Integration: Built-in support for RAG through dspy.Retrieve and integration with popular vector databases. DSPy optimizes the entire retrieval-generation pipeline together.
Teleprompters: Advanced optimizers like BootstrapFewShot, BootstrapFewShotWithRandomSearch, BayesianSignatureOptimizer, and KOALA automatically improve your program based on validation metrics.
Who Is DSPy For?
DSPy is ideal for data scientists, ML engineers, and Python developers who want to build reliable, production-quality LLM applications without the fragility of manual prompt engineering. It is particularly powerful for RAG pipelines, multi-hop QA systems, classification tasks, and complex reasoning chains where prompt quality significantly impacts results.
Real-World Applications
DSPy has been used in production for building advanced RAG systems with automatic retrieval optimization, creating reliable classification pipelines for enterprise data, developing multi-step reasoning agents that outperform hand-prompted alternatives, and powering academic research on LLM optimization. Its modular architecture makes it easy to integrate into existing Python codebases and MLOps workflows.