From Errors to Rules: Iterative Prompt Optimization for Text Classification

arXiv cs.AI Papers

Summary

This paper presents ERGO, an error-driven method for iterative prompt optimization in text classification that diagnoses classification failures and generates targeted decision rules, achieving best accuracy on tasks where errors concentrate in specific confused label pairs.

arXiv:2607.20497v1 Announce Type: new Abstract: Prompt optimization for text classification spans diverse approaches, from demonstration selection to exploration-based search to error-driven diagnosis, each with known but incompletely characterized strengths and limitations. We conduct a comprehensive empirical study across diverse classification benchmarks (2 to 150 classes) comparing these paradigms through both quantitative evaluation and qualitative analysis of optimization traces, revealing that each paradigm excels on structurally different task types and that no single method dominates. Guided by these insights, we propose Error-Guided Optimization (ERGO), an error-driven method that iterates over the full training set in non-overlapping batches, diagnoses classification failures, and generates targeted decision rules through a diagnose-prescribe-rewrite feedback loop. ERGO achieves the best accuracy on tasks where errors concentrate in specific confused label pairs (which we term boundary-learnable tasks): TREC: 90.0%, CLINC150: 94.4%, converges in 3-5 iterations, and produces interpretable decision rules. While ERGO does not achieve the highest overall average, it fills a complementary role: demonstration-based ICL wins on coverage-dependent tasks, exploration-based search wins on many-class intent, and ERGO wins where decision boundaries are learnable from error patterns. We provide a complementarity framework linking task characteristics to optimal paradigm selection, offering practical guidance for practitioners.
Original Article
View Cached Full Text

Cached at: 07/24/26, 05:03 AM

