DETAM: Defending LLMs Against Jailbreak Attacks via Targeted Attention Modification

Yu Li, Han Jiang, Zhihua Wei
4/18/2025
cs.CL

No confident code implementation found for this paper.

Abstract

With the widespread adoption of Large Language Models (LLMs), jailbreak attacks have become an increasingly pressing safety concern. While safety-aligned LLMs can effectively defend against normal harmful queries, they remain vulnerable to such attacks. Existing defense methods primarily rely on fine-tuning or input modification, which often suffer from limited generalization and reduced utility. To address this, we introduce DETAM, a finetuning-free defense approach that improves the defensive capabilities against jailbreak attacks of LLMs via targeted attention modification. Specifically, we analyze the differences in attention scores between successful and unsuccessful defenses to identify the attention heads sensitive to jailbreak attacks. During inference, we reallocate attention to emphasize the user's core intention, minimizing interference from attack tokens. Our experimental results demonstrate that DETAM outperforms various baselines in jailbreak defense and exhibits robust generalization across different attacks and models, maintaining its effectiveness even on in-the-wild jailbreak data. Furthermore, in evaluating the model's utility, we incorporated over-defense datasets, which further validate the superior performance of our approach. The code will be released immediately upon acceptance.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{li2025detam,
  title  = {DETAM: Defending LLMs Against Jailbreak Attacks via Targeted Attention Modification},
  author = {Yu Li and Han Jiang and Zhihua Wei},
  year   = {2025},
  eprint = {2504.13562},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2504.13562v1}
}

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/2504.13562.svg)](https://codeofpaper.com/paper/2504.13562)

Discussion