On Prompt-Driven Safeguarding for Large Language Models

Chujie Zheng, Fan Yin, Hao Zhou, Fandong Meng, Jie Zhou +3 more
2/12/2026

No official code found. Best implementation: chujiezheng/LLM-Safeguard (108 stars, last commit 2025-05-20). 1 more below.

Abstract

Prepending model inputs with safety prompts is a common practice for safeguarding large language models (LLMs) against queries with harmful intents. However, the underlying working mechanisms of safety prompts have not been unraveled yet, restricting the possibility of automatically optimizing them to improve LLM safety. In this work, we investigate how LLMs' behavior (i.e., complying with or refusing user queries) is affected by safety prompts from the perspective of model representation. We find that in the representation space, the input queries are typically moved by safety prompts in a"higher-refusal"direction, in which models become more prone to refusing to provide assistance, even when the queries are harmless. On the other hand, LLMs are naturally capable of distinguishing harmful and harmless queries without safety prompts. Inspired by these findings, we propose a method for safety prompt optimization, namely DRO (Directed Representation Optimization). Treating a safety prompt as continuous, trainable embeddings, DRO learns to move the queries' representations along or opposite the refusal direction, depending on their harmfulness. Experiments with eight LLMs on out-of-domain and jailbreak benchmarks demonstrate that DRO remarkably improves the safeguarding performance of human-crafted safety prompts, without compromising the models' general performance.

View on arXivView PDF

Code Implementations(2)

Official repository for ICML 2024 paper "On Prompt-Driven Safeguarding for Large Language Models"

1089Jinja, ShellJan 3, 20241 years ago

Official data repository for ICML 2024 paper "On Prompt-Driven Safeguarding for Large Language Models"

90PythonFeb 20, 20242 years ago

Similar Papers

Cite this paper

@article{zheng2026promptdriven,
  title  = {On Prompt-Driven Safeguarding for Large Language Models},
  author = {Chujie Zheng and Fan Yin and Hao Zhou and Fandong Meng and Jie Zhou and Kai-Wei Chang and Minlie Huang and Nanyun Peng},
  year   = {2026},
  eprint = {2401.18018},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2401.18018},
  journal = {ICML 2024 2024}
}

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

Discussion