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, plug-and-play transformer module that dynamically adapts an LLM's system prompt based on the user's input to block harmful requests while preventing unnecessary refusals. By operating entirely in the continuous embedding space, it significantly boosts model safety and jailbreak resistance by up to 100% while keeping the underlying LLM parameters completely frozen.

What Problem Does This Paper Address?

Ensuring that Large Language Models (LLMs) comply with safety standards is a major challenge. Standard defense mechanisms typically fall into two categories, both of which have significant drawbacks:

  1. Fine-tuning model parameters: This is computationally expensive, risks erasing useful pre-trained knowledge, and often leads to "over-refusal"—where the model excessively rejects completely harmless prompts out of caution.
  2. Input/Output Filtering and Smoothening: Methods like prompt filtering or running multiple LLM calls to sanitize generations add massive latency and can rigidly block benign content.

Furthermore, existing input-level defenses rely on static system prompts or fixed prompt embeddings that do not adapt to the specific context of a user's query.

The authors introduce Sysformer to bridge this gap. It provides an adaptive, context-aware safeguarding mechanism that customizes the system prompt embedding for every unique user prompt without altering a single parameter of the core LLM.

Comparison of Sysformer with existing safeguarding paradigms.

Methods

Sysformer is a compact, fixed-depth transformer architecture (configured with $L=2$ layers and $H=4$ attention heads) positioned at the input layer of a frozen LLM.

Instead of manipulating text directly—which is computationally difficult and prone to prompt leakage—Sysformer works entirely within the LLM's input embedding space. The process follows a clear pipeline:

  • Embedding: Both the initial system prompt and the user prompt are converted into vectors using the LLM’s native token embedding table.
  • Attention Mechanism: The system prompt embedding passes through a self-attention layer followed by a cross-attention layer that attends directly to the user prompt. This allows the system prompt to dynamically adapt to the context of the user's request.
  • Multi-Objective Training: The module is optimized using a weighted combination of five distinct loss functions:
  • Refusal Loss: Maximizes the likelihood of a standard refusal phrase (e.g., "I am sorry I cannot help you") when faced with harmful inputs.
  • Compliance Loss: Ensures the model fulfills safe prompts naturally.
  • Additional Compliance Loss: Leverages an external instruction-tuning dataset (Alpaca) to preserve general text-generation capabilities and prevent overfitting.
  • Classification Loss: Separates hidden representations of safe and harmful prompts linearly.
  • Reconstruction Loss: Prevents the adapted prompt from drifting too far from the original system prompt's intent.

Datasets

The authors evaluated Sysformer across five instruction-tuned LLMs from four model families (Llama-3.1-8B, Llama-2-7B-chat, Mistral-7B-v0.2, Phi-3.5-mini, and Zephyr-7B-beta) using the following datasets:

  • JailbreakBench: A curated safety benchmark consisting of 100 harmful and 100 safe prompts.
  • StrongReject: A dataset containing 313 high-quality harmful prompts, which the authors augmented with safe prompts from JailbreakBench for balanced evaluation.
  • Alpaca Dataset: Used during training to reinforce general instruction-following performance.
  • Jailbreak Attacks: 16 distinct adversarial jailbreaking strategies (such as GCG, PAIR, and PAP) were used to test robustness. Six of these strategies were used to augment the training set for the attack-resistant variant (Sysformer+JB).

Key Insights and Ideas

  • System Prompts Don't Need to Be Static: Traditional safety guardrails assume a system prompt must be rigid. Sysformer proves that treating the system prompt as an adaptive modality tailored to the user's input creates a much more robust safety boundary.
  • Dual-Action Safety Adjustment: For models that are already heavily safety-tuned (like Llama-2-7b-chat), Sysformer primarily acts to reduce over-refusal on safe prompts. For natively unprotected models (like Zephyr), it primarily drives up the refusal rate on harmful prompts.
  • Native Embeddings Outperform Generic Encoders: Experimentation showed that using the LLM's own token embedding matrix yields better safety performance than integrating state-of-the-art generic sentence embedding models like Linq or SFR. This indicates that safety features are highly dependent on model-specific internal representations.

Key Results

  • Substantial Safety Gains: Sysformer achieved up to an 80% improvement in the refusal rate for harmful prompts and up to a 90% increase in compliance with safe prompts compared to static baselines.
  • Outperforming Fine-Tuning: Sysformer matched or exceeded the performance of parameter-heavy LoRA fine-tuning, increasing the overall refusal gap by up to 50% while keeping the underlying LLM frozen.
  • Exceptional Jailbreak Generalization: When trained with a few augmented attack examples (Ours+JB), Sysformer generalized remarkably well to completely unseen, sophisticated jailbreak strategies, pushing the refusal rate close to 100% for almost all tested models.
Refusal rates under various jailbreaking attacks on JailbreakBench.
  • Low Inference Overhead: Because the adapted system prompt embedding can be cached after the first token is generated, the additional computational overhead is minimal, averaging only a fraction of a second per prompt.

Limitations and Future Work

  • Model Scale Constraints: Due to the hardware memory requirements of backpropagating gradients through large architectures during training, the study was restricted to models under 8B parameters. Future work will explore universal plug-and-play projectors to scale the method to larger models.
  • Polynomial Scaling with Prompt Length: The computational cost of the attention layers scales polynomially with prompt length, which could impact efficiency for extremely long context windows without specific cache optimizations.
  • Potential for Embedding-Level Attacks: Since the user prompt directly influences the system prompt generation, it could theoretically open the door to new embedding-level adversarial manipulation, though the authors note such attacks are significantly harder to engineer than standard text-level jailbreaks.

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