skills/dspy-two-step-adapter/SKILL.md
Use when working with reasoning models (o1, o3, o3-mini, DeepSeek-R1, Claude extended thinking) that reject system prompts or ignore formatting instructions. Common scenarios - using o1 or o3 with DSPy, getting structured output from reasoning models, two-phase prompting where a reasoning model generates freely then an extraction model parses the output, or fixing format errors from thinking models. Related - dspy-adapters, dspy-lm, ai-switching-models. Also used for dspy.TwoStepAdapter, o1 with DSPy, o3-mini DSPy, reasoning model in DSPy, DeepSeek-R1 DSPy, extended thinking DSPy, thinking model ignores format, o1 ignores my DSPy format, TwoStepAdapter setup, two-phase prompting, extraction LM, reasoning model structured output, main_lm extraction_lm, model pairing for reasoning models.
npx skillsauth add lebsral/dspy-programming-not-prompting-lms-skills dspy-two-step-adapterInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Guide the user through configuring DSPy to work with reasoning models (o1, o3, o3-mini, DeepSeek-R1, Claude with extended thinking) that need special handling for structured output.
Reasoning models (o1, o3, DeepSeek-R1, Claude extended thinking) behave differently from standard chat models:
[[ ## field_name ## ]])TwoStepAdapter solves this with a two-phase approach:
| Use TwoStepAdapter when... | Use ChatAdapter (default) when... | |---------------------------|----------------------------------| | Using o1, o3, o3-mini | Using GPT-4o, Claude, Gemini | | Using DeepSeek-R1 | Using any instruction-following model | | Using Claude with extended thinking | The model follows formatting reliably | | Model ignores your output format | Structured output works out of the box | | Getting raw reasoning dumps instead of fields | You do not need reasoning-heavy processing |
import dspy
# The reasoning model (generates freely)
main_lm = dspy.LM("openai/o3-mini")
# The extraction model (parses into structured fields)
extraction_lm = dspy.LM("openai/gpt-4o-mini")
# Configure the adapter
adapter = dspy.TwoStepAdapter(
main_lm=main_lm,
extraction_lm=extraction_lm,
)
dspy.configure(lm=main_lm, adapter=adapter)
Now use DSPy normally -- the adapter handles the two-phase flow transparently:
qa = dspy.ChainOfThought("question -> answer")
result = qa(question="What is 127 * 389?")
print(result.answer) # Structured output, extracted by gpt-4o-mini
| Reasoning model (main_lm) | Extraction model (extraction_lm) | Notes |
|---------------------------|----------------------------------|-------|
| openai/o1 | openai/gpt-4o-mini | Best reasoning + cheap extraction |
| openai/o3 | openai/gpt-4o-mini | Highest capability |
| openai/o3-mini | openai/gpt-4o-mini | Cost-effective reasoning |
| deepseek/deepseek-r1 | openai/gpt-4o-mini | Open-weight reasoning |
| anthropic/claude-sonnet-4-5-20250929 (extended thinking) | anthropic/claude-haiku-3-5-20241022 | All-Anthropic stack |
Pairing principles:
You can use TwoStepAdapter for specific modules while using ChatAdapter elsewhere:
import dspy
# Default: fast model with ChatAdapter
fast_lm = dspy.LM("openai/gpt-4o-mini")
dspy.configure(lm=fast_lm)
# Reasoning model for hard problems
reasoning_lm = dspy.LM("openai/o3-mini")
extraction_lm = dspy.LM("openai/gpt-4o-mini")
reasoning_adapter = dspy.TwoStepAdapter(
main_lm=reasoning_lm,
extraction_lm=extraction_lm,
)
class Pipeline(dspy.Module):
def __init__(self):
# Simple classification -- uses default ChatAdapter
self.classify = dspy.Predict("text -> category")
# Hard reasoning -- uses TwoStepAdapter
self.analyze = dspy.ChainOfThought("text, category -> analysis")
self.analyze.adapter = reasoning_adapter
self.analyze.lm = reasoning_lm
def forward(self, text):
category = self.classify(text=text).category
analysis = self.analyze(text=text, category=category).analysis
return dspy.Prediction(category=category, analysis=analysis)
Claude with extended thinking uses a budget parameter instead of a separate model:
import dspy
# Claude with extended thinking enabled
thinking_lm = dspy.LM(
"anthropic/claude-sonnet-4-5-20250929",
thinking={"type": "enabled", "budget_tokens": 10000},
)
# Extraction model
extraction_lm = dspy.LM("anthropic/claude-haiku-3-5-20241022")
adapter = dspy.TwoStepAdapter(
main_lm=thinking_lm,
extraction_lm=extraction_lm,
)
dspy.configure(lm=thinking_lm, adapter=adapter)
# Works transparently -- thinking model reasons, haiku extracts structure
solver = dspy.ChainOfThought("problem -> solution")
result = solver(problem="Prove that sqrt(2) is irrational")
Do not use TwoStepAdapter when:
If the model follows ChatAdapter format reliably, TwoStepAdapter adds cost and latency for no benefit.
lm and adapter on per-module assignment. When assigning TwoStepAdapter to a specific module, set both module.adapter = adapter and module.lm = reasoning_lm. Missing either causes the wrong model or wrong adapter to be used.thinking={"type": "enabled", "budget_tokens": N} to the LM constructor, not as a separate parameter.Install any skill:
npx skills add lebsral/DSPy-Programming-not-prompting-LMs-skills --skill <name>
/dspy-adapters/dspy-chatadapter/dspy-lm/ai-switching-models/ai-do if you do not have it -- it routes any AI problem to the right skill and is the fastest way to work: npx skills add lebsral/DSPy-Programming-not-prompting-LMs-skills --skill ai-dotools
See what is happening during optimizer.compile() instead of waiting blind. Use when you want to watch optimization progress, see scores as they come in, know if your optimizer is working, check if optimization is stuck, understand why optimization is taking too long, get live progress during compile, monitor convergence, detect overfitting during optimization, interpret optimization results, or pick the right tool for watching optimization. Also used for optimizer progress bar, is my optimizer doing anything, optimization seems stuck, how long will optimization take, watch GEPA run, watch MIPROv2 run, live optimization dashboard, optimizer not improving, scores not going up, optimization taking forever, see what optimizer is doing, debug slow optimization, optimization visibility, optimizer metrics, track compile progress, optimization observability.
testing
Use when you want the highest-quality prompt optimization DSPy offers — jointly optimizes instructions and few-shot demos, with auto=light/medium/heavy presets. Common scenarios - you want the best possible accuracy from prompt optimization, jointly tuning instructions and few-shot demonstrations, using auto presets for different compute budgets, or when COPRO or BootstrapFewShot alone are not reaching your accuracy target. Related - ai-improving-accuracy, dspy-copro, dspy-bootstrap-few-shot. Also used for dspy.MIPROv2, best DSPy optimizer, highest quality optimization, auto=light medium heavy, joint instruction and demo optimization, most powerful prompt optimizer, MIPROv2 vs COPRO vs BootstrapFewShot, which optimizer should I use, state of the art prompt optimization, when to use MIPROv2, optimize both instructions and examples, heavy optimization for production, best optimizer for accuracy.
testing
Use LangWatch for DSPy auto-tracing and real-time optimizer progress. Use when you want to set up LangWatch, langwatch.dspy.init, auto-tracing DSPy, real-time optimization dashboard, optimizer progress tracking, app.langwatch.ai, or DSPy optimizer dashboard. Also used for langwatch setup, pip install langwatch, langwatch trace, optimizer progress, real-time optimization, watch optimizer run, LangWatch self-hosted, langwatch docker, langwatch vs langtrace, langwatch autotrack_dspy.
data-ai
Use when you want to optimize instructions without few-shot examples — a lightweight alternative to COPRO when you do not have or do not want to use demonstrations. Common scenarios - optimizing instructions when you do not have or do not want to use few-shot demonstrations, lightweight instruction search as a first step, tasks where examples in the prompt confuse the model, or when you want fast instruction optimization without the cost of COPRO. Related - ai-improving-accuracy, dspy-copro, dspy-miprov2. Also used for dspy.GEPA, instruction optimization without demos, lightweight prompt optimization, optimize instructions only, no few-shot examples needed, GEPA vs COPRO, quick instruction search, when demonstrations hurt performance, zero-shot optimization, instruction-only optimizer, simplest instruction tuner, fast prompt optimization, skip few-shot and just tune instructions, optimize Pydantic field descriptions, GEPA structured output, GEPA does not optimize field desc.