Safeguarding Large Language Models in Real-time with Tunable Safety-Performance Trade-offs

Joao Fonseca, Andrew Bell, Julia Stoyanovich
1/2/2025
cs.CLcs.AIcs.CR

No official code found. Best implementation: joaopfonseca/SafeNudge (1 star, MIT, last commit 2025-09-16).

Abstract

Large Language Models (LLMs) have been shown to be susceptible to jailbreak attacks, or adversarial attacks used to illicit high risk behavior from a model. Jailbreaks have been exploited by cybercriminals and blackhat actors to cause significant harm, highlighting the critical need to safeguard widely-deployed models. Safeguarding approaches, which include fine-tuning models or having LLMs "self-reflect", may lengthen the inference time of a model, incur a computational penalty, reduce the semantic fluency of an output, and restrict ``normal'' model behavior. Importantly, these Safety-Performance Trade-offs (SPTs) remain an understudied area. In this work, we introduce a novel safeguard, called SafeNudge, that combines Controlled Text Generation with "nudging", or using text interventions to change the behavior of a model. SafeNudge triggers during text-generation while a jailbreak attack is being executed, and can reduce successful jailbreak attempts by 30% by guiding the LLM towards a safe responses. It adds minimal latency to inference and has a negligible impact on the semantic fluency of outputs. Further, we allow for tunable SPTs. SafeNudge is open-source and available through https://pypi.org/, and is compatible with models loaded with the Hugging Face "transformers" library.

View on arXivView PDF

Code Implementations(1)

MIT

A Python library with the implementation for the algorithms used in "Safeguarding large language models in real-time with tunable safety-performance trade-offs", by J. Fonseca, A. Bell and J. Stoyanovich.

11Python, Jupyter NotebookNov 19, 20241 years agoMIT

Similar Papers

Cite this paper

@article{fonseca2025safeguarding,
  title  = {Safeguarding Large Language Models in Real-time with Tunable Safety-Performance Trade-offs},
  author = {Joao Fonseca and Andrew Bell and Julia Stoyanovich},
  year   = {2025},
  eprint = {2501.02018},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2501.02018v1}
}

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

Discussion