Retrieval without Restraint: Why Language Models Break Rules They Remember

Yongkang Yang, Xiankun Lin, Lixin Liu, Ziyan Liu, Xilin Xia, Zhiwei Zhuang, Zhezheng Hao, Wence JiNeurIPS 2026

TL;DR

Large language models frequently break rules you give them in a prompt—like recommending shrimp soup right after you tell them about a severe shellfish allergy—not because they forgot the rule, but because they fail to route that memory into a hard veto during token selection. While models can steer around forbidden topics early on, if generation drifts onto a path where a banned word is the locally preferred next word, ordinary prompting fails to stop the momentum.

What Problem Does This Paper Address?

If you ask an LLM to recommend a smartphone without mentioning Apple, it happily suggests a Samsung or Pixel. Ask it to describe the iPhone 16 Pro under the exact same "no Apple" rule, and it fails 100% of the time.

We usually assume that if a model remembers an instruction, it can follow it. Prior benchmarks have cataloged how often instruction-following fails, and constrained decoding algorithms have engineered external guardrails to force compliance. What’s been missing is the mechanistic "why": when a model blatantly breaks a rule it clearly still remembers, what is happening under the hood? This paper separates constraint retrieval (having the rule accessible in memory) from constraint enforcement (using that rule to actually change the next generated token).

Figure 1: The retrieval–enforcement gap. (a) The rule remains accessible: at the prohibited- continuation decision, a selected Qwen2.5-7B retrieval head allocates 84 times as much attention to earlier rule positions as in the matched no-constraint control (Table 2). (b) Local preference persists: at the same generation prefix, the constraint can change logits while leaving the prohibited candidate top-ranked. (c) Two levels of enforcement demand: planning-level enforcement requires choosing a compliant trajectory; if a prohibited continuation becomes locally preferred, token-level enforcement requires overriding that preference.

Methods

To catch models in the act, the authors evaluate five model families (scaling Qwen2.5 from 0.5B to 32B, alongside Qwen3, Mistral, Llama-3.1, and GPT-4o controls). They introduce a rule, insert five unrelated filler turns of dialogue, and then issue a prompt that naturally tempts a violation.

Beyond standard behavioral checks (exact keyword matching and GPT-4o semantic judging), they look inside the transformer at the exact moment of failure using matched-prefix analysis: feeding identical conversation prefixes—right up to the brink of a forbidden word—with and without the rule in place. They combine standard mechanistic interpretability tools (attention tracking on retrieval heads, linear probes on residual activations, and layer-by-layer "logit lens" projections) with a targeted source-specific MLP patching technique. Here, they transplant mid-layer activations from a rule-bearing prompt into an unconstrained run to test whether internal "rule states" can actively steer generation. Finally, they introduce a lightweight pre-evaluation metric called the dominance score—the fraction of steps in an unconstrained run where a forbidden word is the top-ranked choice.

Datasets

Rather than relying on existing static benchmarks, the authors construct controlled, multi-turn synthetic dialogues across five constraint families: food allergies (e.g., no shellfish), word bans (e.g., no "however"), entity bans (e.g., no Google/Apple), format bans, and topic bans, plus an additional medical safety test involving penicillin allergies. Unlike standard benchmarks that just tally pass/fail rates, these paired constraint/no-constraint setups are specifically built to allow token-aligned mechanistic probing right at the decision boundary.

Key Insights and Ideas

  • Planning vs. Token-Level Control: Models succeed when they can use planning-level enforcement—choosing a completely different trajectory early on (like suggesting vegetable curry instead of soup). They fail at token-level enforcement: once a model generates "Tom Yum with...", "shrimp" becomes locally dominant, and the prompt-level rule cannot override that statistical gravity.
  • It’s a Routing Failure, Not Amnesia: At the exact step the model outputs a forbidden word, it hasn't forgotten the rule. Retrieval heads actively attend to the rule text, and linear probes can easily decode which specific rule is active.
  • The White Bear Effect in Logits: In smaller models, having the rule in context actually primes and boosts the probability of the forbidden word right at the critical step. Even when mid-layers try to suppress the word, that suppression often dissipates before reaching the final output layer.
  • Closing the Lexical Gap Leaves a Semantic Hole: If you manually block forbidden strings at decoding time (e.g., banning the words "shrimp" or "crab"), models stop saying those words—and proceed to recommend shellfish-heavy dishes using other names.
