The Research Report
DSPy 3.2.0 Ships Composable Optimizer Pipelines: BetterTogether Grows Up
Stanford's DSPy, the framework for programming language models rather than prompting them, shipped version 3.2.0 on April 21, 2026. The release has 105 commits from 37 contributors across 182 files. The headline feature is a fundamental change to how BetterTogether works: it now chains arbitrary optimizers via strategy strings, turning what was a two-step prompt-then-finetune pipeline into a composable optimization workflow.
This is a meaningful shift. DSPy is moving from single-optimizer tuning to multi-stage optimization pipelines where you can sequence, repeat, and interleave different optimization strategies. If prompt optimization and weight optimization work better together, as the original paper showed, then running them in repeated cycles should work even better.
What BetterTogether Does
BetterTogether is a meta-optimizer. It was introduced in the EMNLP 2024 paper "Fine-Tuning and Prompt Optimization: Two Great Steps that Work Better Together" by Dilara Soylu, Christopher Potts, and Omar Khattab.
The core insight is straightforward. Prompt optimization discovers effective task decompositions and reasoning strategies. Weight optimization (fine-tuning) specializes the model to execute those patterns more efficiently. Running them in sequence lets each build on the other's improvements.
Before 3.2.0, BetterTogether was a fixed two-step optimizer. You ran prompt optimization, then weight optimization, and that was it. The order was configurable but the pipeline was rigid.
What Changed in 3.2.0
The big change: BetterTogether now accepts arbitrary optimizers as keyword arguments and chains them via strategy strings.
Here is what the new API looks like:
from dspy.teleprompt import GEPA, BootstrapFinetune
optimizer = BetterTogether(
metric=metric,
p=GEPA(metric=metric, auto="medium"),
w=BootstrapFinetune(metric=metric)
)
student.set_lm(lm)
compiled = optimizer.compile(
student,
trainset=trainset,
valset=valset,
strategy="p -> w -> p"
)
The strategy parameter is the key innovation. Each letter in the strategy string maps to an optimizer you defined in the constructor. The arrow -> means "then." The string p -> w -> p means: run prompt optimization, then weight optimization, then prompt optimization again.
This unlocks several patterns.
Prompt then finetune then prompt. The p -> w -> p strategy. Fine-tune the model weights to internalize what prompt optimization discovered, then run prompt optimization again on the fine-tuned model to find even better prompts for the specialized weights. The Databricks case study showed this combined approach outperforms either strategy alone by a significant margin.
Multiple prompt optimization passes. You can chain different prompt optimizers. For example, mipro -> gepa -> mipro runs MIPROv2, then GEPA, then MIPROv2 again. Each optimizer has different strengths. MIPROv2 searches over instruction proposals. GEPA searches over few-shot demonstrations. Running them in sequence lets each one improve on what the previous one found.
Custom strategy lengths. There is no limit on how many stages you chain. A strategy like p -> w -> p -> w -> p would run five optimization stages. Whether this produces better results than shorter strategies is an empirical question, but the framework now makes it easy to experiment.
When you provide a validation set, BetterTogether evaluates after each stage and returns the best-performing program. If any stage fails, it returns the best program found so far instead of crashing.
The Other Big Change: Decoupling From LiteLLM
The second major change in 3.2.0 is less flashy but equally important for production users. DSPy is decoupling from LiteLLM.
Before this release, DSPy imported LiteLLM throughout its adapter layer. If you wanted to use a custom language model backend, you still needed LiteLLM installed. The error handling for context window limits came from LiteLLM. The function calling capability checks came from LiteLLM.
In 3.2.0, three changes break this dependency:
- Adapters no longer import LiteLLM. The adapter layer, which handles formatting prompts and parsing responses for different model providers, is now LiteLLM-free.
- BaseLM exposes capability properties. Custom backends can declare what they support through
supportsfunctioncalling,supportsreasoning,supportsresponseschema, andsupportedparams. DSPy can check these without going through LiteLLM. - DSPy owns its error types. A new
dspy.ContextWindowExceededErrorreplaces the LiteLLM error throughout. Custom BaseLM backends can now integrate with DSPy's retry and truncation logic without any LiteLLM dependency.
This matters because LiteLLM has been a recurring source of dependency conflicts and version pinning headaches for DSPy users. Removing it from the adapter layer makes custom model integration cleaner and reduces the attack surface for dependency issues.
Smaller But Notable Changes
Type mismatch warnings. Passing a value that does not match a signature's declared type now logs a warning via typeguard. Extra fields not in the signature also warn. You can disable this with dspy.configure(warnontype_mismatch=False). This catches a common source of silent bugs where the wrong type flows through a pipeline without failing.
Hardened RLM and PythonInterpreter. Tool calls now use kwargs-only dispatch. The JavaScript tool bridge returns structured errors instead of throwing, preventing Deno crashes. Stdout parsing skips non-JSON lines instead of crashing. Subprocess restarts correctly replay tool and mount registration. These are reliability improvements for DSPy's Reasoning Language Model (RLM) module.
Restricted pickle for disk cache. An opt-in dspy.configurecache(restrictpickle=True) swaps pickle.load with 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. In a future release, this restriction will become the default.
Optuna is now optional. Moved from a required dependency to pip install dspy[optuna]. Saves about 12.7 MB. Only MIPROv2 and BootstrapFewShotWithOptuna use it.
Why This Matters for Prompt Engineers
The strategy string feature changes the optimization workflow from "pick one optimizer and run it" to "design a pipeline of optimizers and evaluate at each stage."
This is the same transition that machine learning went through with pipelines and ensembles. Single models gave way to pipelines where preprocessing, feature engineering, and model training each had dedicated stages. DSPy is applying the same principle to prompt and weight optimization.
The practical implication: instead of asking "which optimizer should I use?", you can now ask "what sequence of optimization steps produces the best result for my task?"
The Databricks case study showed that combining prompt optimization with fine-tuning outperforms either approach alone. The 3.2.0 release makes it trivial to test whether adding more stages to that combination helps further.
Getting Started
Upgrade to DSPy 3.2.0:
pip install dspy==3.2.0
If you use Optuna-based optimizers:
pip install dspy[optuna]==3.2.0
A basic BetterTogether pipeline with strategy strings:
import dspy
from dspy.teleprompt import GEPA, BootstrapFinetune, BetterTogether
# Define your program and metric
student = dspy.ChainOfThought("question -> answer")
metric = dspy.evaluate.answer_exact_match
# Set up a two-stage pipeline
optimizer = BetterTogether(
metric=metric,
p=GEPA(metric=metric, auto="medium"),
w=BootstrapFinetune(metric=metric)
)
# Run prompt optimization, then weight optimization
student.set_lm(lm)
compiled = optimizer.compile(
student,
trainset=trainset,
valset=valset,
strategy="p -> w"
)
To try a three-stage pipeline:
# Prompt, finetune, prompt again
compiled = optimizer.compile(
student,
trainset=trainset,
valset=valset,
strategy="p -> w -> p"
)
To pass optimizer-specific compile arguments:
compiled = optimizer.compile(
student,
trainset=trainset,
valset=valset,
strategy="p -> w",
optimizer_compile_args={
"p": {"num_trials": 10, "max_bootstrapped_demos": 8},
}
)
The candidate_programs attribute on the returned program gives you scores for each strategy stage. You can see exactly which step produced the best result.
Sources
- DSPy 3.2.0 release notes: https://github.com/stanfordnlp/dspy/releases/tag/3.2.0
- BetterTogether API documentation: https://dspy.ai/api/optimizers/BetterTogether/
- "Fine-Tuning and Prompt Optimization: Two Great Steps that Work Better Together" (EMNLP 2024): https://aclanthology.org/2024.emnlp-main.597/
- Databricks case study: https://www.databricks.com/blog/building-state-art-enterprise-agents-90x-cheaper-automated-prompt-optimization