DSPy: The framework for programming—not prompting—language models
DSPy: The framework for programming—not prompting—language models
DSPy is the framework for programming—rather than prompting—language models. It allows you to iterate fast on building modular AI systems and offers algorithms for optimizing their prompts and weights, whether you're building simple classifiers, sophisticated RAG pipelines, or Agent loops.
DSPy stands for Declarative Self-improving Python. Instead of brittle prompts, you write compositional Python code and use DSPy to teach your LM to deliver high-quality outputs. Learn more via our official documentation site or meet the community, seek help, or start contributing via this GitHub repo and our Discord server.
Please go to the DSPy Docs at dspy.ai
pip install dspyTo install the very latest from main:
pip install git+https://github.com/stanfordnlp/dspy.gitIf you're looking to understand the framework, please go to the DSPy Docs at dspy.ai.
If you're looking to understand the underlying research, this is a set of our papers:
[Jul'25] GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learning
[Jun'24] Optimizing Instructions and Demonstrations for Multi-Stage Language Model Programs
[Oct'23] DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines
[Jul'24] Fine-Tuning and Prompt Optimization: Two Great Steps that Work Better Together
[Jun'24] Prompts as Auto-Optimized Training Hyperparameters
[Feb'24] Assisting in Writing Wikipedia-like Articles From Scratch with Large Language Models
[Jan'24] In-Context Learning for Extreme Multi-Label Classification
[Dec'23] DSPy Assertions: Computational Constraints for Self-Refining Language Model Pipelines
[Dec'22] Demonstrate-Search-Predict: Composing Retrieval & Language Models for Knowledge-Intensive NLP
To stay up to date or learn more, follow @DSPyOSS on Twitter or the DSPy page on LinkedIn.
The DSPy logo is designed by Chuyi Zhang.
If you use DSPy or DSP in a research paper, please cite our work as follows:
…[Bug] BootstrapFewShot loses teacher demos after a teacher exception
[Bug] Signature.insert/prepend/append silently drops a field whose name exists in the other section
[Bug] ParallelEvaluate `causes cannot schedule new futures after shutdown on long evals`
Proposal: optional durable memory via MemCode
[Bug] ParallelExecutor drops a task result equal to "cancelled"
[Bug] FAISS retrieval can return the last corpus passage for a missing candidate
Prediction/Example fields named items/keys/values/get/... return methods instead of stored values
[Bug] 3.4.0: importing litellm after dspy fails with circular import in openai (lazy openai proxy) when numpy is installed and litellm < 1.102
[Bug] Reserved <<CUSTOM-TYPE-*-IDENTIFIER>> markers leak into assistant messages when a custom Type is an output field in demos or History
[Bug] PythonInterpreter: SyntaxError message is always empty