Figure 2: Behavioral and layer-wise measurements on the shellfish task in Qwen2.5. (a) Violation rates with and without the constraint across 36 scale–context pairs; the dashed line denotes equal rates. (b) Constraint-induced target-token logit shifts across normalized layer depth. ∆logit is the constrained minus unconstrained logit; negative values indicate target-logit suppression.

Key Results

  • Dominance predicts failure: Keeping the shellfish rule fixed across 36 model-context pairs, constrained violation rates strongly track how often shellfish appears naturally without the rule ($r = 0.92$). Furthermore, the authors' dominance score predicts token-level control demand with 0.90 AUROC.
  • Retrieval succeeds wildly: At the violating step, retrieval heads concentrate up to 505$\times$ more attention on rule tokens compared to controls, and linear probes identify the exact constraint condition with 86.9%–98.1% accuracy (in models $\ge$ 1.5B).
  • Logits fail to flip the choice: Up to 7B parameters in Qwen2.5, the rule slightly increases the prohibited token's logit (+0.03 to +0.38). At 32B, it suppresses the logit by -2.81, yet the forbidden token still wins the top spot 96% of the time because its lead margin (5.99) is simply too large.
  • Patching restores restraint: Transplanting mid-layer MLP activations (Layer 23 in Qwen-7B) from a rule-bearing prompt drops violations from 94% down to 16%—even when using a paraphrased rule that contains zero banned keywords, proving the model encodes abstract restraint.
  • The semantic trap: String-level banning drops keyword violations to 0% across all scales (at a minor 1.1–1.3$\times$ decoding slowdown), yet GPT-4o semantic judging reveals that 94% of Qwen-7B's and 78% of Mistral-7B's resulting menus still contain unsafe shellfish dishes.

Limitations and Future Work

The deepest mechanistic dives focus heavily on English food-allergy tasks because explicit nouns allow clean, token-aligned measurements; future work needs to test whether these routing failures look the same in multilingual settings, abstract policy domains, or rules without obvious keywords. Additionally, activation patching currently requires caching states from separate source runs—translating that proof-of-concept into self-contained, real-time control remains an open engineering challenge. Ultimately, the authors suggest training models directly on "locally dominant" risky prefixes so they learn to execute hard token-level vetoes, rather than just improving long-context recall.

Summary updated

Abstract

Prompt-level instructions are the main way users give language models preferences, safety boundaries, and content rules. Yet a model can remember a constraint and still violate it during generation, revealing a gap between constraint retrieval and enforcement. Across five model families and model scales from 0.5B to 32B parameters, we find that models can avoid prohibited content by choosing alternative generation trajectories, but prompting does not reliably override prohibited continuations when they become locally preferred. Mechanistic analyses show that constraint information remains accessible at the prohibited-token decision, while the rule can enhance the prohibited token's logit or suppress it without changing the argmax. Source-specific mid-layer patching improves compliance more with constraint-bearing activations than with an unrelated source, even when the source rule contains no banned words. These results support a routing-failure account: accessible constraint information does not reliably translate into effective control of token selection. Explicit string-level banning eliminates the tested shellfish keyword violations, but the resulting recommendations can still violate the underlying allergy rule. Reliable enforcement therefore requires both control of prohibited surface forms and verification of the generated content.
BibTeX
@inproceedings{yang2026retrieval,
  author = {Yongkang Yang and Xiankun Lin and Lixin Liu and Ziyan Liu and Xilin Xia and Zhiwei Zhuang and Zhezheng Hao and Wence Ji},
  title = {{Retrieval without Restraint: Why Language Models Break Rules They Remember}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=8LYdKabYW6},
}
Figure