ContraPrompt: Contrastive Prompt Optimization via Dyadic Reasoning Trace Analysis

Rishav Rishav, Pushpak Pujari, Pushpendre Rastogi

TL;DR

This paper introduces ContraPrompt, a novel prompt optimization technique that leverages the difference between a language model's failed and successful reasoning traces on the same input to extract specific, actionable rules. This "dyadic reasoning trace analysis" significantly outperforms existing methods on various benchmarks, demonstrating the power of analyzing the process of reasoning rather than just the final output.

What Problem Does This Paper Address?

Current prompt optimization methods often struggle to pinpoint the exact cause of a language model's failure. They either analyze individual failures in isolation (leading to generic "be more thorough" advice) or compare different prompt variants across many examples (losing the fine-grained signal of why a specific input failed). This leaves a gap in understanding how to effectively guide models to improve their reasoning process, especially when a model can succeed on a task but fails to do so reliably on the first attempt. The authors highlight a "capability-application gap" where models possess the underlying knowledge but struggle with consistent application, and existing methods don't fully exploit the signals available from retries.

Methods

ContraPrompt's core innovation is dyadic reasoning trace analysis. Instead of looking at a single failed trace or comparing final outputs, it takes a pair of traces for the same input: one that failed (τ⁻) and one that succeeded (τ⁺) after a retry. By comparing these two complete chain-of-thought traces, ContraPrompt can identify specific reasoning steps that were present in the successful attempt but absent in the failed one. This allows for the extraction of precise, actionable rules.

The process involves:

  1. Instrumented Agentic Retry Loop: The model attempts a task multiple times, with feedback from previous failures appended as context for subsequent attempts. This generates the necessary trace pairs.
  2. Contrastive Pair Mining: Examples where performance significantly improved between attempts are selected.
  3. Rule Extraction: A language model analyzes the τ⁻ and τ⁺ pair to identify and extract a transferable rule, focusing on the change in reasoning approach.
  4. Aggregated Failure Analysis: For examples where all attempts fail, a fallback mechanism identifies systematic patterns.
  5. Input-Aware Tree Merge: Extracted rules are organized into an input-aware decision tree. This tree routes rules conditionally based on observable input features, preventing prompt noise and ensuring only relevant rules are applied.

Datasets

The paper evaluates ContraPrompt on several existing benchmarks:

  • HotPotQA: A multi-hop question answering dataset requiring evidence synthesis.
  • GDPR-Bench-Android: A dataset for classifying GDPR compliance violations in Android apps.
  • GPQA Diamond: A graduate-level scientific reasoning benchmark.
  • BBH (BIG-Bench Hard): A collection of challenging reasoning tasks.
  • FiNER-139: A 139-class financial named entity recognition task.
  • EvalSet: A benchmark of 53 synthetic black-box optimization problems.

No new benchmarks were introduced, but the paper highlights how ContraPrompt's approach can uncover structure within existing datasets (e.g., US GAAP categories in FiNER-139).

Key Insights and Ideas

  • The reasoning trace is the key: The most significant insight is that the difference between a failed and successful reasoning trace on the same input provides a much richer optimization signal than comparing final outputs or analyzing failures in isolation. This signal is specific and actionable.
  • Dyadic analysis beats monadic: Removing the dyadic trace comparison component led to the largest performance drop (-16% relative), underscoring its critical role. Analyzing pairs of traces is far more effective than analyzing single traces.
  • Specificity matters: ContraPrompt extracts highly specific rules (e.g., "When the question requires combining facts from multiple paragraphs, state which paragraph provides each individual fact before combining them") rather than generic advice. This specificity is crucial for effective prompt optimization.
  • Input-aware routing is essential for scale: As rules accumulate, an input-aware decision tree is vital to prevent prompt noise and ensure efficiency by only injecting relevant rules based on input characteristics.
  • Generalization beyond text reasoning: The method's success in black-box optimization and financial entity recognition demonstrates its broad applicability beyond traditional NLP reasoning tasks.

Key Results

  • Outperforms GEPA: ContraPrompt consistently outperforms the state-of-the-art baseline GEPA across four reasoning and compliance benchmarks, with significant absolute gains: +8.29 pp (HotPotQA), +7.14 pp (GPQA Diamond), +2.21 pp (GDPR-Bench), and +0.74 pp (BBH).
  • Correlation with Retry Success: The performance gains are ordered consistently with the benchmarks' retry success rates, suggesting that tasks with a higher capability-application gap benefit more from this method.
  • Generalization:
    • On FiNER-139 (139-class classification), ContraPrompt achieved +7.77 pp absolute improvement over the baseline and +1.94 pp over GEPA.
  • In black-box optimization, ContraPrompt achieved a 96.4% win-plus-tie rate against Optuna and outperformed GEPA.
  • Ablation Study: Removing contrastive mining (the core dyadic trace analysis) resulted in a -16% average relative performance drop, confirming its critical importance.

Limitations and Future Work

  • Dependence on Retry Success: The dyadic mechanism requires at least one successful retry per training example. For tasks where all attempts fail, it relies on weaker aggregated failure analysis. This means the method is most valuable where the capability-application gap is largest.
  • Controlled Comparison Caveat: The successful retry is conditioned on error feedback from the prior failure, making the pair not a pure reasoning-strategy comparison. While rule extraction is designed to focus on reasoning changes, this decomposition is approximate. Future work could involve controlled experiments without feedback.
  • Scope and Scale: The current evaluation uses a single model family and a limited set of benchmarks. Expanding to more models, benchmarks, and complex compound AI systems is a natural next step.
  • Hybrid Approaches: Combining ContraPrompt's within-example dyadic signal with GEPA's cross-example population-level search is a promising direction.
  • Online Adaptation: Developing an online variant that updates the rule tree during deployment would enable continual adaptation.
  • Deeper Rule Organization: Exploring deeper or graph-structured rule organizations could capture more complex input-type interactions.

Summary updated

BibTeX
@inproceedings{rishav2026contraprompt,
  author = {Rishav Rishav and Pushpak Pujari and Pushpendre Rastogi},
  title = {{ContraPrompt: Contrastive Prompt Optimization via Dyadic Reasoning Trace Analysis}},
  booktitle = {LLM Reasoning @ ICLR},
  year = {2026},
  url = {https://openreview.net/forum?id=86E9P53xbM},
}
Figure