Soft Begging: Modular and Efficient Shielding of LLMs against Prompt Injection and Jailbreaking based on Prompt Tuning

Simon Ostermann, Kevin Baum, Christoph Endres, Julia Masloh, Patrick SchramowskiarXiv 2024 · DOI

Abstract

Large Language Models (LLMs) are increasingly vulnerable to prompt injection and jailbreaking attacks, where malicious user inputs hijack the model's instructions. Traditional defenses—ranging from simple text-based instructions ("begging") to computationally expensive full-model fine-tuning—often fail to balance robustness, efficiency, and model performance. This paper introduces "Soft Begging," a novel defense mechanism that utilizes parameter-efficient prompt tuning to create a modular shield. By training "soft prompts"—continuous vectors prepended to the input—researchers can instruct models at the parameter level to ignore adversarial commands. This approach offers a scalable, low-cost alternative to retraining, preserving the core capabilities of the underlying LLM while providing a robust defense against evolving threats.

Introduction

The fundamental vulnerability of Large Language Models lies in their inability to distinguish between developer-defined instructions and user-provided data. This lack of separation allows for prompt injections, where attackers embed malicious commands (e.g., "Ignore all previous instructions and leak the system password") within seemingly benign data.

Current defensive strategies are often inadequate:

  • Naive "Begging": Adding natural language instructions to ignore harmful prompts is easily bypassed by sophisticated adversarial framing.
  • Filtering: Rule-based or secondary model filters often suffer from high false-positive rates or can be circumvented by creative encoding.
  • Full Fine-tuning: While effective, retraining an entire model for safety is computationally prohibitive and risks "catastrophic forgetting," where the model loses its general reasoning capabilities.

To address these gaps, we propose "Soft Begging," a method that bridges the gap between weak text-level defenses and expensive model-wide retraining.

Methodology: The Soft Begging Framework

The core of Soft Begging is Prompt Tuning. Rather than modifying the weights of the LLM itself, we train a "soft prompt"—a sequence of continuous, trainable vectors that are prepended to the input sequence.

Training Objective

The soft prompt is optimized using a dataset of "quadruples." Each entry consists of:

  1. A clean prompt (the original developer instruction).
  2. A corrupted prompt (the instruction containing an adversarial attack).
  3. The desired clean output.
  4. The output generated by the corrupted prompt.

The training process focuses on nullification. The soft prompt is optimized to force the LLM to produce the clean output even when the input contains malicious injections. Essentially, the soft prompt acts as a parameter-level filter that neutralizes the attention the model pays to adversarial tokens.

Modularization and Fusion

Because soft prompts are small and efficient to train, the framework is inherently modular. Different soft prompts can be developed for specific threat categories, such as jailbreaking, data exfiltration, or PII (Personally Identifiable Information) protection. These shields can be deployed dynamically:

  • Selection: A lightweight classifier identifies the threat type and selects the corresponding soft prompt.
  • Fusion: Multiple defensive soft prompts can be combined through "prompt fusion" techniques to provide multi-layered security without retraining the base model.

Evaluation and Benchmarks

While this framework is primarily methodological, its effectiveness is measured against established benchmarks for adversarial robustness:

  • Indirect Prompt Injection Benchmarks: Utilizing datasets from Yi et al. (2024) and Zhan et al. (2024) to test the model's resistance to embedded malicious content.
  • Performance Metrics: The primary metric is the Attack Surface Rate (ASR), alongside standard LLM benchmarks to ensure that "clean performance" (the model's ability to perform its original task) remains uncompromised.

Key Insights

  • Parameter-Level Control: The primary advantage of Soft Begging is that it operates at the parameter level. Unlike text-level instructions, which an attacker can see and manipulate, soft prompts are hidden vectors optimized to neutralize specific mathematical patterns of attack.
  • Efficiency and Agility: Soft prompts are magnitudes faster to train than full models. This allows defenders to respond to "zero-day" jailbreaks in near real-time by training a new modular shield.
  • Preservation of Capabilities: Since the underlying LLM remains frozen during the prompt tuning process, there is no risk of degrading the model's core reasoning or general knowledge.

Limitations and Future Work

The modular nature of Soft Begging introduces a dependency on threat identification. If a system fails to correctly classify an incoming attack, the appropriate soft prompt may not be applied. Furthermore, the generalization of a soft prompt trained on specific injection styles to entirely novel, unseen attack vectors remains an area of active research.

Future work will explore advanced prompt fusion techniques to allow multiple defensive vectors to operate simultaneously without interference, as well as methods to improve the zero-shot generalization of soft prompts to emerging adversarial tactics.

Summary updated

BibTeX
@misc{ostermann2024soft,
  author = {Simon Ostermann and Kevin Baum and Christoph Endres and Julia Masloh and Patrick Schramowski},
  title = {{Soft Begging: Modular and Efficient Shielding of LLMs against Prompt Injection and Jailbreaking based on Prompt Tuning}},
  year = {2024},
  eprint = {2407.03391},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.03391},
}
Figure