How an ACL 2026 paper replaces manual prompt engineering with automated, self-discovering prompt decomposition — and cuts optimization cost by up to 87%.


The Prompt Engineering Trap

Here's a scenario every LLM developer knows: you write a prompt. It doesn't work. You tweak a word. It works slightly better. You add a sentence. It gets worse. You remove that sentence and change the framing. It gets different-worse. Three hours later you have a prompt that works on your test set, but you have no idea why, and you're terrified to touch it.

This isn't a skill issue. It's a structural problem.

Most prompt optimization methods — including the automated ones — treat the prompt as a single, monolithic block of text. When something goes wrong, the optimizer rewrites the whole thing or makes a change somewhere and hopes for the best. There's no way to tell whether the failure came from the reasoning strategy, the output format, the role description, or some subtle constraint buried in paragraph three.

It's debugging a program by rewriting the entire source file from scratch each time. At some point, you stop calling it "engineering."

Adaptive Prompt Structure Factorization (aPSF), an ACL 2026 main conference paper by Haoyue Liu, Zhichao Wang, Yongxin Guo, Haoran Shou, and Xiaoying Tang from the Chinese University of Hong Kong, Shenzhen (T-Lab), proposes a fundamentally different approach: decompose the prompt into compositional sub-programs, then optimize each factor independently based on where the model is actually failing.

The result? Up to +2.16 percentage points improvement over strong baselines, and a 45–87% reduction in optimization tokens on certain benchmarks. Let's dig into how it works, why it matters, and what it means for anyone building with LLMs.


The Core Problem: Monolithic Prompts Obscure Credit Assignment

To understand aPSF, you first have to understand the pathology it's treating.

A typical prompt for a reasoning task might contain:

  1. Task framing — "You are an expert mathematician solving step-by-step..."
  2. Reasoning style — "Think through the problem carefully before answering."
  3. Answer format — "Put your final answer in \boxed{}."
  4. Constraint specification — "Do not use external tools. Show all work."
  5. Perspective — "Consider alternative approaches if your first attempt fails."

These aren't just decorations. Each component independently affects model behavior. But when you treat the prompt as one undifferentiated string, two pathologies emerge:

Credit assignment is impossible. When the model gets a wrong answer, which of those five components caused the failure? Was the task framing misleading? Was the reasoning instruction too vague? Did the format constraint confuse the model? You can't tell from the output alone because all factors are coupled.

Optimization is inefficient. Without credit assignment, you're left with blind perturbation — randomly modifying parts of the prompt and checking if accuracy goes up. This wastes tokens, is unstable across runs, and produces prompts that are hard to interpret or transfer to new tasks.

