DSPy
Framework from Stanford NLP for programming — rather than hand-prompting — LLM pipelines, with optimisers that tune prompts and weights.
In DSPy you declare what each module should do through signatures (inputs and outputs) and compose modules in Python. Optimisers then compile the program against a metric and example data, generating better prompts or fine-tuning weights automatically. This makes LLM pipelines more systematic and less dependent on fragile prompt strings.
- Type
- AI framework
- Category
- AI & ML
- Maintainer
- Stanford NLP and community
- First released
- 2023
- License
- Open source (MIT)
- Pricing
- Open source
- Level
- Advanced
- Technologies
- python, llm, prompt-engineering
- GitHub stars
- 39,386
- Weekly downloads
- 1,987,138 (pypi)
- Latest release
- [object Object]
- Last verified
- 26 Nov 2026
What DSPy is used for
- Optimising prompts against a metric
- Building modular RAG and classification pipelines
- Research on LM programs
Strengths
- Metric-driven optimisation
- Model-agnostic
- Encourages evaluation discipline
Limitations
- Requires labelled examples and a metric
- Different mental model from chains
DSPy alternatives
How it relates to other tools
- DSPy works with OpenAI API
- DSPy works with Claude API (Anthropic)
- DSPy works with Ollama