Skip to content
Prompting & Context EngineeringInstruction placement and recency

Senior · 8 chapters

Instruction placement and recency

Critical constraints last; prefilling the assistant turn

Instruction order is a production control, not a style preference: misplaced constraints and careless prefilling can silently corrupt structured outputs while cache-friendly layouts pull in the opposite direction.

Read these first

What you will know

  • Put the constraint that must not be violated in the position it survives

    Late placement helps against lost-in-the-middle behavior, but it does not override higher-priority instructions or resolve contradictions.

  • Demonstrate recency effects on a long prompt

    Use identical inputs, decoding settings, and evaluation cases so a compliance change can be attributed to position rather than randomness.

  • Prefill the assistant turn to force a format

    A partial assistant response can anchor syntax, though malformed prefixes may truncate valid answers or conflict with provider-specific generation behavior.

  • Defend an instruction-ordering decision in a prompt review using measured compliance and token-cache constraints

    The review should expose whether the chosen layout favors reliability, stable prefixes, or lower latency, and identify the accepted compromise.

  • Benchmark two prompt layouts with and without a stable cached prefix, then record the quality, cache-hit, and latency trade-off

    Moving dynamic instructions forward can invalidate cached tokens, increasing spend and time even when answer quality improves.


Chapters

  1. 1

    Instruction distance and recency

    Five instructions at the top of a prompt, then 38,000 tokens of retrieved documents, then the question: two of the five are reliably ignored while three are followed. Covers the recency and lost-in-the-middle behaviour behind that split, why conditional and negative rules are the ones that fail, and the standard remedy — restating the critical rules directly after the documents and before the question while keeping the full set at the top for review.

  2. 2

    Designing a position experiment

    An eighteen-point compliance jump from moving a single line is a claim about causation, and it needs an experiment shaped to support it: two prompts differing only in where that rule sits, run over the same cases with identical decoding, repeated often enough that you know each condition's spread. Covers the three arms that separate position from repetition, what a failure to replicate looks like, and why one pair of runs cannot separate position from chance.

  3. 3

    Conflicting rules and implicit precedence

    Move 'never exceed 200 words' to the final line and compliance goes from 60% to 88%, while an earlier section still demands a disclaimer that runs to 180 words by itself. The remaining 12% are cases where both rules cannot hold, so you have traded length violations for dropped disclaimers rather than fixing anything. Covers telling a placement win apart from an unresolved conflict, and the arithmetic check that finds the conflict in ninety seconds.

  4. 4

    Ranking constraints by violation cost

    The previous chapter ends with two rules that cannot both hold, and position only picks a winner between them. Covers what to do when placement runs out: de-conflict and consolidate so a prompt with four critical rules does not become four competing final lines, rank the survivors by the cost of a violation, and move the ones that must not be violated out of the prompt entirely into a deterministic output check that fails closed.

  5. 5

    Prompt caching and prefix stability

    A reviewer blocking a late-placement change because 'moving things around breaks prompt caching' has the mechanism backwards: matching runs forward from the first token, so relocating a static line later leaves everything ahead of it byte-identical. What destroys a cache is variable content early. Covers what a hit actually buys — prefill work skipped, which shows up as both a discounted input price and a lower time to first token — and why restating a short critical instruction late stays compatible with a shared static prefix.

  6. 6

    Assistant prefill and forced formats

    Prefilling the assistant turn with an opening brace forces JSON syntax in a way a final-line instruction only requests. The hazards are specific: the prefix commits a shape before the model has weighed the input, it is not echoed back in the response, everything after the brace is ordinary generation, and an answer of 'I cannot answer this from the given input' has been made unreachable. Covers the three ways to force a format and which models still accept each.

  7. 7

    Defending a prompt layout decision

    'Critical constraints go last' has no answer for a prompt with four critical constraints, and none at all for one that is both critical and per-request, which is exactly where compliance and cache stability fight. Covers defending an ordering decision in review with measured per-rule compliance, hit-rate and time-to-first-token numbers, naming which property the layout favours, and writing down the compromise you knowingly accepted.

  8. 8

    Safety constraints and residual rates

    Moving a safety constraint to the final line takes violations from 3.1% to 0.4% and the team wants to close the security ticket. The improvement is probably real; the closure is the error. A rate that fell from one in thirty to one in two hundred and fifty is still a steady stream at volume, and the mechanism is a positional bias in a text predictor, not a property that holds on unseen inputs. Covers reporting a residual as an interval, keeping adversarial slices separate, and what an eval can and cannot support.

External resources