From Monolithic to Modular: Segment-level Automatic Prompt Optimization

Nikita Kulin, Viktor Zhuravlev, Artur Khairullin, Sergey Muravyov, Ilya Makarov, Daniil Sukhorukov, Ekaterina AverkovaarXiv 2026

TL;DR

SAPO (Segment-level Automatic Prompt Optimization) moves away from "monolithic" prompt rewriting by decomposing instructions into functional segments like Role, Context, and Tasks. By identifying and preserving high-performing segments while only revising weak ones based on contrastive evidence, SAPO achieves significant performance gains—up to +7.25% on average—while reducing the instability and "prompt drifting" common in traditional optimization methods.

What Problem Does This Paper Address?

In the era of Large Language Models (LLMs), prompt engineering has largely replaced traditional fine-tuning. However, manual prompt iteration is costly, and existing Automatic Prompt Optimization (APO) tools often treat prompts as "monolithic" strings.

When an optimizer rewrites a prompt globally, it often suffers from prompt drifting: an edit that fixes a failure in one specific case might inadvertently degrade performance on a dozen other cases that were previously handled correctly. The authors identify a core challenge: we don't just need more prompt variants; we need better control over where and how those edits are applied.

Methods

The authors introduce SAPO, a modular framework that treats a prompt as a compositional artifact. The process follows a structured loop:

  1. Segmentation: An initial prompt is decomposed into four distinct segments: Role (behavioral stance), Context (grounding and input placement), Tasks (specific requirements), and Output Format (constraints on the response schema).
  2. Stage A (Analyze & Diagnose): The system evaluates the current prompt on a training set and extracts "contrastive evidence"—the top-5 best-performing and bottom-5 worst-performing examples. A meta-prompting LLM then diagnoses which segments are "strong" (associated with success) and which are "weak" (associated with failure).
  3. Stage B (Candidate Generation): The optimizer generates $K$ new candidates. Crucially, this process is constrained: the LLM is instructed to preserve strong segments exactly as they are and focus its creative rewriting only on the weak segments.
  4. Conservative Selection: Candidates are evaluated on a validation set. If scores are tied, SAPO uses an edit-distance tie-break, choosing the candidate most similar to the original to prevent unnecessary "churn" in the prompt's logic.
Figure 1: SAPO loop. Starting from the initial prompt P (0), the method first segments instructions into role/context/tasks/output for- mat, then performs contrastive evidence extraction on train data to diagnose weak and strong segments. Next, it generates constrained candidates that preserve strong segments while revising weak ones, evaluates them on validation data, applies edit-distance tie-break under equal scores, and accepts an update only when validation per- formance improves; otherwise the current prompt is retained.

Datasets

The researchers evaluated SAPO across five diverse NLP tasks to test different prompt components:

  • SQuADv2: Extractive Question Answering.
  • TweetEval: Social media sentiment classification.
  • XSUM: Abstractive summarization.
  • CommonGen (CG): Constrained commonsense generation.
  • GSM8K: Multi-step mathematical reasoning.

The experiments were conducted using two model backbones: GPT-3.5-Turbo and GPT-4o-mini.

Key Insights and Ideas

  • Modularity Reduces Interference: By localizing edits, SAPO prevents the "one step forward, two steps back" problem. If the "Role" is working well but the "Output Format" is causing errors, only the format is touched.
  • Tasks are the Primary Lever: Ablation studies (Table 3 in the paper) revealed that the "Tasks" segment is the most critical driver of performance. Reverting the optimized tasks back to their initial wording caused the largest drops in accuracy, particularly in reasoning tasks like GSM8K.
  • Contrastive Evidence is Essential: By looking at both what the model got right and what it got wrong, the optimizer can pinpoint specific instruction ambiguities that lead to failure modes.
  • Conservative Updates Matter: The use of edit-distance as a tie-breaker ensures that the prompt only changes as much as necessary to improve performance, maintaining the stability of the instruction set over multiple iterations.
Figure 2: Example of SAPO optimization on GSM8K samples. The figure traces how the LLM diagnoses and updates weak prompt segments across iterations. At each step, performance is analyzed at the segment level; missing segments are treated as weak by default. Segments identified as strong are preserved and not modified during candidate generation. The best result was obtained at iteration 3 (candidate 1), where segment-level expansion and reformulation yielded near-complete coverage of correct answers on the sample.

Key Results

SAPO consistently outperformed strong baselines like APE, OPRO, and StraGO across both model backbones:

  • GPT-3.5-Turbo: SAPO achieved a +5.13% relative improvement in average score over the strongest baseline. The most dramatic gain was on GSM8K, where it outperformed the next best method by +9.1 points (absolute).
  • GPT-4o-mini: The gains were even more pronounced, with a +7.25% relative improvement. It achieved the highest scores on every single dataset in this configuration.
  • Qualitative Improvements: Optimized prompts often evolved from simple one-liners to structured instructions that included specific reasoning steps and strict negative constraints (e.g., "Do NOT output JSON").
Figure 4: TweetEval Sentiment prompt pair (GPT-4o-mini): initial prompt (top) and optimized segmented prompt (bottom).

Limitations and Future Work

The authors acknowledge a few key limitations:

  • Fixed Taxonomy: SAPO currently relies on a predefined set of four segments. While effective, this might not capture the nuances of highly complex, multi-stage prompts.
  • Evidence Window: The use of a fixed top-5/bottom-5 window might miss subtle error modes that only appear in a larger sample of data.
  • Future Directions: The team suggests moving toward adaptive segmentation, where the LLM itself determines the best way to decompose a prompt during the optimization process, rather than relying on a static template.

Summary updated

BibTeX
@misc{kulin2026from,
  author = {Nikita Kulin and Viktor Zhuravlev and Artur Khairullin and Sergey Muravyov and Ilya Makarov and Daniil Sukhorukov and Ekaterina Averkova},
  title = {{From Monolithic to Modular: Segment-level Automatic Prompt Optimization}},
  year = {2026},
  eprint = {2608.11219},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2608.11219},
}
Figure