The Research Report
DSPy 3.2.0: Stanford Turns Prompt Engineering Into Actual Programming
Release Date: April 21, 2026
GitHub Stars: 34,391
Contributors: 37
Files Changed: 182
Commits: 105
The Problem DSPy Solves
Most people build LLM applications by hand-crafting prompts. They tweak wording, add examples, adjust temperature, and hope the model behaves consistently. This is fragile. A prompt that works on GPT-4o fails on Claude 3.7. A prompt that works today breaks tomorrow when the model updates.
Stanford NLP's DSPy (Declarative Self-improving Python) treats this as a software engineering problem, not a creative writing exercise. Version 3.2.0, released on April 21, 2026, doubles down on this philosophy with stricter types, better optimizers, and cleaner architecture.
The project's GitHub star count sits at 34,391. That number matters. It signals that developers are tired of prompt hacking and want something systematic.
What DSPy Actually Is
DSPy is a framework for programming language models. You define what you want, not how to ask for it. You specify inputs, outputs, and types. The framework figures out the prompting strategy, the few-shot examples, and the instruction wording.
Think of it like SQL. You write a query describing the data you want. The database engine decides how to execute it. DSPy applies the same separation of concerns to LLM calls.
The Core Building Blocks
Signatures define the input/output contract. They look like function signatures, but they declare behavior, not just data types.
A simple question-answering signature:
"question -> answer"
A retrieval-augmented signature with typed fields:
"context: list[str], question: str -> answer: str"
A classification signature with constrained output:
"sentence -> sentiment: Literal['sadness', 'joy', 'love', 'anger', 'fear', 'surprise']"
Field names carry semantic weight. A field called question tells the optimizer something different from a field called query. The names guide the prompt construction.
Modules are the executable units. dspy.Predict is the simplest. dspy.ChainOfThought adds a reasoning step. dspy.ReAct gives the model tools to use. You compose these into larger programs.
Optimizers (formerly called teleprompters) are the engine. They tune your program's parameters, prompts, or model weights to maximize a metric you define.
What's New in 3.2.0
Typed Functions and Runtime Validation
The biggest user-facing change is type checking. In 3.2.0, passing the wrong type to a signature field triggers a warning.
class MathSignature(dspy.Signature):
"""Perform a mathematical operation."""
number: int = dspy.InputField()
result: str = dspy.OutputField()
predictor = dspy.Predict(MathSignature)
predictor(number="42") # Warning: expected int, got str
This works through typeguard. Extra fields not declared in the signature also warn. You can disable this with dspy.configure(warnontype_mismatch=False), but you probably shouldn't.
This matters because type safety catches errors early. A string where an integer belongs might slide through a prompt and produce garbage output. The warning surfaces the bug before the LLM sees it.
The type system supports:
- Basic types:
str,int,bool - Collections:
list[str],dict[str, int],Optional[float] - Pydantic models for nested structures
- Special DSPy types:
dspy.Image,dspy.History
Duplicate field names are now rejected. The framework won't let you declare the same name as both input and output.
BetterTogether: Chaining Optimizers
The BetterTogether meta-optimizer got a major upgrade. It now accepts arbitrary optimizers as keyword arguments and chains them via strategy strings.
BetterTogether(
metric=m,
p=GEPA(...),
w=BootstrapFinetune(...),
strategy="p -> w -> p"
)
This runs prompt optimization, then fine-tuning, then prompt optimization again. Each step evaluates on a validation set. The best program wins.
The insight here is that prompt optimization and weight optimization complement each other. Prompt optimization discovers effective reasoning strategies. Fine-tuning specializes the model to execute those strategies efficiently. Running them in sequence lets each build on the other's improvements.
Decoupling From LiteLLM
Maxime Rivest led an effort to remove the hard LiteLLM dependency. Adapters no longer import litellm at all. BaseLM now exposes capability properties:
supportsfunctioncallingsupports_reasoningsupportsresponseschemasupported_params
A new dspy.ContextWindowExceededError replaces the LiteLLM-specific error throughout the codebase. Custom backends can plug into DSPy's retry and truncation logic without dragging in LiteLLM.
This is architectural hygiene. It makes DSPy more portable and easier to integrate with custom model deployments.
Hardened RLM and PythonInterpreter
The Remote Language Model (RLM) and Python interpreter tooling got reliability fixes:
- Tool calls use kwargs-only dispatch
- The JavaScript tool bridge returns structured errors instead of crashing Deno
- Stdout parsing skips non-JSON lines instead of failing
- Subprocess restarts replay tool and mount registration correctly
These are production concerns. When your system runs code or calls remote tools, crashes cascade. The fixes make the execution environment more predictable.
Security: Restricted Pickle for Disk Cache
A new dspy.configurecache(restrictpickle=True) setting swaps pickle.load for a restricted unpickler. It only allows litellm/openai types, numpy reconstruction helpers, and user-registered safe types.
This prevents arbitrary code execution from corrupted or malicious cache files. The team plans to make this the default in a future release.
Optional Optuna
Optuna moved from required to optional (pip install dspy[optuna]). This saves 12.7 MB. Only MIPROv2 and BootstrapFewShotWithOptuna need it.
How Optimizers Work
DSPy optimizers are the feature that separates it from other LLM frameworks. They take three inputs:
- Your program (single module or complex pipeline)
- Your metric (a function scoring output quality)
- Training inputs (can be as small as 5-10 examples, inputs only, no labels needed)
The optimizer then systematically improves your program.
BootstrapFewShot
The simplest optimizer. It uses your program as a teacher to generate demonstrations. It runs the program on your training inputs, collects input/output traces for each module, and keeps only the traces that score well on your metric.
MIPROv2
More sophisticated. It runs in three stages:
- Bootstrapping: Run the program many times to collect high-scoring traces
- Grounded proposal: Preview your code, data, and traces, then draft candidate instructions for every prompt
- Discrete search: Sample mini-batches, propose instruction/trace combinations, evaluate, and update a surrogate model to guide better proposals
An informal benchmark on HotPotQA with GPT-4o-mini raised a ReAct agent from 24% to 51% accuracy.
GEPA
GEPA (Generative Engine for Prompt Adaptation) uses the LLM to reflect on your program's trajectories. It identifies what worked, what didn't, and proposes prompts addressing the gaps. It can also leverage domain-specific textual feedback.
BootstrapFinetune
This distills a prompt-based program into weight updates. The output is a program with the same steps, but each step runs through a fine-tuned model instead of a prompted one.
An informal run on the Banking77 dataset with GPT-4o-mini raised accuracy from 66% to 87%.
BetterTogether
The meta-optimizer that composes the others. It can run sequences like:
- Prompt optimization → Fine-tuning → Prompt optimization
- Multiple GEPA steps in sequence
- Any combination you specify via strategy strings
A Practical Example
Here's a minimal ReAct agent optimized with MIPROv2:
import dspy
from dspy.datasets import HotPotQA
# Configure the language model
dspy.configure(lm=dspy.LM('openai/gpt-4o-mini'))
# Define a search tool
def search(query: str) -> list[str]:
"""Retrieves abstracts from Wikipedia."""
results = dspy.ColBERTv2(url='http://20.102.90.50:2017/wiki17_abstracts')(query, k=3)
return [x['text'] for x in results]
# Load training data
trainset = [x.with_inputs('question') for x in HotPotQA(train_seed=2024, train_size=500).train]
# Define the agent
react = dspy.ReAct("question -> answer", tools=[search])
# Optimize
tp = dspy.MIPROv2(metric=dspy.evaluate.answer_exact_match, auto="light", num_threads=24)
optimized_react = tp.compile(react, trainset=trainset)
Notice what's missing. There are no manually crafted prompts. No few-shot examples written by hand. No temperature tuning. You define the agent, provide data, and the optimizer does the rest.
The Philosophy Behind DSPy
The DSPy team argues that prompt engineering is a distraction. It forces developers to think about wording, formatting, and model quirks instead of task structure and data quality.
By separating the what from the how, DSPy lets you:
- Swap language models without rewriting prompts
- Optimize systematically instead of guessing
- Version control your program logic separately from prompt hacks
- Transfer improvements across models because the optimizer adapts to each backend
The class-based signatures are particularly powerful. They let you add docstrings for task clarification, descriptions for input fields, and constraints for outputs, all in familiar Python syntax.
class CheckCitationFaithfulness(dspy.Signature):
"""Verify that the text is based on the provided context."""
context: str = dspy.InputField(desc="facts here are assumed to be true")
text: str = dspy.InputField()
faithfulness: bool = dspy.OutputField()
evidence: dict[str, list[str]] = dspy.OutputField(desc="Supporting evidence for claims")
Which Optimizer Should You Use?
The DSPy documentation offers clear guidance:
- Around 10 examples: Start with
BootstrapFewShot - 50+ examples: Try
BootstrapFewShotWithRandomSearch - Instruction-only (0-shot): Use
MIPROv2configured for 0-shot - 200+ examples, longer runs: Use
MIPROv2with more trials - Need efficiency after prompt optimization: Use
BootstrapFinetune - Want the best of both worlds: Use
BetterTogetherwith a chained strategy
A typical simple optimization run costs about $2 and takes around ten minutes. Complex runs with large models or datasets can climb to tens of dollars.
The Bigger Picture
DSPy 3.2.0 represents a maturation of the framework. The type system makes it safer. The optimizer chaining makes it more powerful. The LiteLLM decoupling makes it more portable.
The 105 commits across 182 files by 37 contributors show active development, not maintenance mode. The 34,391 GitHub stars show community traction.
The trend is clear. Developers are moving from artisanal prompt crafting to systematic program optimization. DSPy is the leading tool for that shift. Version 3.2.0 makes the case stronger with better types, better security, and better composability.
If you are still hand-tweaking prompts, you are working harder than you need to. Define your task. Pick a metric. Let the optimizer figure out the rest.
Resources
- Repository: github.com/stanfordnlp/dspy
- Release Notes: github.com/stanfordnlp/dspy/releases/tag/3.2.0
- Documentation: dspy.ai
- GEPA Paper: arXiv:2507.19457
- MIPROv2 Paper: arXiv:2406.11695
Published May 14, 2026. DSPy 3.2.0 released April 21, 2026.