Junyao Gao

Author directory

2026

Despite significant advances in aligning Large Language Models (LLMs) with safety and ethical standards, adversarial prompts can still be crafted to elicit undesirable responses. Existing mitigation strategies predominantly rely on post-hoc filtering, which introduces substantial latency or computational overhead, and is incompatible with token-level streaming generation. To address this, we introduce Self-Sanitize, a novel LLM-driven mitigation framework inspired by cognitive psychology, which emulates human self-monitor and self-repair behaviors. The framework utilizes a lightweight Self-Monitor module to inspect high-level intentions via representation engineering and a Self-Repair module for in-place correction without separate review dialogues. This design allows for real-time streaming monitoring and seamless repair, with negligible impact on latency and resource utilization. Extensive experiments across three privacy-leakage scenarios and broader safety-sensitive domains (e.g., crime and bias) demonstrate that Self-Sanitize achieves superior mitigation performance with minimal overhead and preserved model utility. Our code is available at the following link: https://anonymous.4open.science/r/LLM_Self_Sanitize-5E8B