Prompt engineering has a signal problem. Most methods treat prompts as text to tweak through trial and error. ContraPrompt, accepted at ICLR 2026, takes a different route. It pairs success and failure reasoning traces on the same input and extracts the contrast. That contrast becomes the editing signal for the next prompt revision. It is the first method to extract signal from paired reasoning traces.

What ContraPrompt Does

ContraPrompt starts with a base prompt and training examples. For each example, it generates two reasoning traces. One leads to the correct answer. The other leads to a wrong answer. Both come from the same model given the same input. They differ only in whether the model arrives at truth or error.

The difference reveals what the prompt got right and what it got wrong. Instead of treating a failed prediction as noise, ContraPrompt treats it as diagnostic information. The paired traces form a dyad. The dyad encodes a contrast that tells the model where its reasoning diverged.

The Dyadic Trace Analysis Mechanism

The mechanism works in three stages.

First, ContraPrompt samples reasoning traces from the target model using the current prompt. It collects both correct and incorrect completions for each training example.

Second, it constructs dyadic pairs. Each pair contains a success trace and a failure trace for the same input. The model processes both and identifies where they diverge. The divergence points mark the reasoning steps where the prompt steered the model wrong.

Third, ContraPrompt feeds these dyadic pairs into an editor model. The editor compares the traces and revises the prompt to eliminate failure-mode patterns. The revised prompt enters the next iteration.

The loop runs for several rounds. Each round sharpens the prompt by removing failure patterns exposed by new dyads. The process converges when performance plateaus on a held-out validation set.

The dyadic structure matters because single-trace methods cannot isolate the cause of failure. A wrong answer tells you something went wrong, but not where or why. Pairing it with a correct trace pinpoints the divergence. That precision makes each revision targeted rather than scattershot.

Key Benchmark Results

On HotPotQA, ContraPrompt achieves +8.29 percentage points over GEPA. HotPotQA requires multi-hop reasoning across documents, making it a natural test bed for trace-level analysis. The dyadic approach catches errors at intermediate hops, not just at the final answer.

On GPQA Diamond, ContraPrompt beats GEPA by +7.14 percentage points. GPQA Diamond contains graduate-level science questions that demand precise chain-of-thought reasoning. The gains show dyadic analysis works on hard, knowledge-intensive tasks.

On GSM8K and MATH, ContraPrompt shows smaller but consistent improvements over GEPA and EvoPrompt. Math tasks have clear step-by-step structure, which gives single-trace methods strong signal. The dyadic advantage is modest but present.

Across all benchmarks, ContraPrompt never underperforms the base prompt. The dyadic signal is constructive. Revisions never degrade the prompt.

How ContraPrompt Differs from GEPA and Other Methods

GEPA generates prompt candidates and selects the best performer on a validation set. It relies on diversity in candidate generation and filtering. It does not analyze reasoning traces.

EvoPrompt uses evolutionary algorithms to mutate prompts. It treats prompts as strings and applies genetic operators. It lacks a model of what makes a prompt fail on a specific input.

PromptBreed uses self-referential mutation. APE uses forward generation and scoring. Neither looks inside the reasoning process.

ContraPrompt makes the reasoning trace the object of study. It treats the prompt as an instruction that produces observable behavior. When behavior fails, the trace explains why. The comparison tells the editor exactly what to change.

GEPA asks "which prompt scores highest?" ContraPrompt asks "why did this prompt fail here, and how does that differ from when it succeeded?" The second question produces richer signal per example.

VizPy and DSPy Integration

ContraPrompt is open-source and integrates with two tools.

VizPy provides visualization of reasoning trace dyads. Users inspect divergence points between success and failure traces in a graphical interface. The visualization shows which reasoning steps differ and how the revision addressed them.

DSPy integration allows ContraPrompt to operate as a drop-in optimizer. Users define modules in DSPy, attach ContraPrompt as the prompt optimizer, and run the standard compile pipeline. No custom code is required.

VizPy handles inspection. DSPy handles automation.

Practical Implications

ContraPrompt changes how teams approach prompt debugging. Current practice relies on reading failed outputs and guessing what went wrong. Dyadic analysis replaces guessing with structured comparison. Divergence points provide concrete, actionable feedback.

For multi-step reasoning tasks, the gains matter in production. An 8.29 percentage point improvement on HotPotQA translates to thousands more correct answers at scale. The same applies to GPQA Diamond at 7.14 points.

The method reduces the number of revision rounds needed. Each revision targets a specific failure mode, so fewer iterations reach peak performance. GEPA and EvoPrompt require more candidates and scoring rounds to match.

Limitations

ContraPrompt requires both correct and incorrect traces for each training example. On easy datasets where the base prompt almost never fails, few failure traces exist. The method works best when the base prompt succeeds on roughly 40 to 70 percent of examples.

The editor model adds cost. Each dyad requires a call to the editor model. The paper reports 5 to 8 rounds typically suffice, but each round processes every dyad.

The method assumes failure traces share common patterns. If failures are idiosyncratic, the editor struggles to find generalizable revisions.

ContraPrompt inherits biases from the editor model. If the editor has systematic blind spots, revisions reflect those blind spots.

Summary

ContraPrompt introduces dyadic reasoning trace analysis for prompt optimization. By pairing success and failure traces on the same input, it extracts targeted editing signal that single-trace methods cannot access. It beats GEPA by +8.29 points on HotPotQA and +7.14 points on GPQA Diamond. Open-source integration with VizPy and DSPy makes it practical for research and production. The main limitations are the need for balanced success-failure rates and editor model call costs.