Skip to content
aicoolies logo
DSPy logo

DSPy

Programming — not prompting — LLMs

Declarative framework from Stanford University for programming language models rather than prompting them. DSPy treats LLM interactions as programmable modules with input-output signatures and uses optimization algorithms to automatically compile these modules into effective prompts or fine-tuned weights, replacing brittle prompt strings with structured, modular AI software.

About DSPy

DSPy is a declarative framework from Stanford University for programming language models rather than prompting them, enabling developers to build modular AI software using structured code instead of brittle prompt strings. It solves the fundamental challenge of prompt engineering by treating LLM interactions as programmable modules with defined input-output signatures, then using optimization algorithms to automatically compile these modules into effective prompts or fine-tuned weights. DSPy shifts the paradigm from manually crafting prompts to declaring what you want and letting the framework figure out how to achieve it through systematic optimization.

DSPy applications are built using three core components: language models, signatures that declare program inputs and outputs, and modules that define the prompting technique. The framework provides optimizers that automatically improve pipelines by tuning prompts, adjusting instructions, adding optimal few-shot examples, or fine-tuning the model weights to maximize performance on specified metrics. DSPy supports building everything from simple classifiers to sophisticated RAG pipelines and agent loops, with composable modules that can be combined with different models, inference strategies, or learning algorithms for maximum flexibility.

DSPy is designed for AI researchers, machine learning engineers, and developers building LLM-powered applications who want to move beyond manual prompt engineering to systematic, reproducible optimization of their AI pipelines. It integrates with major model providers and can be used alongside other frameworks for retrieval, evaluation, and deployment. The framework is particularly valuable for teams working on production systems where prompt reliability and performance consistency are critical, as DSPy optimizers can automatically discover prompt configurations that outperform hand-tuned alternatives.

Pricing & Platform Specs

Pricing Summary

Open-source declarative framework from Stanford NLP for programming and automatically optimizing LLM pipelines (MIT). 100% free with $0 software cost; users only incur standard token costs from their underlying model providers during compilation and inference.

full pricing breakdown →

Supported Platforms

Python

Explore categories, tags & use cases

Alternatives

All DSPy alternatives →

Framework for LLM applications

The most widely-used framework for building LLM-powered applications, available in Python and JavaScript. Provides abstractions for chains, agents, RAG, memory, tool usage, and structured output. Integrates with 100+ LLM providers, vector stores, document loaders, and tools. LangSmith offers tracing and evaluation. LangGraph enables stateful, multi-agent workflows with cycles. 100K+ GitHub stars. The de facto standard for LLM application development despite growing alternatives like LlamaIndex.

freemiumOpen Source

LLM testing and evaluation toolkit

Promptfoo is an OpenAI-owned open-source toolkit for evaluating, red-teaming and securing LLM applications. It supports config-driven prompt/model tests, CI regression gates, red-team scans, guardrails, model security workflows, MCP Proxy, code scanning and evaluations across prompts, agents and RAG pipelines.

freemiumOpen Source

Structured LLM outputs with validation

Instructor is the most popular Python library for extracting structured, validated data from large language models, with over 3 million monthly downloads and ports across Python, TypeScript, Go, Ruby, Elixir, and Rust. It uses Pydantic models to define output schemas and automatically handles validation, retries, and error correction when the LLM output does not match. Instructor patches existing client libraries instead of replacing them, preserving full access to the underlying API.

Open Source

Side-by-Side Comparisons

DSPy logo
DSPy
vs
LangChain logo
LangChain

DSPy vs LangChain — Programmatic Prompt Optimization vs LLM Orchestration Framework

DSPy and LangChain represent two fundamentally different philosophies for building LLM-powered applications. LangChain provides an orchestration layer that connects language models to external tools, data sources, and custom logic through chains and agents. DSPy, developed at Stanford and backed by Databricks, takes a programmatic approach where prompts are treated as optimizable programs rather than handcrafted strings.

Ell logo
Ell
vs
DSPy logo
DSPy

Ell vs DSPy — Prompt Versioning and Visualization vs Algorithmic Prompt Optimization

Ell and DSPy both improve how developers work with LLM prompts, but from opposite angles. Ell treats prompts as versioned Python functions with a TensorBoard-like studio for tracking evolution. DSPy treats prompts as programs to be algorithmically optimized through compilers and evaluators. This comparison helps ML engineers choose between human-driven prompt engineering and machine-driven prompt optimization.

EllDSPy

Community experience

Sources & verification

Sources checked
Content verified

Verification dates are editorial checks. Routine CMS saves and automatic updatedAt timestamps do not advance them.

FAQ

What is DSPy?

Declarative framework from Stanford University for programming language models rather than prompting them. DSPy treats LLM interactions as programmable modules with input-output signatures and uses optimization algorithms to automatically compile these modules into effective prompts or fine-tuned weights, replacing brittle prompt strings with structured, modular AI software.

Is DSPy free?

Yes — DSPy is open source and free to use. Open-source declarative framework from Stanford NLP for programming and automatically optimizing LLM pipelines (MIT). 100% free with $0 software cost; users only incur standard token costs from their underlying model providers during compilation and inference.

Is DSPy open source?

Yes — DSPy is open source.

Is DSPy still maintained?

Yes — DSPy is active. Its listing was last verified on September 6, 2026.

What are the best DSPy alternatives?

The first editor-selected DSPy alternatives are LangChain, Promptfoo, Instructor.