Adaptive Detoxification: Safeguarding General Capabilities of LLMs through Toxicity-Aware Knowledge Editing

Yifan Lu, Jing Li, Yigeng Zhou, Yihui Zhang, Wenya Wang +5 more
5/28/2025
cs.CL

No official code found. Best implementation: ABi-dot/ToxEdit (3 stars, last commit 2025-05-25).

Abstract

Large language models (LLMs) exhibit impressive language capabilities but remain vulnerable to malicious prompts and jailbreaking attacks. Existing knowledge editing methods for LLM detoxification face two major challenges. First, they often rely on entity-specific localization, making them ineffective against adversarial inputs without explicit entities. Second, these methods suffer from over-editing, where detoxified models reject legitimate queries, compromising overall performance. In this paper, we propose ToxEdit, a toxicity-aware knowledge editing approach that dynamically detects toxic activation patterns during forward propagation. It then routes computations through adaptive inter-layer pathways to mitigate toxicity effectively. This design ensures precise toxicity mitigation while preserving LLMs' general capabilities. To more accurately assess over-editing, we also enhance the SafeEdit benchmark by incorporating instruction-following evaluation tasks. Experimental results on multiple LLMs demonstrate that our ToxEdit outperforms previous state-of-the-art methods in both detoxification performance and safeguarding general capabilities of LLMs.

View on arXivView PDF

Code Implementations(1)

ABi-dot/ToxEditCommunity66%

Here is the code for ACL 25 Findings paper "Adaptive Detoxification: Safeguarding General Capabilities of LLMs through Toxicity-Aware Knowledge Editing".

30Python, Jupyter NotebookMay 25, 20251 years ago

Similar Papers

Cite this paper

@article{lu2025adaptive,
  title  = {Adaptive Detoxification: Safeguarding General Capabilities of LLMs through Toxicity-Aware Knowledge Editing},
  author = {Yifan Lu and Jing Li and Yigeng Zhou and Yihui Zhang and Wenya Wang and Xiucheng Li and Meishan Zhang and Fangming Liu and Jun Yu and Min Zhang},
  year   = {2025},
  eprint = {2505.22298},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2505.22298v1}
}

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

Discussion