# From Errors to Rules: Iterative Prompt Optimization for Text Classification
Source: [https://arxiv.org/html/2607.20497](https://arxiv.org/html/2607.20497)
###### Abstract

Prompt optimization for text classification spans diverse approaches, from demonstration selection to exploration\-based search to error\-driven diagnosis, each with known but incompletely characterized strengths and limitations\. We conduct a comprehensive empirical study across diverse classification benchmarks \(2 to 150 classes\) comparing these paradigms through both quantitative evaluation and qualitative analysis of optimization traces, revealing that each paradigm excels on structurally different task types and that no single method dominates\. Guided by these insights, we propose Error\-Guided Optimization \(ERGO\), an error\-driven method that iterates over the full training set in non\-overlapping batches, diagnoses classification failures, and generates targeted decision rules through a diagnose\-prescribe\-rewrite feedback loop\. ERGO achieves the best accuracy on tasks where errors concentrate in specific confused label pairs \(which we term boundary\-learnable tasks\): TREC: 90\.0%, CLINC150: 94\.4%, converges in 3\-5 iterations, and produces interpretable decision rules\. While ERGO does not achieve the highest overall average, it fills a complementary role: demonstration\-based ICL wins on coverage\-dependent tasks, exploration\-based search wins on many\-class intent, and ERGO wins where decision boundaries are learnable from error patterns\. We provide a complementarity framework linking task characteristics to optimal paradigm selection, offering practical guidance for practitioners\.

From Errors to Rules: Iterative Prompt Optimization for Text Classification

Yueying Cui Renhao Xue Yi Zhang Mukul PrasadAmazon Web Services

## 1Introduction

Prompt optimization for text classification has produced a rich landscape of methods, from demonstration selectionLiuet al\.\([2022](https://arxiv.org/html/2607.20497#bib.bib5)\)to exploration\-based searchZhouet al\.\([2023](https://arxiv.org/html/2607.20497#bib.bib15)\); Khattabet al\.\([2024](https://arxiv.org/html/2607.20497#bib.bib32)\)to error\-driven diagnosisPryzantet al\.\([2023](https://arxiv.org/html/2607.20497#bib.bib35)\)\. Unlike fine\-tuned modelsDevlinet al\.\([2019](https://arxiv.org/html/2607.20497#bib.bib6)\); Botunacet al\.\([2024](https://arxiv.org/html/2607.20497#bib.bib14)\)that require substantial labeled data, these methods operate in the few\-shot regimeSahooet al\.\([2024](https://arxiv.org/html/2607.20497#bib.bib11)\), yet they embody fundamentally different optimization strategies\. Existing comparisons typically focus on overall accuracy without analyzing when and why each approach excelsLiet al\.\([2025](https://arxiv.org/html/2607.20497#bib.bib19)\); Ramnathet al\.\([2025](https://arxiv.org/html/2607.20497#bib.bib20)\)\. Recent findings that prompt optimization is “statistically indistinguishable from a coin flip”Zhanget al\.\([2026](https://arxiv.org/html/2607.20497#bib.bib40)\)further underscore the need for a deeper understanding of which tasks benefit from which paradigm\.

We address this gap through a comprehensive empirical study across diverse classification benchmarks \(2–150 classes\), comparing three paradigms: demonstration selection methods that choose diverse few\-shot examplesLiuet al\.\([2022](https://arxiv.org/html/2607.20497#bib.bib5)\); Yuet al\.\([2023](https://arxiv.org/html/2607.20497#bib.bib3)\), exploration\-based methods that search over instruction–demonstration combinations \(DSPyKhattabet al\.\([2024](https://arxiv.org/html/2607.20497#bib.bib32)\), GEPAAgrawalet al\.\([2026](https://arxiv.org/html/2607.20497#bib.bib34)\), APEZhouet al\.\([2023](https://arxiv.org/html/2607.20497#bib.bib15)\)\), and our proposed diagnosis\-based method \(ERGO\) that uses classification errors to generate targeted decision rules\. Our analysis reveals that these paradigms are complementary rather than competing: each excels on structurally different task types, and no single method dominates overall\.

We propose Error\-Guided Optimization \(ERGO\), which iterates over the full training set using a diagnose→\\rightarrowprescribe→\\rightarrowrewrite meta\-prompt: at each iteration, ERGO classifies a batch, identifies confused label pairs, and generates explicit decision rules\. Unlike exploration\-based methods that treat accuracy as a black\-box signal, ERGO jointly refines instructions, demonstrations, and classification guidelines from actual error patterns, producing interpretable rules that encode task\-intrinsic knowledge\.

ERGO provides unique value on boundary\-learnable tasks, where classification errors concentrate in specific confused pairs amenable to natural\-language rules\. On such tasks, ERGO achieves the best accuracy \(TREC: 90\.0%, CLINC150: 94\.4%\), typically converges in 3\-5 iterations, and produces rules that transfer across model families\. For instance, a single misclassified query about a company triggers the rule “organizations→\\rightarrowhuman beings,” fixing 25\+ test queries\. However, ERGO does not dominate overall: ICL\-Diversity wins on coverage\-dependent tasks at zero optimization cost, and DSPy wins on many\-class tasks, confirming that the paradigms are complementary rather than competing\.

Our main contributions:

- •ERGO, an error\-driven prompt optimization method that produces interpretable, transferable decision rules through iterative feedback over the full training set \([Section˜3](https://arxiv.org/html/2607.20497#S3)\)\.
- •Case studies showing how ERGO discovers learnable decision boundaries that other methods miss: hidden conventions, progressive boundary refinement, and structural rules that generalize across label pairs \([Section˜6](https://arxiv.org/html/2607.20497#S6)\)\.
- •Quantitative analysis showing ERGO generalizes across 5 models from 4 families and transfers prompts from stronger to weaker models with no measurable accuracy loss \([Section˜5](https://arxiv.org/html/2607.20497#S5)\)\.
- •A practical paradigm selection framework: start with ICL\-Diversity, apply ERGO for boundary\-learnable tasks, use DSPy for many\-class tasks \([Section˜7](https://arxiv.org/html/2607.20497#S7)\)\.

## 2Prompt Optimization Paradigms

We organize prompt\-based classification methods into three paradigms: selecting demonstrations without iterative optimization \(Demonstrate\), searching over prompt variants guided by accuracy signals \(Explore\), and systematically diagnosing classification errors to refine prompts \(Diagnose\)\.

#### Paradigm 1: Demonstrate\.

Select diverse few\-shot examples as demonstrationsBrownet al\.\([2020](https://arxiv.org/html/2607.20497#bib.bib12)\); Donget al\.\([2024](https://arxiv.org/html/2607.20497#bib.bib9)\)\. Research has explored selection strategiesLiuet al\.\([2022](https://arxiv.org/html/2607.20497#bib.bib5)\); Margatinaet al\.\([2023](https://arxiv.org/html/2607.20497#bib.bib8)\), ordering effectsGuoet al\.\([2024](https://arxiv.org/html/2607.20497#bib.bib24)\), and diversity\-based retrievalYuet al\.\([2023](https://arxiv.org/html/2607.20497#bib.bib3)\)\. In our setup, ICL\-Diversity selectsk=20k\{=\}20demonstrations viakk\-means on Sentence\-BERTReimers and Gurevych \([2019](https://arxiv.org/html/2607.20497#bib.bib4)\)embeddingsSuet al\.\([2023](https://arxiv.org/html/2607.20497#bib.bib41)\); ICL\-Uniform samples randomlyBrownet al\.\([2020](https://arxiv.org/html/2607.20497#bib.bib12)\)\. Neither involves iterative refinement or adapts to classification errors\.

#### Paradigm 2: Explore\.

Methods in this paradigm search over prompt variants guided by accuracy signals\. APEZhouet al\.\([2023](https://arxiv.org/html/2607.20497#bib.bib15)\); Honovichet al\.\([2023](https://arxiv.org/html/2607.20497#bib.bib30)\)generates instruction candidates via LLM sampling\. OPROYanget al\.\([2024](https://arxiv.org/html/2607.20497#bib.bib17)\)uses LLM\-driven meta\-optimization\. DSPy/MIPROv2Khattabet al\.\([2024](https://arxiv.org/html/2607.20497#bib.bib32)\)explores instruction×\\timesdemonstration combinations via Bayesian optimization, selecting candidates based on 35\-item minibatch scores\. GEPAAgrawalet al\.\([2026](https://arxiv.org/html/2607.20497#bib.bib34)\)uses evolutionary search with per\-example error feedback to guide instruction evolution\. Other methods include PromptWizardAgarwalet al\.\([2025](https://arxiv.org/html/2607.20497#bib.bib16)\), self\-refinementMadaanet al\.\([2023](https://arxiv.org/html/2607.20497#bib.bib18)\), and RL\-based approachesDenget al\.\([2022](https://arxiv.org/html/2607.20497#bib.bib28)\)\.

#### Paradigm 3: Diagnose\.

Our contribution\. While Explore methods also iterate and can use error feedback, they treat prompt refinement as a search problem \(generate variants, evaluate, select\)\. ERGO instead uses a structured diagnose→\\rightarrowprescribe→\\rightarrowrewrite meta\-prompt: at each iteration, it shows the LLM both correct and incorrect predictions from a batch, asks it to identify confused label pairs and why, then jointly rewrites the full prompt \(instruction \+ demonstrations \+ classification guidelines\) in one pass\. ProTeGiPryzantet al\.\([2023](https://arxiv.org/html/2607.20497#bib.bib35)\)also uses LLM\-generated feedback but optimizes instructions only\.

#### Why does this matter?

Concurrent workZhanget al\.\([2026](https://arxiv.org/html/2607.20497#bib.bib40)\)finds prompt optimization is “statistically indistinguishable from a coin flip” across 4 tasks, raising the question of when optimization is worthwhile\. We confirm this: DSPy’s optimization finds no improvement over the default instruction in 35% of runs, and evaluates candidates on 35\-item minibatches that overfit by up to 14 percentage points relative to test accuracy\. Error\-driven optimization addresses this by focusing search on what actually fails: rather than searching over instruction variants \(DSPy/GEPA\) or relying on fixed examples \(ICL\), it learns task\-specific conventions directly from structured error diagnosis\.

![Refer to caption](https://arxiv.org/html/2607.20497v1/images/ergo-architecture.png)Figure 1:ERGO overview\.Inputs: a seed promptπ0\\pi\_\{0\}, training setDtrainD\_\{\\text\{train\}\}, validation setDvalD\_\{\\text\{val\}\}, and iteration budgetTT\. Training data is shuffled once into non\-overlapping batches of sizekk\.Loop\(steps 1–4\): each iteration selects the next batch, classifies it with the current prompt, partitions predictions into mistakesEtE\_\{t\}and correctCtC\_\{t\}, then applies the diagnose→\\rightarrowprescribe→\\rightarrowrewrite meta\-prompt to produce an updated promptπt\\pi\_\{t\}\.Step 5: every candidate is evaluated onDvalD\_\{\\text\{val\}\}; the best\-on\-val promptπ∗=arg⁡maxt⁡A​\(πt\)\\pi^\{\*\}=\\arg\\max\_\{t\}A\(\\pi\_\{t\}\)is returned\.

## 3ERGO: Error\-Driven Prompt Refinement

### 3\.1Problem Formulation

Let𝒳\\mathcal\{X\}be an input space and𝒴=\{y1,…,yK\}\\mathcal\{Y\}=\\\{y\_\{1\},\\ldots,y\_\{K\}\\\}a finite label set\. We define a promptπ\\pias a structured tuple:

π=\(τ,𝒟,𝒢\)\\pi=\(\\tau,\\mathcal\{D\},\\mathcal\{G\}\)\(1\)whereτ∈𝒯\\tau\\in\\mathcal\{T\}is a natural language instruction,𝒟=\{\(xi,yi\)\}i=1n\\mathcal\{D\}=\\\{\(x\_\{i\},y\_\{i\}\)\\\}\_\{i=1\}^\{n\}is a set of in\-context demonstrations, and𝒢\\mathcal\{G\}is a set of decision guidelines \(classification rules, boundary conditions, common pitfalls\)\.

Given a frozen LLMfθ:𝒳×Π→𝒴f\_\{\\theta\}:\\mathcal\{X\}\\times\\Pi\\rightarrow\\mathcal\{Y\}, the prompt optimization problem is:

π∗\\displaystyle\\pi^\{\*\}=arg⁡maxπ∈Π⁡A​\(π\),\\displaystyle=\\arg\\max\_\{\\pi\\in\\Pi\}\\;A\(\\pi\),\(2\)A​\(π\)\\displaystyle A\(\\pi\)=𝔼\(x,y\)∼𝒫​\[𝟏​\[fθ​\(x;π\)=y\]\]\\displaystyle=\\mathbb\{E\}\_\{\(x,y\)\\sim\\mathcal\{P\}\}\\left\[\\mathbf\{1\}\[f\_\{\\theta\}\(x;\\pi\)=y\]\\right\]\(3\)SinceA​\(π\)A\(\\pi\)depends on the full tuple\(τ,𝒟,𝒢\)\(\\tau,\\mathcal\{D\},\\mathcal\{G\}\)and the components interact \(the effectiveness of demonstrations𝒟\\mathcal\{D\}depends on the instructionτ\\tauthat frames them\), we optimize all three jointly rather than in isolation\.

### 3\.2Overview

We instantiate error\-driven refinement asError\-Guided Optimization \(ERGO\)\([Figure˜1](https://arxiv.org/html/2607.20497#S2.F1)\)\. Unlike exploration\-based search which explores prompt variants, ERGO uses classification errors as structured feedback: at each iteration, it identifies*which*label pairs are confused and generates*why*\-level decision rules to disambiguate them\. Training examples are partitioned into non\-overlapping batches, ensuring every example is seen exactly once across iterations\.

### 3\.3Algorithm

#### Seed prompt\.

ERGO starts from a minimal instruction \(“Classify the input as exactly one of: \{LABELS\}”\) with a structured output format and no demonstrations\. The method’s gains come entirely from iterative refinement\.

Table 1:Test accuracy \(%\) on 8 classification benchmarks \(mean over 5 seeds\)\.Bold= best\. No method significantly outperforms all others overall \(pairedtt\-test,p\>0\.05p\{\>\}0\.05\)\.DatasetICL\-UniICL\-DivAPEDSPyGEPAERGOTREC \(6 cls\)87\.889\.386\.884\.685\.390\.0CLINC150 \(150 cls\)93\.093\.092\.893\.793\.294\.4RTE \(2 cls\)91\.891\.392\.592\.793\.093\.2Ethos \(2 cls\)85\.685\.463\.488\.487\.088\.1Yahoo \(10 cls\)73\.372\.772\.573\.972\.971\.720Newsgroups \(20 cls\)69\.970\.867\.769\.268\.766\.8Rotten Tom\. \(2 cls\)93\.293\.292\.692\.993\.792\.8MASSIVE \(60 cls\)90\.189\.289\.390\.089\.487\.8Average \(8\)85\.685\.682\.285\.785\.485\.6
#### Feedback\-first meta\-prompt\.

At each iteration, the meta\-prompt provides the LLM with: \(a\) all correctly classified examples from the batch, \(b\) all misclassified examples with predicted vs\. true labels, and instructs the LLM to: \(1\)*diagnose*which label pairs are confused and why, \(2\)*prescribe*specific decision rules, \(3\)*rewrite*the full prompt \(full template in[Appendix˜H](https://arxiv.org/html/2607.20497#A8); pseudocode in[Algorithm˜1](https://arxiv.org/html/2607.20497#alg1)\)\. A key byproduct is interpretability: the resulting prompts contain human\-readable decision rules that practitioners can audit, refine, or use as annotation guidelines\.

#### Random non\-overlapping batches\.

Training examples are shuffled once; sequential 20\-item batches ensure each example is seen exactly once across iterations, maximizing information coverage without stratification complexity\.

#### Best\-of\-TTselection\.

Since LLM generation is stochastic and improvement is not guaranteed at every step, ERGO retains all candidate prompts and returns the best by validation accuracy\. Each candidate is evaluated on the full validation set to reduce selection noise\. Empirically, the optimal prompt is found within 3–5 iterations\.

## 4Experiments

### 4\.1Setup

#### Datasets\.

We evaluate on 8 representative classification benchmarks spanning 2–150 classes, including EthosMollaset al\.\([2022](https://arxiv.org/html/2607.20497#bib.bib1)\), RTEWanget al\.\([2018](https://arxiv.org/html/2607.20497#bib.bib2)\), and CLINC150 among others \(full details in[Appendix˜A](https://arxiv.org/html/2607.20497#A1)\)\. Each uses a stratified split targeting 200 training, 100 validation, and 500 test examples, reduced proportionally for smaller datasets\.

#### Model\.

Claude Sonnet 4\.5 via AWS Bedrock \(temperature=0\.0\)\. Per run, ERGO completes in 16\.4 min on average vs\. DSPy \(28\.8 min\) and GEPA \(30\.9 min\); full cost comparison in[Table˜14](https://arxiv.org/html/2607.20497#A6.T14)\.

#### Seeds\.

All experiments use 5 random seeds \(42, 123, 7, 1, 2\)\. Statistical significance via pairedtt\-test at 5% level across all 40 configurations \(8 datasets×\\times5 seeds\)\.

#### Baselines\.

\(1\) ICL\-Uniform: 20 random demos; \(2\) ICL\-Diversity: 20 demos viakk\-means on Sentence\-BERTReimers and Gurevych \([2019](https://arxiv.org/html/2607.20497#bib.bib4)\); \(3\) APEZhouet al\.\([2023](https://arxiv.org/html/2607.20497#bib.bib15)\): best\-of\-5 instructions; \(4\) DSPyKhattabet al\.\([2024](https://arxiv.org/html/2607.20497#bib.bib32)\); Sarmahet al\.\([2024](https://arxiv.org/html/2607.20497#bib.bib33)\): MIPROv2auto="light"; \(5\) GEPAAgrawalet al\.\([2026](https://arxiv.org/html/2607.20497#bib.bib34)\): evolutionary prompt optimization \(our primary comparison target as the closest iterative method\)\.

### 4\.2Main Results

[Table˜1](https://arxiv.org/html/2607.20497#S3.T1)shows results on 8 classification benchmarks\.

#### ERGO wins on boundary\-learnable tasks\.

On TREC \(\+4\.7% over GEPA,p=0\.004p\{=\}0\.004\) and CLINC150 \(\+1\.2%,p=0\.043p\{=\}0\.043\), ERGO’s error\-driven refinement discovers decision rules that exploration\-based search cannot\. These are tasks where classification errors concentrate in specific confused pairs amenable to natural\-language rules\.

#### Other paradigms win on coverage tasks\.

ICL\-Diversity wins on 20Newsgroups \(70\.8% vs ERGO’s 66\.8%,p=0\.013p\{=\}0\.013\), ICL\-Uniform on MASSIVE \(90\.1% vs 87\.8%,p<0\.001p\{<\}0\.001\), and DSPy on Yahoo \(73\.9% vs 71\.7%,p=0\.046p\{=\}0\.046\)\. These tasks require broad coverage of many overlapping categories where demonstrations or exploration outperform targeted rules\.

#### Overall: no method dominates\.

ERGO averages 85\.6%, statistically tied with ICL\-Diversity \(85\.6%\), DSPy \(85\.7%\), and GEPA \(85\.4%\), all pairwisep\>0\.6p\{\>\}0\.6\. Only APE is significantly worse \(p=0\.013p\{=\}0\.013\)\. The contribution is not a new state\-of\-the\-art but identifying when each paradigm provides unique value: ERGO for boundary\-learnable tasks, ICL for coverage tasks, and DSPy/GEPA for broad\-coverage optimization\.

## 5Quantitative Analysis

### 5\.1Convergence: Rapid Error\-Driven Learning

![Refer to caption](https://arxiv.org/html/2607.20497v1/images/convergence_ethos.png)\(a\)Ethos: 68%→\\rightarrow88\.6% in 3 iters
![Refer to caption](https://arxiv.org/html/2607.20497v1/images/convergence_trec.png)\(b\)TREC: 74\.5%→\\rightarrow91\.4% in 3 iters

Figure 2:ERGO convergence on boundary\-learnable tasks\. Dashed lines: ICL\-Div, GEPA, and DSPy baselines\. ERGO captures 80% of total gain in the first 3 iterations\.[Figure˜2](https://arxiv.org/html/2607.20497#S5.F2)shows ERGO’s convergence on the two tasks with most dramatic early improvement\. On Ethos, ERGO jumps from 68% to 88\.6% \(\+20\.6%\) in just 3 iterations as it learns the profanity\-vs\-targeting boundary\. On TREC, it jumps from 74\.5% to 91\.4% \(\+16\.9%\) as it discovers the organizations\-as\-human\-beings convention\. Both surpass GEPA’s final accuracy within 1–2 iterations; on TREC, ERGO also surpasses DSPy\.

### 5\.2Homogeneous Training: Model Generalization

To test whether ERGO generalizes beyond Claude, we run the full protocol \(optimize, validate, and infer with the same model\) on five models from four families: Claude Haiku 4\.5 and Sonnet 4\.5, Gemma 3 27B IT, and Mistral Large 3 \([Table˜2](https://arxiv.org/html/2607.20497#S5.T2); per\-dataset breakdown in[Table˜10](https://arxiv.org/html/2607.20497#A3.T10)\)\. Pooled across all 200 \(model, dataset, seed\) triples, ERGO improves over the baseline by\+5\.67\+5\.67pp \(t=6\.34t\{=\}6\.34,p=1\.5×10−9p\{=\}1\.5\{\\times\}10^\{\-9\}\)\. Four of five models gain significantly with the same meta\-prompt and no model\-specific tuning\. ERGO wins on61\.0%61\.0\\%of individual \(dataset, seed\) pairs\.

#### Largest gains come from weak\-baseline datasets\.

ETHOS \(\+28\.7\+28\.7pp\) and TREC \(\+16\.4\+16\.4pp\) drive most of the cross\-model improvement: the seed prompt produces near\-random output for several models, and ERGO’s error\-driven feedback corrects these issues within a few iterations\. On near\-ceiling tasks \(≥0\.93\\geq 0\.93baseline\) gains are minimal\.

Table 2:Homogeneous training: ERGO vs\. seed\-prompt baseline across model families \(8 datasets, 5 seeds,N=40N\{=\}40per model\)\.Δ\\Deltain percentage points;pp\-value from pairedtt\-test\.p∗⁣∗∗<0\.001\{\}^\{\*\*\*\}\\,p\{<\}0\.001,p∗∗<0\.01\{\}^\{\*\*\}\\,p\{<\}0\.01,p∗<0\.05\{\}^\{\*\}\\,p\{<\}0\.05\.ModelBaselineERGOΔ\\Delta\(pp\)Sonnet 4\.580\.3085\.55\+5\.25∗∗\+5\.25^\{\*\*\}Haiku 4\.574\.0982\.37\+8\.29∗∗\+8\.29^\{\*\*\}Mistral L375\.4478\.97\+3\.53∗\+3\.53^\{\*\}Gemma 3 27B69\.3370\.51\+1\.18n\.s\.\+1\.18^\{\\text\{n\.s\.\}\}Overall74\.3179\.98\+5\.67∗⁣∗∗\\mathbf\{\+5\.67^\{\*\*\*\}\}

### 5\.3Homogeneous Training: Ablation Studies

We isolate the effect of four ERGO hyperparameters on Sonnet 4\.5 across all 8 datasets with 3 seeds \([Table˜13](https://arxiv.org/html/2607.20497#A5.T13)in Appendix\)\. Each ablation varies one parameter and holds the others at their defaults \(T=10\{=\}10, batch sizek=20k\{=\}20, shuffle batches, full prompt rewrite\)\. Significance is pairedtt\-test against the default,N=24N\{=\}24\.

#### Iterations\.

Accuracy plateaus rapidly\. No variant differs significantly from T=10\{=\}10\(allp\>0\.35p\{\>\}0\.35\)\. T=5\{=\}5vs T=1\{=\}1is not significant \(\+0\.18\+0\.18pp,p=0\.59p\{=\}0\.59\); T=15\{=\}15adds nothing over T=5\{=\}5\(\+0\.08\+0\.08pp,p=0\.77p\{=\}0\.77\)\. T=5\{=\}5reaches 99% of T=10\{=\}10accuracy at 73% of the cost \(1056 vs 1444 LLM calls\)\.

#### Batch size\.

Larger batches are more cost\-efficient under shuffle\-once batching\.k=50k\{=\}50uses 30% fewer LLM calls thank=20k\{=\}20because larger batches exhaust training data sooner\.k=50k\{=\}50vsk=5k\{=\}5is the only significant comparison \(\+1\.29\+1\.29pp,p=7\.5×10−3p\{=\}7\.5\{\\times\}10^\{\-3\}\); no individual variant differs significantly from the default\.

#### Contrast sample\.

Shuffle \(non\-overlapping random batches\) outperforms class\-balanced sampling by0\.530\.53pp \(p=0\.42p\{=\}0\.42, n\.s\.\) while using 18% fewer calls\. Balanced helps on many\-class tasks \(CLINC150\+1\.78\+1\.78, TREC\+2\.14\+2\.14, 20Newsgroups\+1\.13\+1\.13\) but hurts on naturally imbalanced ones \(Yahoo−5\.00\-5\.00, Ethos−1\.81\-1\.81\)\. We retain shuffle as the default for cost reasons\.

#### Component\.

Restricting the LLM to rewrite only the demonstrations yields the highest accuracy \(\+0\.67\+0\.67pp over full,p=0\.087p\{=\}0\.087\), though the difference does not reach significance at the 5% level\. Rewriting only the instruction or only the rules performs no better than the default\. The trend suggests example refinement carries most of ERGO’s signal\. However, demos\-only drops 5\.5 pp on TREC, precisely the boundary\-learnable task where explicit rules are essential\. We retain joint rewriting as the default because it produces explicit, auditable decision rules and avoids catastrophic failures on tasks requiring them\.

#### Robustness\.

Across all 16 ablation variants the spread is1\.401\.40pp \(84\.85–86\.24\), and only thek=50k\{=\}50batch\-size variant significantly outperforms the default\. ERGO is robust to the choice of T, batch size, contrast strategy, and component\.

### 5\.4Heterogeneous Training: Sonnet Refines, Haiku Infers

We next decouple the refinement and inference models\. Claude Sonnet 4\.5 runs the ERGO loop \(generating refined prompts from its own classifications and feedback\), and the resulting best\-on\-val prompt is then used by Claude Haiku 4\.5 for test\-time inference \([Table˜3](https://arxiv.org/html/2607.20497#S5.T3); per\-dataset numbers in[Table˜11](https://arxiv.org/html/2607.20497#A3.T11)\)\. Sonnet\-refined prompts give Haiku a\+8\.83\+8\.83pp lift over its seed\-prompt baseline \(t=3\.52t\{=\}3\.52,p=1\.1×10−3p\{=\}1\.1\{\\times\}10^\{\-3\}\)\. The gap to homogeneous Haiku\-ERGO is\+0\.55\+0\.55pp, which is not significant \(p=0\.22p\{=\}0\.22\)\. The optimized prompt thus carries task knowledge that transfers cleanly to a smaller inference model: a stronger model can be used once for refinement, and the resulting prompt can be deployed with a cheaper model at no measurable accuracy cost\.

Table 3:Heterogeneous training: prompts refined on Sonnet 4\.5 are used by Haiku 4\.5 at test time \(8 datasets, 5 seeds\)\. Hetero vs\. baseline:p=0\.001p\{=\}0\.001; hetero vs\. homo:p=0\.22p\{=\}0\.22\(n\.s\.\)\.SettingAccBaseline \(seed prompt, Haiku\)74\.1Heterogeneous ERGO \(Sonnet→\\rightarrowHaiku\)82\.9Homogeneous ERGO \(Haiku→\\rightarrowHaiku\)82\.4
### 5\.5Robustness to Annotation Noise

We identify 162 queries \(4\.6% of all test data\) where ERGO, DSPy, and GEPA across all 5 seeds unanimously predict the same “wrong” answer\. Manual review confirms the majority are clear annotation errors \(e\.g\., gold labels contradicting the text\), with the remainder being ambiguous boundary cases\. Removing these, the relative performance gaps are unchanged \(ERGO vs GEPA: \+0\.3% raw→\\rightarrow\+0\.3% clean\), confirming that ERGO’s advantage comes from learning genuine task conventions, not fitting annotation noise\.

Table 4:Paradigm selection guide based on task characteristics\.Task characteristicRecommended paradigmMethodExample datasetsLearnable boundariesDiagnoseERGOTREC, Ethos, CLINC150Need interpretable outputDiagnoseERGOEthosMany\-class \+ broadExploreDSPyMASSIVE, YahooMany overlapping classesDemonstrateICL20NewsZero optimization budgetDemonstrateICLAnyNear\-ceiling tasksAnyICL \(cheapest\)Rotten Tom\.

## 6Case Studies

The quantitative results show that ERGO wins on boundary\-learnable tasks; here we show why, examining how single errors trigger generalizable principles: hidden labeling conventions \(TREC\), progressive boundary refinement \(Ethos\), and structural rules that generalize across label pairs \(CLINC150\)\.

### 6\.1TREC: Learning Hidden Conventions

TREC \(6\-class question type classification\) contains a counterintuitive labeling convention: questions about companies, schools, or organizations should be classified as “human beings,” a rule that cannot be inferred from the label name alone\. For instance, “What is the first personal computer company?” and “What army’s motto is Blood and Fire?” are both gold\-labeled “human beings” \(full table in[Appendix˜B](https://arxiv.org/html/2607.20497#A2)\)\.

ERGO discovers this convention at iteration 3 \(seed 123\), when the batch contains “What Japanese electronics company was named for a coastal city?” misclassified as “entities\.” The meta\-prompt diagnoses:*“The classifier incorrectly treats companies as entities rather than human organizations,”*and prescribes:*“Add rule: ‘What \[company/organization/band/team\]’→\\rightarrowhuman beings\.”*This single error triggers a rule that fixes 25\+ test queries across all seeds\. Per\-class analysis confirms ERGO’s gains concentrate on the “human beings” class \(\+5\.5 pp over ICL\-Diversity;[Table˜7](https://arxiv.org/html/2607.20497#A2.T7)\)\.

### 6\.2Ethos: Progressive Boundary Refinement

Ethos \(binary hate speech detection\) requires distinguishing profanity without identity\-group targeting \(not hate speech\) from genuine hate speech\. ERGO learns this boundary progressively over 3 iterations:

At iteration 1 \(9 mistakes\), it diagnoses that the prompt lacks clarity on True vs\. False and prescribes: “True requires BOTH targeting based on identity AND dehumanization/threats,” jumping from 68% to 86\.8%\. Iteration 2 \(6 mistakes\) adds that “dismissing a condition in abstract terms≠\\neqtargeting people with that condition\.” Iteration 3 \(4 mistakes\) adds that “economic status and occupation are NOT protected characteristics\.”

The result: texts like “Holy shit\! Kill them all\!” and “Go f\*\*\*ing kill yourself… useless pile of shit scumbag” are correctly classified as False \(not hate speech\) because they lack identity\-group targeting \(full table in[Appendix˜B](https://arxiv.org/html/2607.20497#A2)\)\. The final prompt is also directly interpretable: a practitioner can read “Label as True only if targeting a protected identity group AND includes dehumanization, threats, or calls for discrimination” and audit, refine, or use it as an annotation guideline\.

### 6\.3CLINC150: Structural Rule Generalization

CLINC150 \(150\-class intent detection\) contains many near\-identical label pairs that differ only by action vs\. status: “set up a reminder so I don’t forget the baby shower” should map toreminder\_update\(creating\), notreminder\(querying\)\.

ERGO learns the general principle from a single misclassified example: creating or modifying maps to\_updatevariants, while querying or viewing maps to base variants\. This structural rule generalizes across multiple label pairs \(reminder/reminder\_update, calendar/calendar\_update, freeze\_account/account\_blocked\): a single principle learned from one error fixes an entire class of confusions \([Table˜9](https://arxiv.org/html/2607.20497#A2.T9)\)\.

## 7Comparative Analysis

The three paradigms are complementary:*demonstrate*\(ICL\) excels on coverage\-dependent tasks,*explore*\(DSPy/GEPA\) on many\-class tasks, and*diagnose*\(ERGO\) on boundary\-learnable tasks\.

### 7\.1ERGO vs\. GEPA: Error\-Driven vs\. Exploration\-Based

We compare against GEPA as the closest iterative method: both refine instruction\-based prompts, but GEPA generates rules via evolutionary search while ERGO learns them incrementally from errors\.

Across our benchmarks, we identify 113 queries where ERGO consistently gets right but GEPA gets wrong \(3\+ seeds\), and 84 in the reverse direction\.

#### Why they fail in opposite ways:

ERGO over\-constrains \(rules too specific misfire on edge cases\); GEPA under\-constrains \(generic guidelines miss task\-specific boundaries\)\. On TREC, GEPA’s rule covers only organizations that “did something,” missing identification questions\. Conversely, ERGO’s “profanity≠\\neqhate” rule misses gendered slurs that GEPA’s broader definition catches\. The failure modes are complementary: ERGO excels on tasks with learnable boundaries \(TREC, Ethos, CLINC150\); GEPA on broad\-coverage tasks \(20Newsgroups, Yahoo, MASSIVE; see[Appendix˜B](https://arxiv.org/html/2607.20497#A2)for a detailed 20Newsgroups example\)\.

#### Convergence and stability:

On boundary\-learnable tasks, ERGO converges in 3 iterations \(Ethos: 68%→\\rightarrow88\.6%, TREC: 74\.5%→\\rightarrow91\.4%\), surpassing GEPA’s final accuracy within 1–2 iterations\. GEPA finds one good mutation early then cannot improve further \(Ethos: 1 accepted out of 124 iterations\)\. ERGO is 4–10×\\timesmore stable across seeds \(Ethos: std 0\.13% vs 1\.25%\) because learned rules apply deterministically \([Table˜12](https://arxiv.org/html/2607.20497#A4.T12)\)\.

### 7\.2ERGO vs\. ICL: Rules vs\. Demonstrations

ICL\-Diversity edges ERGO overall \(85\.9% vs\. 85\.6%\), though the difference is not statistically significant\. ERGO wins on 4 boundary\-learnable tasks \(Ethos \+2\.6%, RTE \+1\.9%, CLINC150 \+1\.4%, TREC \+0\.7%\); ICL wins on broad\-coverage tasks \(20Newsgroups−\-4\.0%, MASSIVE−\-1\.3%\)\.

#### Why they differ:

Demonstrations cannot express abstract rules\. On Ethos, a demo showing “Kill them all = False” helps one query, but ERGO’s explicit rule “profanity without group targeting = False” generalizes to all similar cases\. On CLINC150, 20 demos cover only 13% of 150 labels and cannot demonstrate the action\-vs\-status distinction for most pairs\. Conversely, on broad\-coverage tasks, ICL’s holistic pattern matching outperforms ERGO’s keyword\-based rules that misfire across overlapping categories\. The fundamental tradeoff: rules are precise but brittle; demonstrations are robust but implicit\.

### 7\.3When Does Each Paradigm Win?

A key finding is that the cheapest method \(ICL\-Diversity, zero optimization cost\) is already optimal on the majority of tasks — iterative optimization is justified only under specific, identifiable conditions \([Table˜4](https://arxiv.org/html/2607.20497#S5.T4)\)\.

We recommend the following decision procedure: \(1\) start with ICL\-Diversity as a baseline; \(2\) if classification errors concentrate in specific confused label pairs, apply ERGO — it typically converges in 3\-5 iterations, produces stable results across seeds, and yields auditable rules; \(3\) if the task has many classes with overlapping categories, try DSPy’s structured taxonomy framing; \(4\) when interpretability is required, prefer ERGO’s auditable decision rules\.

For near\-ceiling tasks where all methods converge to similar accuracy, ICL is the cheapest option and optimization provides no measurable benefit\. This framework enables practitioners to select the appropriate paradigm based on task characteristics rather than defaulting to the most complex method\.

## 8Conclusion

We propose ERGO, a prompt optimization method that iterates over the full training set in non\-overlapping batches, diagnoses classification errors using both mistakes and correct predictions as contrast, and generates interpretable decision rules\. Through case studies on 8 classification benchmarks, we demonstrate that error\-driven refinement discovers task conventions invisible to other paradigms, such as “organizations = human beings” in TREC and “profanity without targeting≠\\neqhate speech” in Ethos\.

Our central finding is that the three paradigms \(demonstrate, explore, and diagnose\) are complementary rather than competing: no method significantly outperforms the others overall\. ERGO excels on boundary\-learnable tasks, ICL\-Diversity on coverage\-dependent tasks at zero optimization cost, and DSPy/GEPA on many\-class tasks requiring broad exploration\.

The practical contribution is a paradigm selection framework linking task characteristics to the optimal method\. Future work includes adapting batch strategies for many\-class settings and exploring hybrid approaches that combine multiple paradigms\.

## Limitations

#### Not universally better\.

ERGO is statistically tied with ICL\-Diversity overall, though it shows lower accuracy on coverage\-dependent tasks such as 20Newsgroups and MASSIVE\. We do not claim dominance; the contribution is identifying when error\-driven refinement provides unique value\.

#### Task scope\.

ERGO is designed for classification with learnable boundaries and is not suitable for generation or multi\-hop reasoning\. All benchmarks are English\-only, and while they span diverse domains and class counts, many task domains \(e\.g\., legal, medical\) remain untested; generalizability beyond our benchmark suite remains to be validated\.

#### Scaling and batch coverage\.

The fixed batch size \(k=20k\{=\}20\) may need adjustment for many\-class tasks\. On CLINC150 \(150 classes\) and MASSIVE \(60 classes\), random 20\-item batches cover only 10–15% of classes per iteration, limiting error signal diversity\. As the number of classes grows, the generated rules may not generalize across all class boundaries, and limited or imbalanced training data may not expose representative error patterns\.

#### Heterogeneous training assumption\.

We assume the learning model \(which generates rules\) is at least as strong as the task model \(which applies them at inference\)\. Weak\-to\-strong settings \(e\.g\., Haiku optimizing prompts for Sonnet\) remain to be validated\.

#### Use of AI assistants\.

AI writing assistants were used for language editing and literature searching during the preparation of this manuscript\. All generated content was verified, revised, and approved by the authors, who take full responsibility for the final text\.

## References

- E\. Agarwal, R\. Magazine, J\. Singh, V\. Dani, T\. Ganu, and A\. Nambi \(2025\)PromptWizard: optimizing prompts via task\-aware, feedback\-driven self\-evolution\.InFindings of the Association for Computational Linguistics: ACL 2025,Vienna, Austria,pp\. 19974–20003\.External Links:[Link](https://aclanthology.org/2025.findings-acl.1025/)Cited by:[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px2.p1.1)\.
- L\. A\. Agrawal, S\. Tan, D\. Soylu, N\. Ziems, R\. Khare, K\. Opsahl\-Ong, A\. Singhvi, H\. Shandilya, M\. J\. Ryan, M\. Jiang, C\. Potts, K\. Sen, A\. Dimakis, I\. Stoica, D\. Klein, M\. Zaharia, and O\. Khattab \(2026\)GEPA: reflective prompt evolution can outperform reinforcement learning\.InInternational Conference on Learning Representations,External Links:[Link](https://openreview.net/forum?id=RQm2KQTM5r)Cited by:[§1](https://arxiv.org/html/2607.20497#S1.p2.1),[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px2.p1.1),[§4\.1](https://arxiv.org/html/2607.20497#S4.SS1.SSS0.Px4.p1.1)\.
- I\. Botunac, M\. Brkić Bakarić, and M\. Matetić \(2024\)Comparing fine\-tuning and prompt engineering for multi\-class classification in hospitality review analysis\.Applied Sciences14\(14\),pp\. 6254\.External Links:[Document](https://dx.doi.org/10.3390/app14146254),[Link](https://doi.org/10.3390/app14146254)Cited by:[§1](https://arxiv.org/html/2607.20497#S1.p1.1)\.
- T\. B\. Brown, B\. Mann, N\. Ryder, M\. Subbiah, J\. Kaplan, P\. Dhariwal, A\. Neelakantan, P\. Shyam, G\. Sastry, A\. Askell, S\. Agarwal, A\. Herbert\-Voss, G\. Krueger, T\. Henighan, R\. Child, A\. Ramesh, D\. M\. Ziegler, J\. Wu, C\. Winter, C\. Hesse, M\. Chen, E\. Sigler, M\. Litwin, S\. Gray, B\. Chess, J\. Clark, C\. Berner, S\. McCandlish, A\. Radford, I\. Sutskever, and D\. Amodei \(2020\)Language models are few\-shot learners\.InAdvances in Neural Information Processing Systems,Vol\.33,pp\. 1877–1901\.External Links:[Link](https://proceedings.neurips.cc/paper/2020/hash/1457c0d6bfcb4967418bfb8ac142f64a-Abstract.html)Cited by:[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px1.p1.2)\.
- M\. Deng, J\. Wang, C\. Hsieh, Y\. Wang, H\. Guo, T\. Shu, M\. Song, E\. Xing, and Z\. Hu \(2022\)RLPrompt: optimizing discrete text prompts with reinforcement learning\.InProceedings of the 2022 Conference on Empirical Methods in Natural Language Processing,Abu Dhabi, United Arab Emirates,pp\. 3369–3391\.External Links:[Document](https://dx.doi.org/10.18653/v1/2022.emnlp-main.222),[Link](https://aclanthology.org/2022.emnlp-main.222/)Cited by:[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px2.p1.1)\.
- J\. Devlin, M\. Chang, K\. Lee, and K\. Toutanova \(2019\)BERT: pre\-training of deep bidirectional transformers for language understanding\.InProceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies,Vol\.1,Minneapolis, Minnesota,pp\. 4171–4186\.External Links:[Document](https://dx.doi.org/10.18653/v1/N19-1423),[Link](https://aclanthology.org/N19-1423)Cited by:[§1](https://arxiv.org/html/2607.20497#S1.p1.1)\.
- Q\. Dong, L\. Li, D\. Dai, C\. Zheng, J\. Ma, R\. Li, H\. Xia, J\. Xu, Z\. Wu, B\. Chang, X\. Sun, L\. Li, and Z\. Sui \(2024\)A survey on in\-context learning\.InProceedings of the 2024 Conference on Empirical Methods in Natural Language Processing,Miami, Florida, USA,pp\. 1107–1128\.External Links:[Document](https://dx.doi.org/10.18653/v1/2024.emnlp-main.64),[Link](https://aclanthology.org/2024.emnlp-main.64)Cited by:[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px1.p1.2)\.
- J\. FitzGerald, C\. Hench, C\. Peris, S\. Mackie, K\. Rottmann, A\. Sanchez, A\. Nash, L\. Urbach, V\. Kakarala, R\. Singh, S\. Ranganath, L\. Crist, M\. Britan, W\. Leeuwis, G\. Tur, and P\. Natarajan \(2023\)MASSIVE: a 1m\-example multilingual natural language understanding dataset with 51 typologically\-diverse languages\.InProceedings of the 61st Annual Meeting of the Association for Computational Linguistics \(Volume 1: Long Papers\),Toronto, Canada,pp\. 4277–4302\.External Links:[Document](https://dx.doi.org/10.18653/v1/2023.acl-long.235),[Link](https://aclanthology.org/2023.acl-long.235/)Cited by:[Table 5](https://arxiv.org/html/2607.20497#A1.T5.3.9.1)\.
- Q\. Guo, L\. Wang, Y\. Wang, W\. Ye, and S\. Zhang \(2024\)What makes a good order of examples in in\-context learning\.InFindings of the Association for Computational Linguistics: ACL 2024,Bangkok, Thailand,pp\. 14892–14904\.External Links:[Document](https://dx.doi.org/10.18653/v1/2024.findings-acl.884),[Link](https://aclanthology.org/2024.findings-acl.884/)Cited by:[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px1.p1.2)\.
- O\. Honovich, U\. Shaham, S\. R\. Bowman, and O\. Levy \(2023\)Instruction induction: from few examples to natural language task descriptions\.InProceedings of the 61st Annual Meeting of the Association for Computational Linguistics \(Volume 1: Long Papers\),Toronto, Canada,pp\. 1935–1952\.External Links:[Document](https://dx.doi.org/10.18653/v1/2023.acl-long.108),[Link](https://aclanthology.org/2023.acl-long.108/)Cited by:[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px2.p1.1)\.
- O\. Khattab, A\. Singhvi, P\. Maheshwari, Z\. Zhang, K\. Santhanam, S\. Vardhamanan, S\. Haq, A\. Sharma, T\. T\. Joshi, H\. Moazam, H\. Miller, M\. Zaharia, and C\. Potts \(2024\)DSPy: compiling declarative language model calls into state\-of\-the\-art pipelines\.InInternational Conference on Learning Representations,External Links:[Link](https://openreview.net/forum?id=sY5N0zY5Od)Cited by:[§1](https://arxiv.org/html/2607.20497#S1.p1.1),[§1](https://arxiv.org/html/2607.20497#S1.p2.1),[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px2.p1.1),[§4\.1](https://arxiv.org/html/2607.20497#S4.SS1.SSS0.Px4.p1.1)\.
- K\. Lang \(1995\)NewsWeeder: learning to filter netnews\.InMachine Learning Proceedings 1995,pp\. 331–339\.External Links:[Document](https://dx.doi.org/10.1016/B978-1-55860-377-6.50048-7),[Link](https://doi.org/10.1016/B978-1-55860-377-6.50048-7)Cited by:[Table 5](https://arxiv.org/html/2607.20497#A1.T5.3.8.1)\.
- S\. Larson, A\. Mahendran, J\. J\. Peper, C\. Clarke, A\. Lee, P\. Hill, J\. K\. Kummerfeld, K\. Leach, M\. A\. Laurenzano, L\. Tang, and J\. Mars \(2019\)An evaluation dataset for intent classification and out\-of\-scope prediction\.InProceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing,Hong Kong, China,pp\. 1311–1316\.External Links:[Document](https://dx.doi.org/10.18653/v1/D19-1131),[Link](https://aclanthology.org/D19-1131/)Cited by:[Table 5](https://arxiv.org/html/2607.20497#A1.T5.3.3.1)\.
- S\. Leone \(2020\)Rotten tomatoes movies and critic reviews dataset\.Kaggle\.External Links:[Link](https://www.kaggle.com/datasets/stefanoleone992/rotten-tomatoes-movies-and-critic-reviews-dataset)Cited by:[Table 5](https://arxiv.org/html/2607.20497#A1.T5.3.7.1)\.
- W\. Li, X\. Wang, W\. Li, and B\. Jin \(2025\)A survey of automatic prompt engineering: an optimization perspective\.External Links:2502\.11560,[Document](https://dx.doi.org/10.48550/arXiv.2502.11560),[Link](https://arxiv.org/abs/2502.11560)Cited by:[§1](https://arxiv.org/html/2607.20497#S1.p1.1)\.
- X\. Li and D\. Roth \(2002\)Learning question classifiers\.InCOLING 2002: The 19th International Conference on Computational Linguistics,External Links:[Link](https://aclanthology.org/C02-1150/)Cited by:[Table 5](https://arxiv.org/html/2607.20497#A1.T5.3.2.1)\.
- J\. Liu, D\. Shen, Y\. Zhang, B\. Dolan, L\. Carin, and W\. Chen \(2022\)What makes good in\-context examples for GPT\-3?\.InProceedings of Deep Learning Inside Out \(DeeLIO 2022\): The 3rd Workshop on Knowledge Extraction and Integration for Deep Learning Architectures,Dublin, Ireland and Online,pp\. 100–114\.External Links:[Document](https://dx.doi.org/10.18653/v1/2022.deelio-1.10),[Link](https://aclanthology.org/2022.deelio-1.10)Cited by:[§1](https://arxiv.org/html/2607.20497#S1.p1.1),[§1](https://arxiv.org/html/2607.20497#S1.p2.1),[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px1.p1.2)\.
- A\. Madaan, N\. Tandon, P\. Gupta, S\. Hallinan, L\. Gao, S\. Wiegreffe, U\. Alon, N\. Dziri, S\. Prabhumoye, Y\. Yang, S\. Gupta, B\. P\. Majumder, K\. Hermann, S\. Welleck, A\. Yazdanbakhsh, and P\. Clark \(2023\)Self\-refine: iterative refinement with self\-feedback\.InAdvances in Neural Information Processing Systems,Vol\.36\.External Links:[Link](https://proceedings.neurips.cc/paper_files/paper/2023/hash/91edff07232fb1b55a505a9e9f6c0ff3-Abstract-Conference.html)Cited by:[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px2.p1.1)\.
- K\. Margatina, T\. Schick, N\. Aletras, and J\. Dwivedi\-Yu \(2023\)Active learning principles for in\-context learning with large language models\.InFindings of the Association for Computational Linguistics: EMNLP 2023,Singapore,pp\. 5011–5034\.External Links:[Document](https://dx.doi.org/10.18653/v1/2023.findings-emnlp.334),[Link](https://aclanthology.org/2023.findings-emnlp.334)Cited by:[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px1.p1.2)\.
- I\. Mollas, Z\. Chrysopoulou, S\. Karlos, and G\. Tsoumakas \(2022\)ETHOS: a multi\-label hate speech detection dataset\.Complex & Intelligent Systems8\(6\),pp\. 4663–4678\.External Links:[Document](https://dx.doi.org/10.1007/s40747-021-00608-2)Cited by:[Table 5](https://arxiv.org/html/2607.20497#A1.T5.3.5.1),[§4\.1](https://arxiv.org/html/2607.20497#S4.SS1.SSS0.Px1.p1.1)\.
- R\. Pryzant, D\. Iter, J\. Li, Y\. Lee, C\. Zhu, and M\. Zeng \(2023\)Automatic prompt optimization with “gradient descent” and beam search\.InProceedings of the 2023 conference on empirical methods in natural language processing,pp\. 7957–7968\.Cited by:[§1](https://arxiv.org/html/2607.20497#S1.p1.1),[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px3.p1.2)\.
- K\. Ramnath, K\. Zhou, S\. Guan, S\. S\. Mishra, X\. Qi, Z\. Shen, S\. Wang, S\. Woo, S\. Jeoung, Y\. Wang, H\. Wang, H\. Ding, Y\. Lu, Z\. Xu, Y\. Zhou, B\. Srinivasan, Q\. Yan, Y\. Chen, H\. Ding, P\. Xu, and L\. L\. Cheong \(2025\)A systematic survey of automatic prompt optimization techniques\.InProceedings of the 2025 Conference on Empirical Methods in Natural Language Processing,Suzhou, China,pp\. 33078–33110\.External Links:[Document](https://dx.doi.org/10.18653/v1/2025.emnlp-main.1681),[Link](https://aclanthology.org/2025.emnlp-main.1681/)Cited by:[§1](https://arxiv.org/html/2607.20497#S1.p1.1)\.
- N\. Reimers and I\. Gurevych \(2019\)Sentence\-bert: sentence embeddings using siamese bert\-networks\.InProceedings of the 2019 conference on empirical methods in natural language processing and the 9th international joint conference on natural language processing \(EMNLP\-IJCNLP\),pp\. 3982–3992\.Cited by:[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px1.p1.2),[§4\.1](https://arxiv.org/html/2607.20497#S4.SS1.SSS0.Px4.p1.1)\.
- P\. Sahoo, A\. K\. Singh, S\. Saha, V\. Jain, S\. Mondal, and A\. Chadha \(2024\)A systematic survey of prompt engineering in large language models: techniques and applications\.External Links:2402\.07927,[Link](https://arxiv.org/abs/2402.07927)Cited by:[§1](https://arxiv.org/html/2607.20497#S1.p1.1)\.
- B\. Sarmah, K\. Dutta, A\. Grigoryan, S\. Tiwari, S\. Pasquali, and D\. Mehta \(2024\)A comparative study of DSPy teleprompter algorithms for aligning large language models evaluation metrics to human evaluation\.External Links:2412\.15298,[Document](https://dx.doi.org/10.48550/arXiv.2412.15298),[Link](https://arxiv.org/abs/2412.15298)Cited by:[§4\.1](https://arxiv.org/html/2607.20497#S4.SS1.SSS0.Px4.p1.1)\.
- H\. Su, J\. Kasai, C\. H\. Wu, W\. Shi, T\. Wang, J\. Xin, R\. Zhang, M\. Ostendorf, L\. Zettlemoyer, N\. A\. Smith, and T\. Yu \(2023\)Selective annotation makes language models better few\-shot learners\.InInternational Conference on Learning Representations,External Links:[Link](https://openreview.net/forum?id=qY1hlv7gwg)Cited by:[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px1.p1.2)\.
- A\. Wang, A\. Singh, J\. Michael, F\. Hill, O\. Levy, and S\. Bowman \(2018\)GLUE: a multi\-task benchmark and analysis platform for natural language understanding\.InProceedings of the 2018 EMNLP workshop BlackboxNLP: Analyzing and interpreting neural networks for NLP,pp\. 353–355\.Cited by:[Table 5](https://arxiv.org/html/2607.20497#A1.T5.3.4.1),[§4\.1](https://arxiv.org/html/2607.20497#S4.SS1.SSS0.Px1.p1.1)\.
- C\. Yang, X\. Wang, Y\. Lu, H\. Liu, Q\. V\. Le, D\. Zhou, and X\. Chen \(2024\)Large language models as optimizers\.InInternational Conference on Learning Representations,External Links:[Link](https://openreview.net/forum?id=Bb4VGOWELI)Cited by:[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px2.p1.1)\.
- W\. Yu, D\. Iter, S\. Wang, Y\. Xu, M\. Ju, S\. Sanyal, C\. Zhu, M\. Zeng, and M\. Jiang \(2023\)Generate rather than retrieve: large language models are strong context generators\.InInternational Conference on Learning Representations,External Links:[Link](https://openreview.net/forum?id=fB0hRu9GZUS)Cited by:[§1](https://arxiv.org/html/2607.20497#S1.p2.1),[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px1.p1.2)\.
- X\. Zhang, J\. Zhao, and Y\. LeCun \(2015\)Character\-level convolutional networks for text classification\.InAdvances in Neural Information Processing Systems,C\. Cortes, N\. Lawrence, D\. Lee, M\. Sugiyama, and R\. Garnett \(Eds\.\),Vol\.28,pp\.\.External Links:[Link](https://proceedings.neurips.cc/paper_files/paper/2015/file/250cf8b51c773f3f8dc8b4be867a9a02-Paper.pdf)Cited by:[Table 5](https://arxiv.org/html/2607.20497#A1.T5.3.6.1)\.
- X\. Zhang, G\. Wang, Y\. Cui, W\. Qiu, Z\. Li, B\. Zhu, and P\. He \(2026\)Prompt optimization is a coin flip: diagnosing when it helps in compound AI systems\.External Links:2604\.14585,[Document](https://dx.doi.org/10.48550/arXiv.2604.14585),[Link](https://arxiv.org/abs/2604.14585)Cited by:[§1](https://arxiv.org/html/2607.20497#S1.p1.1),[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px4.p1.1)\.
- Y\. Zhou, A\. I\. Muresanu, Z\. Han, K\. Paster, S\. Pitis, H\. Chan, and J\. Ba \(2023\)Large language models are human\-level prompt engineers\.InInternational Conference on Learning Representations,External Links:[Link](https://openreview.net/forum?id=92gvk82DE-)Cited by:[§1](https://arxiv.org/html/2607.20497#S1.p1.1),[§1](https://arxiv.org/html/2607.20497#S1.p2.1),[§2](https://arxiv.org/html/2607.20497#S2.SS0.SSS0.Px2.p1.1),[§4\.1](https://arxiv.org/html/2607.20497#S4.SS1.SSS0.Px4.p1.1)\.

## Appendix ADataset Details

[Table˜5](https://arxiv.org/html/2607.20497#A1.T5)summarizes the 8 classification benchmarks used in our evaluation, spanning 2 to 150 classes across diverse domains\. Training sets provide ERGO’s refinement batches\. Validation sets are used for prompt selection\. Test sets are held out for final reporting\. All datasets are publicly available and used consistent with their intended purpose of classification benchmarking\. No dataset is used outside its original research context\.

Table 5:Dataset statistics\. All splits are stratified; many\-class datasets ensure≥\\geq2 examples per class in training\.DatasetClassesTrainValTestDomainTRECLi and Roth \([2002](https://arxiv.org/html/2607.20497#bib.bib36)\)6198102451Question typeCLINC150Larsonet al\.\([2019](https://arxiv.org/html/2607.20497#bib.bib37)\)150150150450Intent detectionRTEWanget al\.\([2018](https://arxiv.org/html/2607.20497#bib.bib2)\)28040157NLIEthosMollaset al\.\([2022](https://arxiv.org/html/2607.20497#bib.bib1)\)2200100698Hate speechYahoo AnswersZhanget al\.\([2015](https://arxiv.org/html/2607.20497#bib.bib43)\)10200100500TopicRotten TomatoesLeone \([2020](https://arxiv.org/html/2607.20497#bib.bib42)\)2200100500Sentiment20NewsgroupsLang \([1995](https://arxiv.org/html/2607.20497#bib.bib39)\)20200100500TopicMASSIVEFitzGeraldet al\.\([2023](https://arxiv.org/html/2607.20497#bib.bib38)\)6012060288VA intent
## Appendix BCase Study Details

### B\.1TREC: Query Examples

Table 6:TREC queries: ERGO correct \(5/5 seeds\), GEPA wrong \(5/5 seeds\)\. GEPA predicts “entities” for all\.QueryGold“What is the first personal computer company?”human beings“What army’s motto is Blood and Fire?”human beings“Rotary engine cars were made by what company?”human beings“What group asked ‘Do You Believe in Magic’?”human beings“What party was Winston Churchill a member of?”human beings“What are the major companies that are part of Dow Jones?”human beingsTable 7:Per\-class accuracy on TREC: ERGO’s gains concentrate on the target class \(human beings\)\.ClassICL\-DivERGOΔ\\Deltahuman beings89\.9%95\.4%\+5\.5description89\.2%92\.8%\+\+3\.6entities81\.2%82\.2%\+\+1\.0numeric values99\.8%98\.8%−\-1\.0locations85\.5%82\.2%−\-3\.4abbreviation91\.1%86\.7%−\-4\.4
### B\.2Ethos: Query Examples

Table 8:Ethos: ERGO correct, GEPA wrong \(4–5/5 seeds\)\. Gold = False \(not hate speech\)\. GEPA predicts True for all\.TextSeeds“Holy shit\! Kill them all\!”4/5“Go f\*\*\*ing kill yourself… useless pile of shit scumbag”4/5“Not only the politicians are going into the wood chippers but also the police”4/5“Every time that blonde lady talks I lose twenty brain cells”3/5“I very much appreciate the Asian woman’s smarts”3/5
### B\.3CLINC150: Query Examples

Table 9:CLINC150: ERGO correct, GEPA wrong \(4/5 seeds\)\.QueryGoldGEPA pred“set up a reminder so I don’t forget the baby shower”reminder\_updatereminder“i need to get a new credit card application”new\_cardapplication\_status“how long will I have to wait at cheesecake factory”how\_busyrestaurant\_reviews“what is the best way to remove this appointment”calendar\_updatecancel\_reservationERGO learns that intent labels distinguish between*performing an action*and*querying status*:

- •“set up a reminder so I don’t forget the baby shower”→\\rightarrowreminder\_update\(creating\), notreminder\(querying\)
- •“how did my bank account get frozen”→\\rightarrowaccount\_blocked\(status\), notfreeze\_account\(action\)
- •“what is the best way to remove this appointment”→\\rightarrowcalendar\_update\(modifying\), notcancel\_reservation

GEPA’s generic prompt cannot teach this structural distinction\. ICL’s 20 demos \(covering only 13% of 150 labels\) are unlikely to include both members of these confusable pairs\.

### B\.4Where GEPA Wins: 20Newsgroups

GEPA outperforms ERGO by 1\.9% on 20Newsgroups because its evolutionary search produces holistic guidelines:*“Look for context beyond surface\-level keywords\. A discussion about ‘scientific facts’ may actually be part of a religious debate\.”*ERGO’s keyword\-based rules \(learned from 20\-item batches\) cannot capture this holistic understanding of 20 overlapping categories\.

### B\.5Rotten Tomatoes: Conditional Recommendations

ERGO learns that hedged or conditional positive language does not override strong negative criticism:

- •“the four feathers is definitely horse feathers, but if you go in knowing that, you might have fun” \(Gold: Negative, initial: Positive\)
- •“moderately involving despite bargain\-basement photography and hackneyed romance” \(Gold: Negative, initial: Positive\)

ERGO’s rule:*“Weak conditional positives \(‘you might have fun if…’\) do not override strong negative qualifiers \(‘bargain\-basement,’ ‘hackneyed’\)\. Classify based on the dominant critical assessment\.”*

## Appendix CCross\-Model Transfer and Generalization

Table 10:Homogeneous training: per\-model per\-dataset baseline \(B\) and ERGO \(I\) accuracy \(%, mean over 5 seeds\)\. 8 datasets, 5 models\.Haiku 4\.5Sonnet 4\.5Gemma 3 27BMistral L3DatasetBIBIBIBIBITREC51\.484\.771\.990\.052\.481\.841\.541\.458\.660\.0CLINC15090\.292\.892\.794\.287\.590\.185\.685\.488\.488\.7RTE91\.793\.593\.193\.689\.091\.086\.686\.688\.889\.7Ethos48\.986\.263\.487\.740\.085\.342\.350\.454\.883\.4Yahoo71\.666\.272\.871\.269\.369\.170\.870\.873\.371\.4Rotten Tom\.91\.689\.991\.493\.090\.290\.790\.291\.989\.490\.420News63\.062\.667\.667\.065\.466\.457\.557\.663\.763\.0MASSIVE84\.283\.189\.487\.785\.085\.580\.179\.986\.785\.2Average74\.182\.480\.385\.672\.482\.569\.370\.575\.579\.0Table 11:Heterogeneous training: prompts refined on Sonnet 4\.5, used by Haiku 4\.5 at test time \(per\-dataset accuracy, %, mean over 5 seeds\)\. Hetero vs\. baseline:\+8\.83\+8\.83pp,p=0\.001p\{=\}0\.001; hetero vs\. homo:\+0\.55\+0\.55pp,p=0\.22p\{=\}0\.22\(n\.s\.\)\.DatasetBaseHeteroHomoΔ\\Deltavs BaseTREC51\.486\.284\.7\+34\.7\+34\.7CLINC15090\.292\.692\.8\+2\.4\+2\.4RTE91\.792\.293\.5\+0\.5\+0\.5Ethos48\.985\.686\.2\+36\.7\+36\.7Yahoo71\.669\.666\.2−2\.0\-2\.0Rotten Tom\.91\.690\.389\.9−1\.3\-1\.320News63\.062\.462\.6−0\.6\-0\.6MASSIVE84\.384\.483\.1\+0\.1\+0\.1Average74\.182\.982\.4\+8\.8\+8\.8
## Appendix DStability Analysis

Table 12:Cross\-seed standard deviation \(%\) by method on 8 datasets\.Bold= lowest \(most stable\)\.DatasetERGODSPyGEPAICL\-DivEthos0\.130\.481\.251\.55TREC0\.481\.512\.051\.81RTE0\.351\.071\.270\.97Rotten Tom\.0\.370\.720\.300\.30CLINC1501\.030\.540\.600\.73Yahoo1\.860\.182\.000\.3620Newsgroups1\.421\.640\.971\.17MASSIVE0\.550\.380\.400\.83Average0\.770\.821\.100\.97ERGO has the lowest average cross\-seed variance \(0\.77%\) followed by DSPy \(0\.82%\), ICL\-Diversity \(0\.97%\), and GEPA \(1\.10%\)\. ERGO is notably stable on boundary tasks \(Ethos: 0\.13%, TREC: 0\.48%\) because learned rules apply deterministically regardless of seed\.

## Appendix EAblation Studies

Table 13:Ablation results on Sonnet 4\.5 \(8 datasets, 3 seeds,N=24N\{=\}24per variant\)\. Defaults marked†\\dagger\. “Calls” is mean LLM calls per run\. Significance: pairedtt\-test vs default;p∗<0\.05\{\}^\{\*\}\\,p\{<\}0\.05,p∗∗<0\.01\{\}^\{\*\*\}\\,p\{<\}0\.01\.DimensionVariantAccCallsIterations \(T\)T=185\.17657T=385\.20850T=585\.351056T=10†85\.541444T=1585\.431458Batch size \(kk\)kk=584\.851116kk=1085\.351301kk=20†85\.381444kk=3085\.771205kk=50∗∗86\.131017Contrast sampleshuffle†85\.711456balanced85\.181723Componentfull†85\.571457instruction85\.181469demos86\.241445rules85\.421430
## Appendix FComputational Cost

Table 14:Computational cost per method \(averaged over 8 datasets, 5 seeds\)\.MethodOpt CallsTime \(min\)AccuracyICL\-Diversity04\.885\.6%APE57610\.882\.2%ERGO1,05416\.485\.6%DSPy65928\.885\.7%GEPA80730\.985\.4%ERGO uses more LLM calls than DSPy and GEPA but runs faster because its calls are predominantly short classifications \(input→\\rightarrowlabel,∼\{\\sim\}0\.8s each\), while DSPy and GEPA include long\-generation calls for bootstrapping, instruction proposals, and reflections \(∼\{\\sim\}1\.5s each\)\. ERGO also parallelizes batch classification, whereas DSPy and GEPA have sequential coordination overhead from Bayesian optimization trials and population management\.

## Appendix GAlgorithm

Algorithm 1Error\-Guided Optimization \(ERGO\)0:Seed prompt

π0\\pi\_\{0\}, train set

𝒟train\\mathcal\{D\}\_\{\\text\{train\}\}, val set

𝒟val\\mathcal\{D\}\_\{\\text\{val\}\}, batch size

k=20k\{=\}20, LLM

fθf\_\{\\theta\}
0:Optimized prompt

π∗\\pi^\{\*\}
1:Initialize

π0\\pi\_\{0\}with seed prompt \(instruction \+ output format\)

2:

𝒟shuffled←RandomShuffle​\(𝒟train\)\\mathcal\{D\}\_\{\\text\{shuffled\}\}\\leftarrow\\text\{RandomShuffle\}\(\\mathcal\{D\}\_\{\\text\{train\}\}\)\{shuffle once at start\}

3:

T←⌈\|𝒟train\|/k⌉T\\leftarrow\\lceil\|\\mathcal\{D\}\_\{\\text\{train\}\}\|/k\\rceil\{number of batches\}

4:

π∗←π0\\pi^\{\*\}\\leftarrow\\pi\_\{0\};

A∗←Accuracy​\(fθ,π0,𝒟val\)A^\{\*\}\\leftarrow\\text\{Accuracy\}\(f\_\{\\theta\},\\pi\_\{0\},\\mathcal\{D\}\_\{\\text\{val\}\}\)
5:for

t=1t=1to

TTdo

6:

ℬt←𝒟shuffled\[\(t−1\)k:tk\]\\mathcal\{B\}\_\{t\}\\leftarrow\\mathcal\{D\}\_\{\\text\{shuffled\}\}\[\(t\{\-\}1\)k:tk\]\{non\-overlapping batch\}

7:

𝒴^t←fθ​\(πt−1,ℬt\)\\hat\{\\mathcal\{Y\}\}\_\{t\}\\leftarrow f\_\{\\theta\}\(\\pi\_\{t\-1\},\\mathcal\{B\}\_\{t\}\)\{classify batch\}

8:

ℰt←\{\(x,y^,y\):x∈ℬt,y^≠y\}\\mathcal\{E\}\_\{t\}\\leftarrow\\\{\(x,\\hat\{y\},y\):x\\in\\mathcal\{B\}\_\{t\},\\;\\hat\{y\}\\neq y\\\};

𝒞t←\{\(x,y\):x∈ℬt,y^=y\}\\mathcal\{C\}\_\{t\}\\leftarrow\\\{\(x,y\):x\\in\\mathcal\{B\}\_\{t\},\\;\\hat\{y\}=y\\\}
9:if

ℰt=∅\\mathcal\{E\}\_\{t\}=\\emptysetthen

10:

πt←πt−1\\pi\_\{t\}\\leftarrow\\pi\_\{t\-1\}\{no errors, skip refinement\}

11:else

12:

πt←fθ​\(MetaPrompt​\(πt−1,ℰt,𝒞t\)\)\\pi\_\{t\}\\leftarrow f\_\{\\theta\}\(\\text\{MetaPrompt\}\(\\pi\_\{t\-1\},\\mathcal\{E\}\_\{t\},\\mathcal\{C\}\_\{t\}\)\)\{diagnose

→\\rightarrowprescribe

→\\rightarrowrewrite\}

13:endif

14:

A​\(πt\)←Accuracy​\(fθ,πt,𝒟val\)A\(\\pi\_\{t\}\)\\leftarrow\\text\{Accuracy\}\(f\_\{\\theta\},\\pi\_\{t\},\\mathcal\{D\}\_\{\\text\{val\}\}\)
15:if

A​\(πt\)≥A∗A\(\\pi\_\{t\}\)\\geq A^\{\*\}then

16:

π∗←πt\\pi^\{\*\}\\leftarrow\\pi\_\{t\};

A∗←A​\(πt\)A^\{\*\}\\leftarrow A\(\\pi\_\{t\}\)
17:endif

18:endfor

19:return

π∗\\pi^\{\*\}

## Appendix HMeta\-Prompt

The following is an example of the meta\-prompt template used at each iteration:

```
You are a prompt engineer that rephrase and
improve the original multiclass classifier
system prompt using the input samples.

<original_multiclass_classifier_system_prompt>
{current_prompt}
</original_multiclass_classifier_system_prompt>

The classifier made these predictions on the
batch:

<correct_predictions>
{correct_predictions}
</correct_predictions>

<wrong_predictions>
{wrong_predictions}
</wrong_predictions>

Please output a critic feedback of the original
system prompt, actionable improvements and the
improved multiclass classifier system prompt
according to your instructions:
<feedback>feedback</feedback>
<improvement>improvement</improvement>
<improved_multiclass_classifier_system_prompt>
improved_multiclass_classifier_system_prompt
</improved_multiclass_classifier_system_prompt>

<reminder>
REMINDER: DO NOT CHANGE THE OUTPUT FORMAT and
LABELS. DO NOT ADD EXTRA OUTPUTS.
</reminder>
```

Each correct prediction is formatted asInput: \{text\}\\nLabel: \{label\}\. Each wrong prediction is formatted asInput: \{text\}\\nPredicted: \{pred\}\\nCorrect: \{label\}\. Multiple predictions are separated by a triple\-dash delimiter\. The LLM’s response is parsed to extract the improved prompt from the XML tags\.

Similar Articles

Making Optimization Work When Labels Are Scarce [R]

Reddit r/MachineLearning

Gnosys Labs introduces an autonomous model engineering method that improves classifiers under label scarcity, outperforming standard optimizers like GEPA on the ToxicChat benchmark.