Sysformer: Safeguarding Frozen Large Language Models with Adaptive System Prompts

Kartik Sharma, Yiqiao Jin, Vineeth Rakesh, Yingtong Dou, Menghai Pan, Mahashweta Das, Srijan Kumar

TL;DR

Sysformer is a lightweight, modular transformer that safeguards Large Language Models (LLMs) by dynamically adapting system prompts based on specific user inputs. By modifying prompts in the embedding space while keeping the core LLM frozen, it achieves up to an 80% improvement in refusing harmful content and a 90% boost in complying with safe requests, even against sophisticated jailbreak attacks.

What Problem Does This Paper Address?

As LLMs move into safety-critical applications, the "safety-utility tradeoff" remains a major hurdle. Current defenses generally fall into two camps:

  1. Fine-tuning: Updating the model's weights to be safer. This is computationally expensive, risks "catastrophic forgetting" of useful knowledge, and often leads to "over-refusal" (where the model becomes too timid to answer benign questions).
  2. Fixed System Prompts: Hard-coding instructions like "You are a helpful and harmless assistant." These are brittle and easily bypassed by "jailbreaking" techniques that trick the model into ignoring its instructions.

The authors identify a critical gap: system prompts are usually static, regardless of whether a user is asking for a cookie recipe or instructions on building a bomb. They propose that for a defense to be truly robust, the system prompt must be adaptive—it needs to change its "posture" based on the context of the user's query.

Methods

The authors introduce Sysformer, a fixed-depth modular transformer architecture that acts as a "pre-processor" for the LLM.

Comparison of Sysformer with existing LLM defense strategies.

Instead of changing the text of the system prompt, Sysformer operates in the input embedding space. Here’s the workflow:

  • Input: It takes the initial system prompt and the user's query.
  • Mechanism: It uses a series of self-attention and cross-attention layers. The system prompt "attends" to the user prompt, allowing the model to learn how to transform the system prompt's representation to better counter the specific user input.
  • Output: A modified set of embeddings that are prepended to the user's query and fed into a frozen LLM.

To train Sysformer, the authors use a multi-faceted loss function:

  • Refusal Loss: Encourages the model to output a standard refusal string for harmful prompts.
  • Compliance Loss: Ensures the model remains helpful for safe prompts.
  • Classification Loss: Aligns the LLM's internal hidden states with a "refusal direction."
  • Reconstruction Loss: Prevents the system prompt from drifting too far from its original semantic meaning.

Datasets

The study utilizes several key benchmarks to evaluate safety and utility:

  • JailbreakBench: A curated set of 100 harmful and 100 safe prompts used to test standard safety.
  • StrongReject: A more challenging dataset containing 313 sophisticated harmful prompts.
  • Alpaca: Used as an additional instruction-tuning dataset to ensure the model doesn't lose its general ability to follow safe instructions.
  • Jailbreak Attacks: The authors tested against 16 different attack strategies (like GCG, PAIR, and PAP) to evaluate adversarial robustness.

Key Insights and Ideas

  • The Power of the Embedding Space: By working with continuous embeddings rather than discrete text tokens, Sysformer can make subtle, high-dimensional adjustments to the model's "instructional context" that are impossible to achieve with standard text prompting.
  • Modular Safety: Because the core LLM remains frozen, Sysformer acts as a "plug-and-play" safety layer. You can train it once for a specific model and deploy it without the massive overhead of full-model fine-tuning.
  • Context-Aware Defense: The "aha moment" here is that a model doesn't need to be equally "on guard" for every prompt. By adapting the system prompt to the user's intent, the model can be more permissive with safe users while becoming significantly more rigid when it detects a potential attack.
  • Generalization to Unseen Attacks: Even when trained on only a small subset of jailbreak techniques, the "Ours+JB" version of Sysformer showed a remarkable ability to block entirely new, unseen attack strategies.

Key Results

The experimental results across five different LLM families (including Llama-3, Mistral, and Phi-3) are striking:

  • Refusal Gains: Sysformer increased the refusal rate on harmful prompts by up to 80% compared to default system prompts.
  • Utility Preservation: It enhanced compliance with safe prompts by up to 90%, effectively solving the over-refusal problem seen in many safety-tuned models.
  • Adversarial Robustness: When augmented with a few jailbreak examples during training, the model became up to 100% more robust against a wide variety of sophisticated attacks.
  • Efficiency: The inference overhead is minimal, typically adding only 20-30 seconds of total processing time across an entire benchmark set.

Limitations and Future Work

While promising, the authors note a few constraints:

  • Scaling Laws: Due to the need to backpropagate gradients through the frozen LLM during training, the study was limited to models up to 8B parameters. Scaling this to 70B+ models will require more memory-efficient training techniques.
  • Computational Complexity: The method's cost scales polynomially with prompt length, which could impact efficiency for very long documents or multi-turn conversations.
  • New Attack Vectors: The authors acknowledge that making the system prompt adaptive could theoretically open the door to "embedding-level" attacks, though these are currently much harder to craft than text-level jailbreaks.

Future research directions include exploring "universal" Sysformers that can work across different LLMs and applying this adaptive logic to other domains like Retrieval-Augmented Generation (RAG).

Summary updated

BibTeX
@inproceedings{sharma2026sysformer,
  author = {Kartik Sharma and Yiqiao Jin and Vineeth Rakesh and Yingtong Dou and Menghai Pan and Mahashweta Das and Srijan Kumar},
  title = {{Sysformer: Safeguarding Frozen Large Language Models with Adaptive System Prompts}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=EbgCEd8gyN},
}
Figure