TextReg: Mitigating Prompt Distributional Overfitting via Regularized Text-Space Optimization

Lucheng Fu, Ye Yu, Yiyang Wang, Yiqiao Jin, Haibo Jin, B. Aditya Prakash, Haohan WangarXiv 2026

TL;DR

Automated prompt optimization methods often produce bloated prompts that overfit to training data by accumulating narrow, case-specific rules. TextReg introduces a text-space regularization framework that penalizes prompt length and rule narrowness, significantly boosting out-of-distribution (OOD) generalization across complex reasoning tasks.

What Problem Does This Paper Address?

When large language models (LLMs) optimize prompts iteratively based on feedback, they tend to act like overzealous software developers writing ad-hoc patches. Instead of discovering compact, general principles, the optimizer appends specific rules to fix individual training errors (e.g., "if the input mentions tomatoes, count them as vegetables").

The authors define this failure mode as prompt distributional overfitting. It manifests along two coupled dimensions:

  1. Capacity Cost: Prompts grow excessively long, consuming the model's context budget and making it harder to locate relevant instructions.
  2. Scope Narrowness: The rules become highly specific to the training sample distribution, failing catastrophically when evaluated on out-of-distribution (OOD) data.

To solve this, the paper introduces the concept of Representational Inefficiency—a metric that multiplies capacity cost by scope narrowness—and proposes a method to constrain it during discrete text-space optimization.

Figure 1: Problem Illustration. We illustrate prompt distributional overfitting in prompt optimization: I) conven- tional methods often produce long prompts saturated with narrow rules (left), which degrade on OOD inputs. II) Our goal is to instead yield compact prompts composed of broadly applicable rules (right), achieving stronger OOD generalization.

Methods

The authors propose TextReg, a regularization framework that mimics soft-penalty objectives used in classical machine learning (like weight decay or LASSO) but operates entirely within discrete text space. It breaks down prompt updates into three distinct stages:

  1. Dual-Evidence Gradient Purification: Before a raw feedback gradient is applied, it is filtered using two sources of evidence. Local case evidence checks if the rule is too specific to the current mini-batch. Global recurrence evidence checks a "RuleBank" (a cross-step memory of accepted rules) to see if this principle has repeatedly appeared. If a rule is purely stylistic or too narrow, it is discarded.
  2. Semantic Edit Regularization (SER): This stage acts as a textual regularization gradient generator ($g_{reg}$). It uses an LLM as a "semantic diff analyzer" to compare the current prompt with the previous version. If the edit caused an unnecessary increase in length or a narrowing of rule scope, it synthesizes a natural-language directive to compress or generalize the prompt.
  3. Regularization-Guided Prompt Update: The optimizer generates a set of task-faithful candidate prompts. TextReg then selects the candidate that is most compatible with the regularization gradient ($g_{reg}$), biasing the prompt evolution toward compact and broadly applicable instructions.
Figure 2: Overview of TextReg, which proceeds in three stages. (a) Left: Dual-Evidence Gradient Purifica- tion filters the raw task gradient via local batch and RuleBank recurrence evidence, yielding ˜gtask. (b) Middle: Semantic Edit Regularization diagnoses capacity and scope degradation and synthesizes the regularization gradient greg. (c) Right: Regularization-Guided Prompt Update rewrites pt into pt+1 by selecting the task- faithful candidate most compatible with greg.

Datasets

The framework was evaluated on nine reasoning datasets spanning symbolic and arithmetic domains:

  • Big-Bench Hard (BBH): Logical Deduction and Tracking Shuffled Objects. Prompts were optimized on simpler 3-object variants and evaluated OOD on harder 5-object and 7-object variants.
  • Arithmetic Benchmarks: Optimized on GSM8K (grade-school math) and evaluated for cross-dataset generalization on SVAMP and MultiArith.

Key Insights and Ideas

  • Overfitting is Structural: Prompt overfitting isn't just an optimization quirk; it's a structural failure where prompt length and rule narrowness amplify each other.
  • Textual Differentiation: You don't need continuous, differentiable parameters to regularize. By treating prompt changes as finite differences and using an LLM to analyze the "semantic delta," you can effectively calculate a regularization gradient in pure text.
  • Lightweight Models Can Regularize: A resilience study revealed that even when the regularization and optimization roles were downgraded from GPT-4o to a much weaker model (Qwen2.5-7B-Instruct), TextReg retained strong performance. This indicates that the regularization signal is structural and robust, rather than entirely dependent on high-tier LLM capabilities.

Key Results

TextReg consistently outperformed standard prompt optimization methods like TextGrad and REVOLVE across multiple downstream test engines (Qwen2, Llama-3, Llama-3.1, and Phi-3.5):

  • Substantial OOD Gains: TextReg achieved accuracy gains of up to +11.8% over TextGrad and +16.5% over REVOLVE on the hardest tracking and logic tasks.
  • Preventing Performance Degradation: On certain models like Phi-3.5, unregularized baselines actually degraded performance below a simple zero-shot Chain-of-Thought (CoT) baseline due to severe overfitting. TextReg successfully preserved and extended the generalization benefits of CoT.
Table 1: Cross-dataset and cross-model generalization results. We report out-of-distribution test accuracy (%) and the relative improvement over TextGrad. The best and second-best results are highlighted with bold and underline, respectively.

Limitations and Future Work

Currently, TextReg is optimized for single-turn reasoning tasks that rely on well-defined behavioral rules. The authors note that extending this framework to open-ended generation, multi-turn conversational prompts, and autonomous agent instructions remains an open challenge, as rule structures blur and capacity costs are shared dynamically across multiple turns.

Summary updated

BibTeX
@misc{fu2026textreg,
  author = {Lucheng Fu and Ye Yu and Yiyang Wang and Yiqiao Jin and Haibo Jin and B. Aditya Prakash and Haohan Wang},
  title = {{TextReg: Mitigating Prompt Distributional Overfitting via Regularized Text-Space Optimization}},
  year = {2026},
  eprint = {2605.21318},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2605.21318},
}
Figure