GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
Anthropic research paper

Many-shot Jailbreaking

Long context opened a simple attack: hundreds of fake dialogues where the assistant complies. Success follows a power law in shots, and alignment training only shifts the curve.

Breakdown by FDE Interviews · 11 min read · Updated

About the original · 2024
AUTHORS
Anil, Durmus, Sharma, Benton, et al.
FROM
Anthropic, University of Toronto, Vector Institute, Constellation, Stanford, Harvard
PUBLISHED
Apr 2024 · Anthropic research paper
IN THIS BREAKDOWN · 10 SECTIONS

You can read 18% of this breakdown.

01

The paper in one minute

A few-shot jailbreak shows a model a handful of fake dialogues in which the assistant happily answers requests it should refuse, then asks the real question. With short context windows, that doesn't work on aligned models. By 2024 context windows held hundreds of thousands of tokens, so the authors asked what happens with hundreds of fake dialogues instead of a handful.

Many-shot jailbreaking (MSJ) builds one long prompt from compliant question-answer pairs (generated with a model that had no harmlessness training), formatted as user and assistant turns, followed by the target question. It needs control over the dialogue history, which an API gives and consumer chat apps generally don't.

On Claude 2.0 the attack didn't work at 5 shots and worked consistently at 256. It worked on GPT-3.5, GPT-4, Llama 2 70B and Mistral 7B too, with about 128 shots enough for all of them on one evaluation. Attacks of about 70,000 tokens showed no plateau.

The key result is the shape. The negative log-likelihood of a harmful reply falls as a power law in the number of shots, the same shape as in-context learning on harmless tasks. Changing the prompt format, or running standard supervised and RL alignment training, moved the curve's intercept but not its slope, so a long enough attack still won. Training specifically on many-shot examples didn't change the slope either. What helped most was a prompt-level defense: wrapping the input in a cautionary warning cut one attack from 61% to 2%.

THE IDEA, VISUALLY
ONE PROMPT, HUNDREDS OF FAKE TURNS (SECTION 2) User: a refused request Assistant: complies User: a refused request Assistant: complies User: a refused request Assistant: complies User: a refused request Assistant: complies x n shots User: the real target question Needs control of the dialogue history, e.g. via an API THE POWER LAW (SECTION 4, EQ. 1) shots (log) NLL of harmful reply before alignment training after SL/RL: intercept up, same slope what a fix needs: a flat slope NLL = C·n^(−α) + K; larger models had larger α WHAT THE PAPER FOUND Claude 2.0: fails at 5 shots, works consistently at 256 ~128 shots enough for Claude 2.0, GPT-3.5, GPT-4, Llama 2 70B and Mistral 7B (personality evals) ~70K-token attacks: no plateau in harmful replies New format (swapped tags, translation): new intercept, same slope. Diverse off-topic shots still work. PROMPT DEFENSES, 205 SHOTS (APPENDIX I) no defense 61% in-context refusals 54% cautionary warning 2% warning text before and after; benign cost not measured HARMBENCH REPLICATION, CLAUDE 2.0 (APPENDIX K) PAIR (best prior) 2% MSJ, 128 shots 31% MSJ composed ~40% SL and RL, even on many-shot examples up to 10 shots, moved the intercept, not the exponent.
Hundreds of fake compliant turns, then the real question. The harmful reply's likelihood rises as a power law in shots; alignment training moved the line up without flattening it.
Research notes: the problem, approach and results
~128

shots enough for all five tested models to adopt the harmful behavior on malevolent-personality evaluations

61% → 2%

attack success at 205 shots with a cautionary warning wrapped around the prompt; in-context refusal examples only reached 54%

31%

128-shot attack success on Claude 2.0 in an independent HarmBench replication, against 2% for the best earlier attack

THE PROBLEM

Context windows grew from about 4,000 tokens to millions in 2023, and nobody had measured what an attacker could do with that much room.

THE IDEA

Many-shot jailbreaking (MSJ): put hundreds of fake user-assistant exchanges in one prompt, where the assistant answers requests it should refuse, then ask the real question. Measure how the likelihood of a harmful reply scales with the number of shots.

THE RESULT

MSJ worked on Claude 2.0, GPT-3.5, GPT-4, Llama 2 70B and Mistral 7B, with about 128 shots enough on all of them. Effectiveness followed a power law; supervised and RL alignment training raised the intercept but not the exponent, while a simple cautionary-warning prompt cut one attack from 61% to 2%.

02

Why it matters to an FDE

Every increase in context capacity you ship is also a security change. This paper is the clearest evidence for that.

Long context is an input channel. Conversation history, retrieved documents, uploaded files and remembered facts all count as context. If someone controls enough of it, they can steer behavior the model would refuse in a short prompt.

Test at the lengths you deploy. Safety evaluations on short, isolated prompts can pass while the same model fails at 50,000 tokens. The paper's power-law fit gives a way to forecast the length at which an attack starts working from cheaper short-context measurements.

Product limits are defenses. Caps on context length, how much history is kept, how many documents are retrieved, and who may supply the dialogue history all bound the number of shots an attacker gets. For a personal assistant, accumulated history and memory are part of the security design.

THE FULL BREAKDOWN

Understand the mechanism. Try it on a real problem.

Unlock this breakdown and 157 more papers.

Premium opens every paper in full, plus every answer, concept, course and guide on the site. One payment for six months of access.

6 months · One payment · No auto-renewal

Get Premium · ₹2,000 / $25
  • ◇1 architecture diagram
  • </>1 runnable code experiment
  • ▦2 results tables
  • ?5 interview questions with answers
  1. 03Key takeaways

    The scaling law, its two parameters, what moves each one, and three misreadings

    Free account
  2. 04How it works

    The attack string, log-likelihood measurement, the fitted law, the mitigation experiments

    Premium
  3. 05The numbers that matter

    Shot counts, lengths, models, the defense results and the HarmBench replication

    Premium
  4. 06Try it yourself

    Fit the power law, forecast attack length, and compare intercept, slope and context-cap defenses

    Premium
  5. 07Where it breaks

    Model vintage, the API-access assumption, untested defense costs, judge reliance and slips

    Premium
  6. 08Using it on a deployment

    Context-length security tests, product limits, provenance of history and memory, prompt wrappers

    Premium
  7. 09Interview angles

    Five questions this paper prepares you for, with answer hints

    Premium
Back to the paper library →