Every prompt optimization method you have used shares a hidden flaw. Whether you hand-craft prompts, run DSPy's MIPROv2, or let GEPA evolve them through critique-driven mutation, the result is the same: one prompt string applied to every input. Hard questions get the same instructions as easy ones. Multi-hop reasoning tasks receive the same guidance as simple lookups. The optimizer treats all inputs identically because the optimization target is a single monolithic string.

A new paper from IIT Delhi proposes a fundamentally different architecture. Prompt Codebook Optimization (PCO) shreds that monolithic prompt into atomic instruction units, stores them in a discrete codebook, and routes each input to a different composition of those units. The result: different prompts for different inputs, shorter deployed prompts, and better scores on standard benchmarks.

The paper is "Prompt Codebooks: Discrete Compositional Optimization for Language Model Instruction Refinement" by Jyotirmoy Nath, Neeraj Kumar, and Brejesh Lall at IIT Delhi (arXiv:2605.28360, May 2026). It introduces a framework that borrows from generative modeling, applies it to prompt optimization, and produces gains that prior methods cannot match because they structurally cannot express per-instance routing.

The Problem: Instance-Blind Optimization

Standard automatic prompt optimization (APO) treats the prompt as a monolithic string. You define a task, collect a dataset, and the optimizer searches for the single best prompt that maximizes average reward across all inputs.

This creates two pathologies. First, instance blindness: one prompt serves every input, so the optimizer must compromise. A prompt that helps with hard multi-hop questions may add noise on simple ones. Second, global entanglement: every update rewrites the entire prompt. A critique intended to fix one failure mode can disrupt behaviors that were already working. There is no way to update one instruction in isolation because the instruction is not isolated. It is embedded in a single string.

GEPA, the current state of the art, applies critique-driven evolutionary mutation to whole prompts. MIPROv2 jointly optimizes instructions within DSPy pipelines. Both produce impressive results, but both remain monolithic. Every input gets the same prompt.

The PCO Architecture: Four Components

PCO replaces the monolithic prompt with four components that work together.

Codebook. A finite set of K natural-language directives called instincts. Each instinct is a short instruction like "decompose into sub-questions before answering" or "verify each step against the original question." The codebook is a trainable variable. Instincts are initialized, then refined during training.

Encoder. An LLM with a system prompt theta that routes each input x to S discrete indices in the codebook. The encoder reads the input and selects which instincts are relevant. This is semantic routing based on meaning, not nearest-neighbor vector matching.

Generator. An LLM with a system prompt phi that composes the selected instincts, conditioned on the input, into a fluent prompt. The generator does not just concatenate instincts. It weaves them into a coherent natural-language instruction tailored to the specific input.

Critic. A fixed LLM with a verification-oriented system prompt psi that emits structured natural-language feedback. The critic identifies what went wrong in the output, which instruction was responsible, and what should change. This feedback decomposes into per-variable textual gradients.

The key insight: at inference time, different inputs route through different instinct compositions. A hard multi-hop question might activate verification and decomposition instincts. A straightforward lookup might activate only a brevity instinct. The prompt adapts to the input.

How Training Works

PCO trains the encoder, generator, and codebook jointly under what the authors call a language-valued min-max objective. The outer player (theta, phi, and the codebook) maximizes task reward minus a critic-induced penalty. The critic is a frozen adversary that provides dense, structured feedback.

The forward pass has three steps. The encoder selects S indices from the codebook (the discrete bottleneck). The generator composes those instincts into a prompt conditioned on the input. The frozen target LLM executes the prompt.

The critic then examines the output and emits a structured verdict. An attribution operator partitions this verdict across the three trainable components: generator faithfulness (did the generator accurately render the selected instincts?), instinct quality (was each instinct itself helpful or harmful?), and routing quality (did the encoder pick the right instincts for this input?).

This additive decomposition is a core contribution. Each component gets targeted feedback. The codebook entry that caused a failure gets updated. The encoder that chose the wrong instincts gets a routing-specific critique. The generator that misrendered instructions gets a faithfulness penalty. No component receives irrelevant feedback.

To prevent codebook collapse, where all inputs route to the same few instincts, PCO uses epsilon-greedy routing. With probability (1 - epsilon), the encoder selects instincts normally. With probability epsilon, selection follows a success-weighted distribution that encourages exploration of underused instincts. Epsilon decays from 1.0 to 0.15 over training.

The Results

The authors evaluate PCO on six benchmarks across two 8B-parameter models: Qwen3-8B and LLaMA-3.1-8B.

HotpotQA (multi-hop reasoning). PCO surpasses GEPA by +3.34 points on Qwen3-8B. This is the headline number. On a benchmark where every point is hard-won, a 3.34-point gap over the previous state of the art is significant.

Aggregate improvement. Across all six benchmarks (HotpotQA, HoVER, AIME-2025, LiveBench-Math, IFBench, PUPA), PCO improves by +1.11 points in aggregate over GEPA on Qwen3-8B.

Zero-shot gains. PCO improves over zero-shot prompting by up to +30.36 points on LLaMA-3.1-8B. This is the difference between a model that cannot do the task and one that handles it competently.

Prompt length reduction. PCO cuts deployed prompt length by up to 14.1x versus MIPROv2 and 3.0x versus GEPA. This matters because MIPROv2 and GEPA produce long, verbose prompts. PCO achieves better results with shorter prompts because the codebook uses only K=16 instincts. The encoder selects S=4 per input, and the generator composes them concisely.

The optimal configuration is K=16 instincts with S=4 selections per input. This balances semantic diversity (enough instincts to cover different reasoning patterns) with optimization stability (not so many that the encoder cannot learn good routing).

Why Per-Instance Optimization Matters

