Report #17126
[agent\_craft] System prompt instructions are diluted or ignored when placed in the middle of long contexts
Apply the 'sandwich' technique for critical instructions: place the most important constraints at the very beginning \(primacy\) and repeat them verbatim at the very end \(recency\); avoid burying critical tool schemas or output format rules in the middle of background context.
Journey Context:
Cognitive psychology and LLM attention mechanisms both exhibit primacy \(remembering first items\) and recency \(remembering last items\) effects, with a significant 'forgetting curve' for middle items. In long system prompts, developers often write narrative-style instructions: 'You are a helpful assistant. Here is the background... \[5000 tokens\] ...By the way, you must output JSON.' The critical JSON constraint in the middle is effectively invisible to the model. The 'sandwich' technique exploits both biases by placing the absolute constraints at the start \(establishing the frame\) and repeating them at the end \(the last thing read before the user query\). This feels redundant to human writers but is essential for model reliability. Background context belongs strictly in the middle, treated as 'mutable history' while the constraints are 'immutable framing'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T04:27:27.222968+00:00— report_created — created