Skip to main content
QUICK REVIEW

[Paper Review] On Prompt-Driven Safeguarding for Large Language Models

Chujie Zheng, Fan Yin|arXiv (Cornell University)|Jan 31, 2024
VLSI and Analog Circuit TestingComputer Science5 citations
TL;DR

The paper analyzes how safety prompts affect LLM safeguarding via representations and introduces DRO, a method to automatically optimize safety prompts by moving query representations toward/refusal directions.

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.

Motivation & Objective

  • Investigate how safety prompts influence LLM safeguarding from a representation perspective.
  • Test hypotheses about harmful vs. harmless query separability and refusal dynamics.
  • Develop an automatic safety prompt optimization method (DRO) grounded in representation space.

Proposed method

  • Collect and synthesize controlled harmful/harmless queries to study representation effects.
  • Visualize model representations with PCA across eight open-source 7B LLMs under different safety prompts.
  • Propose DRO to learn continuous safety prompt embeddings that move query representations along/refusal direction; include a regularization term to preserve general ability.
  • Anchor a low-dimensional representation space using PCA on safe anchor data and fit a logistic regression to estimate the refusal direction.
  • Optimize the continuous safety prompts with a contrastive objective that increases refusal for harmful queries and decreases it for harmless ones; add a regularization term to prevent degeneration.

Experimental results

Research questions

  • RQ1Do safety prompts improve harmfulness recognition, or do they increase refusal probability overall?
  • RQ2How do safety prompts alter the representation of harmful and harmless queries in latent space?
  • RQ3Can continuous safety prompts be optimized to improve safeguarding while preserving general model capability?
  • RQ4Is there a measurable refusal direction in the representation space that can guide prompt optimization?

Key findings

  • Safety prompts move query representations in similar directions, increasing overall refusal probability even for harmless queries.
  • Harmful/harmless queries remain largely distinguishable in representation space without safety prompts, challenging the idea that prompts primarily boost harmfulness recognition.
  • DRO significantly improves safeguarding on out-of-domain benchmarks (e.g., reducing harmful query compliance from 10.3% to 1.4% on AdvBench for LLaMA-2 safety prompt).
  • DRO outperforms vanilla Prompt-Tuning and preserves general model capability as measured on AlpacaEval.
  • Regularization is essential to maintain generation quality while optimizing the safety prompt.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.