GuardFormer: Guardrail Instruction Pretraining for Efficient SafeGuarding

James O' Neill, Santhosh Subramanian, Eric Lin, Abishek Satish, Vaikkunth MugunthanSafeGenAi @ NeurIPS 2024

TL;DR

This paper introduces GuardFormer, a novel approach to building efficient and effective guardrails for Large Language Models (LLMs). By leveraging synthetic data generation and a unique instruction pretraining strategy, GuardFormer achieves state-of-the-art performance while being significantly smaller and faster than existing solutions, making robust LLM safety more accessible.

What Problem Does This Paper Address?

The increasing power and widespread adoption of LLMs have brought about significant concerns regarding their potential for generating harmful, biased, or unsafe content. While various guardrailing techniques exist, they often come with a steep price: high inference costs, substantial memory footprints, and a tendency to degrade the LLM's overall performance on legitimate tasks. Existing solutions, like third-party APIs or specialized LLMs, can be slow, inflexible, and struggle to adapt to new or custom safety policies. This paper tackles the challenge of creating guardrails that are not only highly accurate and adaptable but also computationally efficient and cost-effective.

Methods

The core innovation lies in GuardFormer's Guardrail Instruction Pretraining (GIP) strategy, built upon a Synthetic Data Generation (SDG) pipeline.

  1. Synthetic Data Generation (SDG): The process starts with defining a "policy" – a set of rules outlining desired and undesired behaviors. An LLM then generates synthetic data, including compliant/non-compliant prompts, rationales for these classifications, and binary labels. A self-reflection step is incorporated to refine the LLM's own label predictions, improving data quality.
  2. PolicyGuard (Single-Policy Classifier): Initially, the generated data is used to fine-tune a base classifier (like RoBERTa-large) for each specific policy. This creates specialized, efficient classifiers.
  3. GuardFormer (Multi-Policy Guardrailing): To achieve a single, versatile model, GuardFormer concatenates datasets from multiple policies. This unified dataset is then used to generate even more diverse synthetic data. GuardFormer is then trained using a multi-task learning approach, combining Masked Language Modeling (MLM), Alice++ loss (for robustness), and a classification loss. This allows the model to learn shared representations across different guardrail tasks, enabling it to handle multiple policies simultaneously.

Datasets

The authors evaluate their approach on a combination of public and private benchmarks:

  • Public Benchmarks:
    • Prompt Injection: deepset/prompt-injections, xTRam1/safe-guard-prompt-injection
    • Toxicity: lmsys/toxic-chat, SetFit/toxic_conversations_50k
    • Content Safety: nvidia/Aegis-AI-Content-Safety-Dataset-1.0, mmathys/openai-moderation-api-evaluation, PKU-Alignment/BeaverTails
  • Private Benchmark (CustomGuardBench): A newly introduced benchmark consisting of four categories: Safety, Finance, Tax, and Injection. This dataset was manually annotated by domain experts and policy-informed annotators.

Key Insights and Ideas

  • Synthetic Data is King (and Queen): Models trained on synthetically generated data consistently outperform those trained on real data, even when evaluated against custom policies. This highlights the power and scalability of their SDG pipeline.
  • Instruction Tuning for Guardrails: Applying instruction-based pretraining (GIP) to guardrail tasks significantly enhances generalization and efficiency, allowing a single model to handle diverse policies.
  • Efficiency is Achievable: GuardFormer demonstrates that high performance doesn't require massive models. It achieves state-of-the-art results with a model size of just 512MB, a fraction of the size of models like GPT-4.
  • Zero-Shot Power: GuardFormer exhibits impressive zero-shot capabilities, meaning it can generalize to new guardrailing policies with minimal or no task-specific fine-tuning, a significant advantage over previous methods.
  • Faster Fine-tuning: GuardFormer converges faster during fine-tuning, requiring fewer training steps and epochs compared to single-policy models like PolicyGuard.

Key Results

  • Superior Performance: GuardFormer significantly outperforms state-of-the-art LLMs and third-party APIs.
  • Achieves average F1 score improvements of 29.64 and 21.07 points compared to Aegis-LlamaGuard and GPT-4o, respectively.
  • Outperforms GPT-4o by 21.62 average F1 score points on public datasets.
  • Efficiency: GuardFormer is up to 14 times faster than GPT-4 and requires only 512MB of storage.
  • Multi-Policy Capability: GuardFormer can learn from multiple custom policies simultaneously, a feat not easily achieved by many baselines.
  • Private Benchmark Success: GuardFormer demonstrates superior performance across all categories of the CustomGuardBenchmark, particularly excelling in Safety (91.83 F1) and Injection (88.62 F1).

Limitations and Future Work

  • Reliance on LLM for Generation: The SDG pipeline relies on an LLM generator. While they use a powerful model (Mixtral 8x22B-Instruct), the quality of the generated data is inherently tied to the generator's capabilities.
  • Future Work: The authors suggest that GuardFormer's zero-shot capabilities and efficiency make it a strong candidate for on-device deployment and integration with general-purpose LLMs, enabling faster and lower-cost guardrailing. Further exploration of its adaptability to novel and unseen policies is also a promising direction.

Summary updated

BibTeX
@inproceedings{neill2024guardformer,
  author = {James O' Neill and Santhosh Subramanian and Eric Lin and Abishek Satish and Vaikkunth Mugunthan},
  title = {{GuardFormer: Guardrail Instruction Pretraining for Efficient SafeGuarding}},
  booktitle = {SafeGenAi @ NeurIPS},
  year = {2024},
  url = {https://openreview.net/forum?id=vr31i9pzQk},
}
Figure