Existing automated prompt optimization methods (like DSPy's optimizers or OPRO-style approaches) partially address this but still operate at the prompt level. They might propose new prompt variants, but they don't decompose the prompt's internal structure or track which semantic component is responsible for improvements or failures.

aPSF argues that the right abstraction isn't "prompt" — it's prompt program, a composition of independently meaningful factors.


How aPSF Works: Factorize, Diagnose, Intervene

The aPSF framework operates in a loop with four stages. Think of it as prompt optimization with a diagnostic step that previous methods skip entirely.

Stage 1: Structure Discovery

The Architect model (a separate LLM) examines the task description and examples to discover what structural factors a good prompt for this task should contain. This isn't hardcoded — the Architect invents factors specific to the task.

For a math task, it might discover factors like: task framing, reasoning style, answer format, verification strategy, and constraint specification. For a logic puzzle, the factors might look different: role setup, decomposition strategy, truth-table guidance, answer format, and consistency check.

This is key: aPSF doesn't impose a fixed template. It self-discovers the factorization that makes sense for the task. The prompt structure emerges from the task itself, not from human intuition about what "should" matter.

Stage 2: Error-Guided Factor Selection

Once the prompt is factorized, the Worker model executes the current prompt program on validation examples. When errors occur, aPSF doesn't blindly pick a factor to modify — it uses error-guided selection to identify which factor is most likely responsible for the current failures.

This is the diagnostic step. If the model is getting the right reasoning path but outputting answers in the wrong format, the optimizer should target the answer format factor, not the reasoning style factor. aPSF routes optimization effort to the highest-impact intervention point.

Stage 3: Interventional, Single-Factor Updates

aPSF then performs a targeted intervention on exactly one factor — rewriting or refining just that component while keeping the rest of the prompt program stable.

This is where the "factorization" in the name really pays off. By changing only one factor at a time, you get:

  • Clean credit assignment: If accuracy improves, you know which change caused it.
  • Controllability: You're not accidentally destroying a working component while trying to fix a broken one.
  • Interpretability: You can read the optimization trace and understand what changed and why.

The paper uses an interventional factor-level scoring mechanism — inspired by causal inference thinking — to estimate each factor's marginal contribution to performance. This is analogous to an A/B test where you change one variable at a time, not the whole experiment at once.

Stage 4: Evaluation and Acceptance

After generating candidate updates, aPSF evaluates them through a unified scoring pipeline. If the intervention improves validation performance, it's accepted. If not, the prompt program stays unchanged. This creates an adaptive optimization loop that progressively discovers and refines compositional prompt programs.

The whole process repeats: execute, diagnose errors, select the most impactful factor, intervene, evaluate, accept or reject. Over multiple steps, the prompt program converges toward a locally optimal decomposition.


The Dual-Model Architecture

aPSF uses two distinct LLM roles:

Role Purpose Example Models
Architect Discovers prompt structure, performs factor-level optimization Qwen3-8B, gpt-oss-120b
Worker Executes the current prompt program, generates task answers Llama-3.1-8B, Qwen2.5-7B

The separation is deliberate. The Architect is the optimizer — it analyzes failures and proposes targeted fixes. The Worker is the executor — it runs under the current prompt program and produces answers. This mirrors the separation between a compiler (which transforms code) and a CPU (which runs it), except here both components are language models.

Crucially, aPSF is an API-only framework. It doesn't need access to model internals (gradients, activations, logits). The entire optimization loop works through prompt-in/text-out — meaning it's compatible with any LLM accessible via an OpenAI-compatible API, including locally-deployed models through Ollama or vLLM.

This is a practical design decision. You can use aPSF with proprietary models (GPT-4, Claude) where you can't see inside the box, or with open models where you can. The framework doesn't care.


Results: Better Accuracy, Dramatically Lower Cost

The paper evaluates aPSF across four categories of reasoning benchmarks:

  • Math: GSM8K, MultiArith, GSM-Hard, AIME 2025, Competition Math
  • Logic: AQuA, BIG-Bench Hard (27 tasks)
  • Knowledge: MMLU (57 subjects), GPQA
  • Code: HumanEval

Across these benchmarks, aPSF outperforms strong baselines including principle-aware optimizers, with up to +2.16 percentage points average improvement in accuracy.

But the efficiency story is arguably more impressive. On MultiArith, aPSF reduces optimization token cost by 45–87% and reaches peak validation performance in just 1 optimization step. Compare this to methods that need dozens of iterations rewriting entire prompts before finding something that works.

Why the dramatic efficiency gain? Because targeted, single-factor interventions are inherently more sample-efficient than whole-prompt rewrites. When you know which part is broken, you need fewer attempts to fix it.


Why This Matters: From Art to Engineering

Prompt engineering has long been more art than science. The field's standard practices — manually crafting instructions, A/B testing word choices, copying "system prompts" from blog posts — would be unrecognizable in any other engineering discipline.

aPSF points toward a future where prompt development looks more like software engineering:

Decomposition is the default. Prompts aren't monolithic strings — they're programs with components that have distinct roles and can be independently analyzed.

Debugging is targeted. When something fails, you diagnose which component failed, rather than rewriting the whole thing and praying.

Optimization is automated and interpretable. The optimizer can tell you which factor it changed and why, not just "here's a new prompt, it works better on the test set."

Transferability becomes possible. If you've discovered that a particular "reasoning style" factor works well across multiple math benchmarks, you can port that factor to a new task while rediscovering the other factors from scratch. Factorized prompts are more modular and reusable than monolithic ones.


Practical Takeaways

1. Stop Writing One Big Prompt

If you're building LLM applications, start thinking of your prompts as compositions of semantic factors. Explicitly structure your prompts with sections for task framing, reasoning instructions, output format, constraints, and perspective. Even if you're not using aPSF, this decomposition makes your prompts easier to debug and iterate on.

2. Error Diagnosis > Blind Mutation

When your model fails, resist the urge to randomly edit the prompt. Instead, ask: which component of my prompt is most likely responsible for this failure? This is the core insight of aPSF — error-guided, factor-level optimization is vastly more efficient than blind whole-prompt search.

3. The Architect-Worker Pattern Is Widely Applicable

Even outside of prompt optimization, the pattern of using one model to analyze and another to execute is powerful. It's essentially a meta-cognitive loop — one model watches the other and suggests improvements. You can apply this pattern to your own evaluation and improvement pipelines.

4. Try aPSF Yourself

The code is open source at github.com/T-Lab-CUHKSZ/aPSF. Setup is straightforward:

pip install -r requirements.txt
export OPENAI_API_KEY="sk-..."
python main.py  # Sanity check
python run_experiments.py --dataset gsm8k --method apsf

It supports OpenAI, SiliconFlow, Groq, DashScope, and local models via Ollama or vLLM. You can also start from existing prompt styles:

python run_experiments.py --dataset gsm8k --method apsf --initial-prompt cot
python run_experiments.py --dataset gsm8k --method apsf --feedback

The --feedback flag enables reflection-based optimization using error feedback — another optimization axis that can improve results.

5. Watch the Factorization Abstraction

The idea that prompts have discoverable latent structure — and that optimizing at the factor level beats optimizing at the prompt level — is a general principle that extends beyond aPSF's specific implementation. Expect to see this pattern show up in more prompt optimization frameworks, IDE tooling, and LLM application architectures.


The Bigger Picture

aPSF sits at the intersection of two important trends in LLM research:

Prompt programming as a first-class discipline. As LLMs become more capable, the gap between a mediocre prompt and an excellent one grows wider. Frameworks that automate and structure prompt development are becoming essential infrastructure, not nice-to-haves.

Causal thinking in LLM optimization. The interventional factor-level scoring in aPSF draws on ideas from causal inference — estimating the marginal effect of changing one variable while holding others constant. This is a principled alternative to the correlation-heavy approaches that dominate the field.

The paper's API-only constraint is also worth noting. By not requiring access to model internals, aPSF works in the most constrained real-world setting — you only need text-in/text-out access. This makes it immediately applicable to production systems using proprietary models.


Limitations and Open Questions

aPSF isn't without limitations:

  • Factor quality depends on the Architect. If the Architect model discovers bad factors, the entire optimization loop suffers. The framework's ceiling is set by the Architect's ability to understand task structure.
  • Single-factor interventions may miss interactions. Sometimes two factors interact in ways that require joint optimization. aPSF's single-factor constraint could miss these cases.
  • Scoring cost. Evaluating each factor's marginal contribution requires running the Worker model multiple times. On expensive models, this can add up.
  • Early adoption. With 3 GitHub stars at the time of writing, aPSF is very new. Real-world usage patterns, failure modes, and edge cases haven't been stress-tested at scale yet.

These aren't fatal flaws — they're the natural starting points for a promising research direction.


The Bottom Line

Adaptive Prompt Structure Factorization represents a meaningful shift in how we think about prompt optimization. Instead of treating prompts as atomic units to be blindly rewritten, aPSF recognizes that prompts have internal structure — and that structure can be discovered, diagnosed, and improved with surgical precision.

The numbers speak for themselves: better accuracy and dramatically lower optimization cost, all without requiring model internals. The code is open, the approach is principled, and the intuition — decompose, diagnose, intervene — is one that every prompt engineer should internalize, even if they never run the aPSF code.

Paper: Adaptive Prompt Structure Factorization: A Framework for Self-Discovering and Optimizing Compositional Prompt Programs — ACL 2026 Main Conference (ACL Anthology: 2026.acl-long.537)

Code: github.com/T-Lab-CUHKSZ/aPSF

Authors: Haoyue Liu, Zhichao Wang, Yongxin Guo, Haoran Shou, Xiaoying Tang — The Chinese University of Hong Kong, Shenzhen (T-Lab)


Found this useful? Subscribe for weekly deep dives into the papers and tools reshaping how we build with language models.