Research
TextReg: Mitigating Prompt Distributional Overfitting via Regularized Text-Space Optimization
Overview Research area: Natural Language Processing (LLM prompt optimization and out-of-distribution generalization). Technical level: Intermediate — the core idea is intuitive (keep prompts short and

- arXiv
- 2605.21318
- Published
- 2026-05-20
- Authors
- Lucheng Fu, Ye Yu, Yiyang Wang, Yiqiao Jin, Haibo Jin, B. Aditya Prakash, Haohan Wang
AI summary
Overview
Research area: Natural Language Processing (LLM prompt optimization and out-of-distribution generalization).
Technical level: Intermediate — the core idea is intuitive (keep prompts short and general), but the paper formalizes it with notation such as a generalization gap and an inefficiency measure, and assumes familiarity with prompt optimization baselines like TextGrad and REVOLVE.
Scope: The paper diagnoses "prompt distributional overfitting" in feedback-based prompt optimization, formalizes it as a dual-factor measure called representational inefficiency, and proposes a three-stage regularization framework, TextReg, that improves out-of-distribution accuracy across reasoning benchmarks and four open-source test engines.
What This Paper Is About
Methods that iteratively rewrite prompts using LLM-generated feedback often produce prompts that get longer and accumulate narrow, sample-specific rules, so they score better on the data they were optimized on but generalize poorly beyond it. The authors call this failure mode prompt distributional overfitting and argue it is really a failure of representation efficiency, not just an artifact of optimization dynamics. TextReg is their attempt to control that failure during optimization by penalizing prompt growth and rule narrowing without directly measuring a scalar penalty.
Key Contributions
-
Formalizing representational inefficiency. The paper recasts prompt distributional overfitting as a failure of representation efficiency in discrete text-space optimization and introduces representational inefficiency, a dual-factor measure that combines capacity cost (prompt token length) with scope waste (rule narrowing), defined multiplicatively as ℐ(p) = |p|_tok · (1 − s̄(p)).
-
A regularization framework for text space. TextReg realizes a soft-penalty objective — conceptually min over p of ℒ_Dtrain(p) + λℐ(p) — through natural-language update signals rather than numerical gradients, using three stages: Dual-Evidence Gradient Purification, Semantic Edit Regularization, and Regularization-Guided Prompt Update.
-
Improved out-of-distribution generalization. Across multiple reasoning benchmarks and four test engines, TextReg outperforms existing prompt optimization methods on OOD generalization, with reported accuracy gains of up to +11.8% over TextGrad and +16.5% over REVOLVE.
-
Complementary control at two levels. The design controls inefficiency both before rewriting (filtering feedback likely to produce narrow or redundant rules) and after rewriting (detecting capacity or scope degradation that still emerges), rather than applying a uniform compression penalty to every update.
Main Findings
-
TextReg leads on nearly every cell. In the main table, TextReg achieves the best or second-best accuracy on nearly all (test engine, dataset) pairs, outperforming TextGrad and REVOLVE in the large majority of cells. Numbers are out-of-domain test accuracy (%), averaged over four independent optimization seeds.
-
Largest gains appear on harder variants of the source task. On Tracking Shuffled Objects, TextReg improves over TextGrad by +10.0 (5obj) and +9.9 (7obj) on Llama-3.1-8B-Instruct, and by +8.4 (5obj) and +10.3 (7obj) on Llama-3-8B-Instruct.
-
Strong results on weak test engines. On Phi-3.5-Mini-Instruct, TextReg reaches 57.9 on Logical Deduction 5obj (+11.8 over TextGrad), 55.2 on Logical Deduction 7obj (+8.8), 94.1 on Tracking Shuffled Objects 5obj (+10.5), 88.5 on SVAMP (+7.9), and 94.7 on MultiArith (+7.9). One cell is a reported drop: 92.2 on Tracking Shuffled Objects 7obj, −0.6 relative to TextGrad.
-
Baselines can fall below the unoptimized prompt. On Phi-3.5-Mini-Instruct, REVOLVE underperforms CoT on all six datasets, which the authors present as direct evidence of the prompt overfitting problem. Baseline methods also degrade below CoT on Llama-3.1-8B-Instruct for the 7-object variants of both BBH task families.
-
All three components are necessary. The ablation study, which disables each of Gradient Purification, Semantic Edit Regularization, and Regularization-Guided Update in turn, reports that full TextReg achieves the highest accuracy on all four test engines and that removing any component produces a clear and consistent drop. Bars report mean OOD accuracy across four OOD tasks: Tracking Shuffled Objects (5/7 obj) and Logical Deduction (5/7 obj).
-
Resilience to weaker optimization roles. When each of the three LLM-driven roles (Gradient, Regularization, Optimizer) is downgraded one at a time from GPT-4o to Qwen2.5-7B-Instruct, TextReg retains strong performance with only minor accuracy drops. On the hardest variant, Tracking Shuffled Objects (7 obj), Weak Regularization and Weak Optimizer even surpass the All-Strong baseline, which the authors read as evidence that the regularization signal is structural rather than capability-bound.
-
Gains hold across heterogeneous test engines. The robustness is reported across four open-source backends spanning different architectures and instruction-tuning recipes, which the authors argue makes overfitting mitigation a model-agnostic property of the optimization procedure.
Methodology in Plain English
The setup is black-box: a fixed language model takes an input plus a prompt and produces an output, and the paper's goal is to find a good prompt without touching model weights. Prompts are optimized on three source tasks — Logical Deduction (3 objects), Tracking Shuffled Objects (3 objects), and GSM8K — and then evaluated on harder or related datasets the optimizer never saw.
The authors first describe what goes wrong. They define a generalization gap as the difference between loss on a shifted target distribution and loss on the training distribution, and say prompt distributional overfitting occurs when optimization lowers training loss while increasing that gap. They then view a prompt as encoding a set of behavioral directives, each with a "generalization scope" — how relevant it is across the broader input space. A broad rule applies nearly everywhere; a narrow rule (their example: "when the input mentions tomatoes, count them as vegetables, not fruits") applies to few inputs. Representational inefficiency is the product of prompt length and the shortfall from perfect scope, so it is high only when a prompt is both long and dominated by low-scope rules.
TextReg operationalizes this in three stages rather than optimizing the penalty numerically.
Stage 1, Dual-Evidence Gradient Purification, filters raw task feedback before it reaches the prompt. It uses two kinds of evidence: local evidence from the current mini-batch, to flag corrections tied to particular entities, quantities, surface patterns, or rare edge conditions, and global recurrence evidence from a maintained RuleBank that tracks how often candidate directives have matched previously accepted purified gradients. An LLM-based projection classifies each gradient as GENERALIZED_RULE, CASE_PATCH, or STYLE_ONLY; only generalized corrections are retained and rewritten into concise instructions. Recurrence is used only as a soft prior, not a hard threshold, and the true scope s(r) is not numerically estimated.
Stage 2, Semantic Edit Regularization, inspects the actual transition from the previous prompt to the new one. Capacity cost is directly observable, so it computes a relative length change and triggers when it exceeds a threshold τ_C. Scope narrowness is semantic and cannot be measured directly, so an LLM-based semantic diff analyzer only estimates the direction of change, along with a record of which rules were introduced, removed, or modified. The two triggers combine into an active channel set, and an LLM controller converts them into a textual regularization signal that asks for compression, generalization or removal of narrow patches, or both. If neither channel fires, no regularization signal is produced.
Stage 3, Regularization-Guided Prompt Update, rewrites the prompt using both signals, but with an asymmetry: the task signal defines what must change, while the regularization signal only constrains how it is expressed. This is stated as a conceptual preference over the set of task-faithful rewrites rather than an enumerated optimization — TextReg does not construct that set or evaluate incompatibility as a scalar; the optimizer LLM realizes the preference in natural language. This task-dominance fallback keeps regularization from becoming a hard structural constraint, so a genuinely useful instruction is not suppressed just because it adds length or a specialized distinction.
Evaluation uses Qwen2.5-7B-Instruct as the forward engine executing prompts on training samples and GPT-4o as the shared backward engine for all LLM-driven optimization operations, applied uniformly to TextReg and all baselines. Test engines are Qwen2-7B-Instruct, Phi-3.5-Mini-Instruct, Llama-3-8B-Instruct, and Llama-3.1-8B-Instruct. Baselines are zero-shot Chain-of-Thought, TextGrad, and REVOLVE. The metric is exact-match string accuracy on the final answer, with greedy decoding, and each optimized entry is the mean over four runs with independent seeds. For the 3-object source tasks, the paper follows TextGrad and uses a 50/100/100 train/validation/test split. The values of λ and τ_C are not reported.
Why This Matters
Impact on research. The paper reframes prompt overfitting from a vague complaint about prompts "getting bloated" into a measurable two-factor quantity and shows that explicitly controlling it improves out-of-distribution accuracy. It also connects feedback-based prompt optimization to the classical regularization literature, suggesting that complexity control — a mainstay of model training — has a meaningful analogue in discrete text-space optimization.
Real-world applications.
- Deploying LLM assistants whose prompts are tuned on internal data but must keep working when real user inputs drift in phrasing, scale, or difficulty.
- Reducing inference cost, since shorter prompts consume less of a limited context window and are cheaper to serve.
- Building reliable task-specific pipelines in domains like arithmetic word problems, symbolic reasoning, and structured deduction, where the paper's benchmarks live.
- Multi-agent or tool-using systems where the prompt is generated and refined automatically, and where uncontrolled prompt growth is an operational risk.
Industry relevance. Prompt optimization is already used in production to cut manual prompt engineering, and this paper quantifies a failure mode those pipelines are prone to: achieving better training scores while silently degrading on shifted inputs. The resilience study is directly practical, indicating that parts of the optimization loop can be served by lightweight models — Weak Regularization and Weak Optimizer even surpassed All-Strong on the hardest variant — which matters for cost-sensitive deployments. The finding that optimized prompts sometimes score worse than plain CoT is a caution for teams that treat training-feedback gains as evidence of improvement.
Future Directions
- Open-ended generation. The paper states that its evaluation focuses primarily on single-turn reasoning with well-defined behavioral rules, and that Appendix F provides only preliminary results on open-ended generation. Extending the framework where rule structure is less explicit is left open.
- Broader generation tasks and multi-turn prompts. The conclusion names these explicitly as future work, noting that in multi-turn settings rule structure can be less explicit and capacity cost may be shared across turns — a case the current capacity-cost formulation does not directly address.
- Agent instructions. The paper also lists agent instructions as a remaining direction, since those prompts face the same growth and narrowing pressures but with different structural properties.
- Better estimation of scope. Scope narrowness is currently estimated only directionally by an LLM-based analyzer, while capacity cost is measured exactly. Improving how scope is measured — and understanding when the directional estimate is wrong — is an open question raised by the design itself.
Target Audience
Researchers and practitioners working on prompt engineering, automatic prompt optimization, and LLM reliability. It is most useful to those who already know methods like TextGrad, APO, or REVOLVE and want a principled account of why their optimized prompts degrade out of distribution, as well as to engineers running iterative prompt-tuning pipelines in production who need prompts that hold up on shifted inputs rather than only on training feedback. Readers unfamiliar with LLM-based optimization loops will need some background, but the central intuition — compact, broadly applicable prompts beat long, case-specific ones — is accessible without it.
Authors’ abstract
Large language models (LLMs) are highly sensitive to the prompts used to specify task objectives and behavioral constraints. Many recent prompt optimization methods iteratively rewrite prompts using LLM-generated feedback, but the resulting prompts often become longer, accumulate narrow sample-specific rules, and generalize poorly beyond the training distribution. We study this failure mode as prompt distributional overfitting and argue that it reflects a lack of representation control in discrete text-space optimization. We formalize this view through representational inefficiency, a dual-factor measure that decomposes prompt inefficiency into capacity cost and scope narrowness, attributing distributional prompt overfitting to their coupled growth during optimization. We propose TextReg, a regularization framework that realizes a soft-penalty objective through regularized textual gradients, combining Dual-Evidence Gradient Purification, Semantic Edit Regularization, and Regularization-Guided Prompt Update. Across multiple reasoning benchmarks, TextReg substantially improves out-of-distribution (OOD) generalization, with accuracy gains of up to +11.8% over TextGrad and +16.5% over REVOLVE.