Do LLMs Understand the Safety of Their Inputs? Training-Free Moderation via Latent Prototypes

Maciej Chrabąszcz, Filip Szatkowski, Bartosz Wójcik, Jan Dubiński, Tomasz Trzciński +1 more
2/22/2025
cs.LGcs.AIcs.CL

No confident code implementation found for this paper.

Abstract

With the rise of LLMs, ensuring model safety and alignment has become a critical concern. While modern instruction-finetuned LLMs incorporate alignment during training, they still frequently require moderation tools to prevent unsafe behavior. The most common approach to moderation are guard models that flag unsafe inputs. However, guards require costly training and are typically limited to fixed-size, pre-trained options, making them difficult to adapt to evolving risks and resource constraints. We hypothesize that instruction-finetuned LLMs already encode safety-relevant information internally and explore training-free safety assessment methods that work with off-the-shelf models. We show that simple prompting allows models to recognize harmful inputs they would otherwise mishandle. We also demonstrate that safe and unsafe prompts are distinctly separable in the models' latent space. Building on this, we introduce the Latent Prototype Moderator (LPM), a training-free moderation method that uses Mahalanobis distance in latent space to assess input safety. LPM is a lightweight, customizable add-on that generalizes across model families and sizes. Our method matches or exceeds state-of-the-art guard models across multiple safety benchmarks, offering a practical and flexible solution for scalable LLM moderation.

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{chrabszcz2025llms,
  title  = {Do LLMs Understand the Safety of Their Inputs? Training-Free Moderation via Latent Prototypes},
  author = {Maciej Chrabąszcz and Filip Szatkowski and Bartosz Wójcik and Jan Dubiński and Tomasz Trzciński and Sebastian Cygert},
  year   = {2025},
  eprint = {2502.16174},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2502.16174v2}
}

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

Discussion