Mitigating Many-shot Jailbreak Attacks with One Single Demonstration

Kejia Chen, Jiawen Zhang, Boheng Li, Pengcheng Li, Jian Lou +4 more
5/8/2026
cs.CRcs.AI

Official code: Thecommonirin/SafeEnd (3 stars, last commit 2026-05-07).

Abstract

Many-shot jailbreaking (MSJ) causes safety-aligned language models to answer harmful queries by preceding them with many harmful question-answer demonstrations. We study why this attack becomes stronger as the number of demonstrations increases.

Show full abstract

Empirically, we find that MSJ induces a progressive activation drift: the representation of a fixed harmful query moves step by step away from the safety-aligned region as more harmful demonstrations are added. Theoretically, we show that this drift can be interpreted as implicit malicious fine-tuning: conditioning on N harmful demonstrations induces SGD-style updates equivalent to optimizing on the corresponding N harmful samples. This view turns the attack mechanism into a defense principle. We append a fixed one-shot safety demonstration at inference time, which induces a counteracting safety-oriented update and restores refusal behavior. The resulting method improves the model's robustness to MSJ without modifying its parameters or requiring white-box access at deployment. Code is available at https://github.com/Thecommonirin/SafeEnd.

View on arXivView PDF

Code Implementations(1)

Explaining many-shot jailbreaks as context-induced drift and introducing SafeEnd: a training-free defense that restores safety alignment via a single fixed demonstration.

30May 7, 20266 months ago

Similar Papers

Cite this paper

@article{chen2026mitigating,
  title  = {Mitigating Many-shot Jailbreak Attacks with One Single Demonstration},
  author = {Kejia Chen and Jiawen Zhang and Boheng Li and Pengcheng Li and Jian Lou and Zunlei Feng and Mingli Song and Ruoxi Jia and Tianwei Zhang},
  year   = {2026},
  eprint = {2605.08277},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2605.08277v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2605.08277.svg)](https://codeofpaper.com/paper/2605.08277)

Discussion