The instance-blind assumption is so deeply embedded in prompt optimization that most practitioners do not even recognize it as an assumption. Of course one prompt serves all inputs. That is how prompts work.

Except it is not how human instructions work. A teacher does not give the same guidance to every student on every problem. A manager does not give the same brief to every team member on every project. Instructions adapt to the situation. The difficulty, the context, the goal shape the guidance.

PCO formalizes this intuition. Hard inputs get verification-heavy instinct compositions. Easy inputs get lightweight ones. The encoder learns which instincts to activate for which inputs. This is not prompt engineering with more steps. It is a structural change in what optimization can express.

Consider HotpotQA, a multi-hop question-answering benchmark. Some questions require decomposing a complex query into sub-questions, then synthesizing answers. Others need direct fact retrieval with minimal reasoning. A single monolithic prompt must serve both cases. It will be too verbose for simple questions and too thin for complex ones. PCO routes each input to instincts that match its needs.

The codebook also enables reuse across the task distribution. An instinct like "verify each step against the original question" can be activated for any input that needs verification, whether that input is a math problem, a multi-hop reasoning task, or an instruction-following challenge. The encoder learns when to deploy it. This is compositionality, not just optimization.

How PCO Relates to Existing Methods

PCO sits in the landscape of automatic prompt optimization alongside several methods this newsletter has covered.

DSPy and MIPROv2. DSPy structures prompts as compositional programs but each component remains instance-blind. MIPROv2 optimizes these programs jointly, producing long prompts. PCO achieves better results with shorter prompts by routing per-instance rather than applying one prompt universally.

GEPA. The current state of the art applies critique-driven evolutionary mutation to monolithic prompts. GEPA produces strong results but cannot route different inputs to different instructions. PCO surpasses GEPA on HotpotQA (+3.34) and in aggregate (+1.11) while cutting prompt length by 3.0x.

TextGrad. PCO builds on TextGrad's textual gradient framework but adds the attribution operator that decomposes feedback per component. TextGrad updates the entire prompt string. PCO updates the specific instinct, routing policy, or generator behavior that caused the failure.

VQ-VAE and discrete codebooks. The theoretical connection is explicit. VQ-VAE showed that discrete latent codebooks enable component reuse and stable optimization in image generation and audio coding. PCO applies the same principle to prompts. The codebook is a discrete latent vocabulary. Each instinct is a code. The encoder performs routing analogous to quantization, but based on semantic meaning rather than vector proximity.

Ablation Insights

The authors run ablation studies that confirm the importance of each component.

Removing TextGrad-style natural-language feedback and replacing it with scalar rewards drops performance. The dense, structured feedback from the critic provides richer training signal than binary reward.

Replacing the learnable encoder with fixed random routing drops performance. The encoder learns meaningful assignment patterns. Frequently selected instincts handle broad behaviors. Sparsely activated instincts specialize in high-impact reasoning patterns. This emergent specialization is a feature of the architecture, not a design choice.

Removing epsilon-greedy exploration causes codebook collapse. Without it, the encoder concentrates on a few instincts and the codebook loses diversity.

Sensitivity analysis shows K=16 and S=4 are optimal. Smaller codebooks lack semantic coverage. Larger ones increase optimization difficulty without proportional gains.

Limitations

The authors are candid about what PCO does not do.

Compositional abstraction trades flexibility for structure. A 16-instinct codebook cannot express every possible instruction. GEPA+Merge, which can merge multiple prompts, slightly outperforms PCO on some dense multi-hop tasks where prompt length is less of a constraint.

Training overhead is higher than monolithic methods. Each training step requires LLM calls for the encoder, generator, critic, and attribution operator. This is manageable for the 8B-parameter models evaluated, but scales with model size.

The codebook size K and selection width S are hyperparameters. The authors show sensitivity analysis but do not provide an automatic tuning procedure.

What This Means for Practice

PCO is a research framework, not a drop-in library. The authors use LLMs for the encoder, generator, and critic, which means training requires API access or local inference capacity for multiple models simultaneously. The target model remains frozen throughout.

But the conceptual shift is immediately applicable. Three ideas transfer to production prompt engineering today.

Stop writing one prompt per task. If your task has diverse inputs, consider whether different input types need different instructions. You can hand-craft a routing mechanism that selects different prompt templates based on input characteristics. This is a manual version of what PCO automates.

Think in terms of reusable instruction units. Instead of writing long monolithic prompts, break them into atomic directives. Keep a library. Compose them per use case. This is what the codebook formalizes.

Attribute failures to specific instructions. When a prompt fails, do not rewrite the whole thing. Identify which part of the instruction caused the failure. Update that part. Leave the rest alone. This is what the attribution operator automates.

The paper shows that per-instance compositional optimization is not just theoretically elegant. It produces measurable gains: +3.34 over GEPA on HotpotQA, +1.11 in aggregate, 14.1x prompt length reduction over MIPROv2. These numbers come from a structural change in what optimization can express, not from more compute or bigger models.

Prompt optimization has been stuck in the paradigm of finding the one best string. PCO breaks that paradigm. Different inputs deserve different prompts. The codebook makes that tractable.


Paper: Jyotirmoy Nath, Neeraj Kumar, Brejesh Lall. "Prompt Codebooks: Discrete Compositional Optimization for Language Model Instruction Refinement." arXiv:2605.28360, May 2026.

Key numbers: +30.36 over zero-shot (LLaMA-3.1-8B), +3.34 over GEPA on HotpotQA (Qwen3-8B), +1.11 aggregate improvement over GEPA, 14.1x prompt length reduction vs MIPROv2, 3.0x vs GEPA, using K=16 instincts with S=4 selections.