🤖AI RepoIndex
🧩 AI FrameworksOpen SourceFree

DSPy

Programming—not prompting—language models. Declarative specs compiled to optimized prompts.

4.6/ 520,000 GitHub starsPythonMIT

📋 Overview

DSPy is a Stanford open-source framework that treats LLM programming as a compilation problem — you write declarative specifications of what you want (signatures, modules, metrics), and DSPy compiles them into optimized prompts, few-shot examples, and retrieval strategies. Unlike LangChain (which chains prompts manually) or prompt-engineering tutorials (which rely on trial-and-error), DSPy uses Bayesian optimization and MIPROv2 to automatically find the best prompt structure, examples, and chain-of-thought patterns for your task. It supports any LLM (OpenAI, Anthropic, Gemini, Ollama) and includes built-in modules for RAG, multi-hop reasoning, and agent loops.

✨ Key Features

  • 36K+ GitHub stars — Stanford NLP framework
  • Declarative programming: write specs, not prompts
  • Automatic prompt optimization via MIPROv2 and Bayesian optimization
  • Built-in modules: ChainOfThought, ReAct, Retrieve, multi-hop
  • Any LLM support: OpenAI, Anthropic, Gemini, Ollama
  • Optimizer searches prompt space, few-shot examples, CoT patterns
  • Compiled programs are versionable and deployable

🎯 The Problem It Solves

Prompt engineering is fragile — a prompt that works for GPT-4 fails on Claude, and a prompt that works today breaks after model updates. DSPy eliminates manual prompt engineering by treating prompts as optimizable parameters, automatically finding the best formulation for your specific task and model.

🔧 How It Works

You define Signatures (input/output specs), Modules (ChainOfThought, ReAct, Retrieve), and Metrics (accuracy, F1, custom). DSPy then runs an optimizer (MIPROv2, BootstrapFewShot) that searches the space of prompt formulations, few-shot examples, and chain-of-thought patterns to maximize your metric. The result is a compiled program that can be saved, versioned, and deployed. The framework handles caching, batching, and parallel evaluation automatically.

🚀 Installation & Quick Start

Installation

See website

Quick Start

  1. See documentation

✅ Pros

  • Eliminates manual prompt engineering
  • Automatic optimization finds better prompts than humans
  • Declarative specs are model-agnostic
  • Built-in RAG and multi-hop reasoning modules
  • Any LLM support — no vendor lock-in
  • MIT licensed — completely free
  • Active Stanford research backing

❌ Cons

  • Steep learning curve — paradigm shift from prompting
  • Optimizer can be slow (hours for complex tasks)
  • Abstraction can feel limiting for simple use cases
  • Documentation assumes ML/optimization knowledge
  • Newer framework — smaller community than LangChain

💬 Practitioner Verdict

DSPy is the most promising approach to systematic LLM development — the declarative paradigm is genuinely better than manual prompt engineering, and the optimizers deliver measurable improvements. The trade-off: steep learning curve, the optimizer can be slow (hours for complex tasks), and the abstraction can feel limiting for simple use cases. For teams building production LLM applications, DSPy is the future.
1

Self-Hosted (Free)

Open source, MIT/Apache licensed. Run it yourself.

⭐ Star & Clone on GitHub

Free forever. Your infrastructure, your data.

3

Deployment Options

Ways to run DSPy in production

📊 Specifications

Language
Python
License
MIT
Platform
Linux, macOS, Windows
Supported Models
REST API, CLI

💰 Pricing Reality

100% free MIT license. No paid tier. You supply your own LLM API keys. Optimizer runs locally on your hardware.

👥 Community Health

Stars20,000
Forks2,500
Contributors400
Health Score9/10

🏷️ Tags

Open SourceFree