Adaptive Detoxification: Safeguarding General Capabilities of LLM s through Toxicity-Aware Knowledge Editing (2025)

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.

## introduction large language models (llms) such as chat-gpt @xcite , llama @xcite and @xcite have gained widespread adoption due to their impressive capabilities in language understanding and reasoning @xcite @xcite . to ensure that the outputs of these models adhere to the 3h principles-helpful, honest, and harmless @xcite -they are typically aligned with human values through safety training @xcite corresponding author. ## conclusion we present toxedit, a novel toxicity-aware knowledge editing method that effectively mitigates harmful outputs in llms while safeguarding general capabilities. by detecting toxic activation patterns and leveraging adaptive inter-layer pathways, our approach overcomes the limitations of existing methods, addressing both entity-agnostic attacks and over-editing issues. additionally, we enhance the safeedit benchmark to provide a more comprehensive evaluation of over-editing. experimental results demonstrate that toxedit achieves superior detoxification performance while maintaining llm's general capabilities.