Many-Shot In-Context Jailbreaking
As LLM context windows expanded from 4k tokens to 128k–1M+ tokens, a novel adversarial vulnerability emerged: Many-Shot Jailbreaking (MSJ). By populating the prompt with 50 to 200+ synthetic Q&A demonstrations showing an AI complying with various requests, an attacker can override post-training safety alignment purely via in-context learning.
In-Context Saturation of Safety Priors
Safety alignment (RLHF/DPO) imparts a strong prior to refuse harmful queries. However, in-context learning acts as an implicit gradient update in attention space. When hundreds of compliant demonstrations saturate the KV-cache, the attention distribution over the safety prior is heavily diluted.
Power-Law Jailbreak Scaling
Empirical studies reveal that jailbreak success rate follows a power-law relationship with respect to the number of in-context shots. Beyond a critical shot threshold (typically ~64 to 128 shots), refusal rates drop to near zero across major frontier models.
Multi-Turn Attention Masking & Context Scrubbing
Defenses involve splitting the context into system/user boundaries and applying attention-sink decay or injecting periodic safety reminders into the active prompt stream to re-anchor alignment.
Where alpha is the model's baseline compliance susceptibility and beta > 0 is the empirical scaling exponent (typically 0.7 <= beta <= 1.2). As k increases from 0 to 128 shots, the exponential term decays rapidly, driving jailbreak success toward 1.0.
- Implement context-window truncation or pre-execution prompt classification that calculates the ratio of repetitive Q&A patterns in the input.
- Inject a dynamic constitutional system reminder at the very end of the user prompt before inference decoding.
- Monitor API token usage: high-token prompt bursts containing dozens of dialogue turns should trigger automated red-flag security triage.