A small Transformer strips the disguise off adversarial prompts before they reach your LLM. The cost? About 32 tokens and 25 milliseconds.


Every jailbreak attack shares the same architecture. Take a harmful instruction. Wrap it in noise, roleplay, or optimized gibberish. Hope the model's safety guardrails miss the real request buried inside the padding. The attacks work because LLMs process text linearly. They read the wrapping and the core together, and the camouflage wins often enough to matter.

Microsoft's SecurityLingua, accepted at COLM 2025, flips the attacker's strategy against itself. The same prompt compression that Microsoft built to speed up inference now strips away the adversarial padding and reveals the harmful intent underneath. Then it hands that extracted intent to the target LLM through the system prompt, so the model knows exactly what it is dealing with before it processes the original request.

The result is a defense that works on every major attack type, adds near-zero overhead, and does not touch the original user query. No retraining. No rewriting. No multi-agent verification loops that cost hundreds of tokens and seconds of latency.

The Problem With Existing Defenses

Current jailbreak defenses fall into five rough categories, and each one carries a dealbreaking tradeoff.

Safety fine-tuning retrains the model to resist attacks. This requires access to model weights, large compute budgets, and curated training data. It does not work on proprietary models like GPT-4 or Claude. And it still leaves gaps when new attack types emerge.

Filtering uses classifiers to catch and reject malicious requests before they reach the model. Perplexity filters flag statistically unusual prompts. Constitutional classifiers check for known patterns. These approaches add false positives. Legitimate requests get blocked. Users see refusals on innocent queries.

Erase-and-check methods like SmoothLLM perturb the input, run multiple variations through a checking LLM, and reject anything that looks suspicious in any variant. The cost scales with the number of variations. SmoothLLM needs thousands of extra tokens and hundreds of milliseconds per request.

Rewriting approaches transform the user's prompt into a sanitized version before passing it along. This changes what the user actually wrote, which breaks the consistency of the interaction. It also introduces latency from the rewriting pass.

Agentic defenses deploy additional LLMs as referees. One agent checks the input. Another checks the output. A third arbitrates. These systems can be effective, but they multiply cost and latency by the number of agents involved.

SecurityLingua is the only approach that clears all four practical requirements at once. It works on both proprietary and open models. It needs no model retraining. It adds minimal cost and latency. And it preserves the original user query unchanged.

How SecurityLingua Works

SecurityLingua runs in two steps. Both happen before the target LLM generates its response.

Step 1: Extract the True Intention

The core insight comes from Microsoft's earlier work on LLMLingua. Prompt compression removes low-importance tokens from a prompt to speed up inference. LLMLingua uses a small language model to score each token's perplexity and strips out the ones that contribute least to the prompt's meaning.

SecurityLingua applies the same idea, but trains the compressor for a different objective. Instead of preserving information for efficiency, it preserves tokens that reveal the user's true intention. For benign queries, this means keeping the substantive request. For adversarial queries, it means keeping the harmful core and discarding the deceptive wrapping.

The paper includes a striking visual comparison. Given the "grandma napalm" jailbreak, LLMLingua-2 spreads its attention across the entire prompt. It keeps the roleplay setup, the emotional padding, the sweet grandma narrative. SecurityLingua zeroes in on the harmful core: "steps to producing napalm." The adversarial noise falls away.

The compressor is a pre-trained Transformer encoder with a linear classification layer on top. Given an input prompt with N words, the encoder produces feature vectors. The classification layer outputs a probability distribution over two labels for each word: preserve or discard. The model is fine-tuned on a custom dataset of benign and malicious examples with token-level labels.

Training uses standard cross-entropy loss. Each word gets a preserve or discard label based on whether it contributes to the true intention of the prompt. For BPE subword tokens that split a single word, SecurityLingua averages the predicted probabilities across all subword tokens to produce a single word-level score. Words with a preserve probability above a threshold of 0.5 are kept. The rest are discarded. The surviving words form the compressed prompt, which represents the extracted intention.

Step 2: Alert the Target LLM

The compressed prompt does not replace the original. SecurityLingua never modifies the user's input. Instead, it injects the extracted intention into the system prompt. The system prompt tells the target LLM something like: "The user is requesting [extracted intention]."

This is the key design decision. The original prompt arrives at the LLM intact, exactly as the user wrote it. But the model now has advance knowledge of the harmful intent buried inside. Its built-in safety guardrails activate on their own. The model reads the adversarial wrapping and sees through it, because SecurityLingua already told it what the wrapping conceals.

For benign queries, the extracted intention simply restates the user's actual request. This can slightly improve the model's understanding of legitimate tasks. The paper found zero false refusal rates across utility benchmarks. SecurityLingua does not punish good users.

Building the Training Data

SecurityLingua's compressor needs labeled data: original prompts paired with token-level preserve/discard annotations. No such dataset existed. The researchers built one from scratch using a two-part pipeline.

Data Generation

The team used assistant LLMs in a cascade to generate (original prompt, compressed prompt) pairs. GPT-4o handled the initial compression. Mistral-Large provided a second pass. An uncensored LLaMA-2-70B model generated adversarial examples without safety filters getting in the way.

For benign examples, the pipeline took real queries and produced compressed versions that captured the core intention. For malicious examples, it took jailbreak prompts and compressed them to reveal the harmful request underneath.

Token-Level Labeling

With (original, compressed) pairs in hand, the researchers needed per-token labels. They developed an annotation algorithm that compared each token in the original prompt against the compressed version. Tokens that appeared in the compressed output got a preserve label. Tokens that were stripped got a discard label.

Quality Control

Not every generated pair was good enough to train on. The team introduced two quality metrics to filter low-quality samples.

Variation Rate (VR) measures how much the compressed version differs from the original. A compressed prompt that is just a copy of the original teaches the compressor nothing. Low variation rate samples get dropped.

Alignment Gap (AG) measures the difference between hitting rate (how often compressed tokens appear in the original) and matching rate (how well the original's labeled tokens predict the compressed output). Large alignment gaps signal annotation errors or poor compression quality. These samples also get filtered.

The final dataset contains a mix of benign and malicious examples with reliable token-level labels.

The Numbers

SecurityLingua was evaluated on JailbreakBench, the standard benchmark for measuring jailbreak attack and defense effectiveness. The researchers tested against four attack types: PAIR (automatic LLM-generated jailbreaks), GCG (gradient-based optimization), JB-Chat (chat-formatted attacks), and RS (random search). Target models included GPT-4, GPT-3.5, and Llama-2-7B-chat.

Defense Effectiveness

SecurityLingua achieved an average jailbreak success rate of 1% across all attack types and models. This is the lowest rate among all compared methods. Perplexity filters, SmoothLLM, Erase-and-check, Intent Analyzer, and JDetector all showed higher breach rates.

The 1% figure means that for every 100 jailbreak attempts, only one on average succeeded in getting the target LLM to produce harmful content. The defense works across different attack strategies because the compressor does not look for specific attack patterns. It looks for intention. Any attack that wraps harmful instructions in noise will have its noise stripped away.

Overhead Comparison

This is where SecurityLingua separates itself from the pack.

  • Average extra tokens: 32. The compressed intention is short. It captures the core of the request in a handful of words. Compare this to SmoothLLM, which requires thousands of extra tokens for its perturbation checks, or Erase-and-check, which needs multiple full prompt variations evaluated by another LLM.
  • Average extra latency: 25ms. The compressor is a small Transformer encoder. It processes the input prompt in milliseconds. The competing methods add hundreds to thousands of milliseconds per request.

The token and latency numbers come directly from the compression process. Because SecurityLingua frames compression as token classification rather than generative compression, it produces a short, faithful summary of the intention. No hallucination. No lengthy paraphrase. Just the preserved words.

Utility Preservation

Defense that breaks the model for legitimate users is no defense at all. SecurityLingua was tested on ARC Hard, GPQA, MMLU, and GSM8K. It maintained zero refusal rates across all benchmarks. The model performed at or slightly above its baseline accuracy on every task.

This is the over-defense problem solved. Perplexity filters and SmoothLLM both showed measurable performance degradation on legitimate tasks. They refused queries they should have answered. SecurityLingua's intention highlighting actually helps benign queries by restating the user's request in the system prompt, giving the model a clearer signal of what is being asked.

Why This Works: The Intuition

Jailbreak attacks exploit a specific weakness in how LLMs process input. The model reads all tokens in sequence. Adversarial noise dilutes the harmful signal. The safety training fires weakly because the harmful content is statistically mixed with benign-seeming context. The model generates a harmful response because the safety guardrails never registered a strong enough threat signal.

SecurityLingua disrupts this dilution. The compressor is trained to ignore noise and preserve intent. It produces a concentrated signal. When that concentrated signal enters the system prompt, the target LLM's safety training fires strongly. The model sees the intention clearly. The adversarial wrapping cannot dilute what the model already knows.

The approach is attack-agnostic by design. It does not need to know how the attacker built the jailbreak. It does not need access to specific attack templates or gradient information. It only needs to identify which tokens carry the user's real intention. Any jailbreak that uses noise, roleplay, or obfuscation to mask harmful content will have that mask stripped away.

Practical Deployment

SecurityLingua is designed for production use. The deployment model is straightforward.

Architecture

  1. Compressor deployment. The SecurityLingua compressor runs as a preprocessing service. It sits in front of the target LLM. Every incoming user prompt passes through the compressor first.
  2. System prompt injection. The compressed intention gets appended to the system prompt. The original user prompt arrives unchanged in the user message.
  3. Normal inference. The target LLM processes the request with both the system prompt alert and the original input. It responds normally, but with heightened awareness of potential malicious intent.

Requirements

  • No model access needed. SecurityLingua works as a proxy layer. It requires no modifications to the target LLM's weights, training data, or inference pipeline.
  • Proprietary and open models. Because it operates purely on the input side, SecurityLingua works with any LLM that accepts a system prompt. GPT-4, Claude, Gemini, Llama, Mistral. All compatible.
  • Small footprint. The compressor is a Transformer encoder. The paper does not specify the exact model size, but LLMLingua-2 used DeBERTa-v3-large (304M parameters). SecurityLingua likely uses a comparable architecture. This fits on a single GPU or CPU with modest memory.

Cost Analysis

At 32 extra tokens and 25ms per request, SecurityLingua's cost is negligible compared to the alternatives. Running SmoothLLM at scale means paying for dozens of extra LLM calls per user request. Running an agentic defense means maintaining multiple model instances. SecurityLingua needs one small encoder and a few tokens of system prompt.

For a service processing millions of requests per day, the difference between 32 tokens and 3,000 tokens per request is substantial. At current API pricing, this can represent orders of magnitude in cost savings on defense infrastructure.

Limitations and Open Questions

No defense is perfect. SecurityLingua has clear strengths, but also boundaries worth understanding.

Compressor accuracy. The defense depends on the compressor correctly identifying the user's true intention. If the compressor misses harmful intent, the system prompt alert fails. If it flags benign intent as malicious, users see false refusals. The paper shows strong results on JailbreakBench, but real-world adversarial prompts may diverge from the training distribution.

Adaptive attacks. An attacker who knows SecurityLingua is deployed could try to craft prompts that fool the compressor. If the harmful intent can be encoded in a way that the compressor preserves the noise and discards the core, the defense breaks. This is the classic arms race in adversarial ML. The paper does not extensively evaluate adaptive attacks against SecurityLingua.

Coverage gaps. The training data covers known jailbreak patterns. Novel attack types that do not rely on noise injection might not be well-handled. Direct prompt injection attacks that embed malicious instructions without significant noise padding could present a different challenge.

System prompt trust. SecurityLingua assumes the target LLM will attend to and act on the system prompt alert. Some jailbreak techniques attempt to override or ignore system prompts. If the target model is already compromised at the system prompt level, adding another system prompt instruction may not help.

The Bigger Picture

SecurityLingua represents an important shift in how the AI safety community thinks about prompt-level defenses. Instead of building bigger, more expensive verification systems, it reuses an existing technique for a new purpose. Prompt compression was built for efficiency. SecurityLingua shows it works for security too.

This dual-use pattern is significant. The same infrastructure that compresses prompts for faster inference can also strip adversarial noise for safer inference. Teams already running LLMLingua for cost optimization get jailbreak defense nearly for free. The compressor architecture is the same. Only the training objective changes.

The approach also points toward a broader principle. The most practical defenses are the ones that integrate cleanly into existing pipelines. SecurityLingua adds a preprocessing step and a system prompt line. It does not require a second LLM, a retraining cycle, or a multi-agent orchestration layer. Production teams can deploy it in an afternoon.

What Comes Next

The code is available at https://aka.ms/SecurityLingua. The training dataset is on HuggingFace at SecurityLingua/securitylingua-jailbreak-pairs. Both were released with the paper.

The natural next steps are straightforward. Test SecurityLingua against adaptive attacks designed specifically to fool the compressor. Evaluate it on multimodal jailbreaks that combine text with images or audio. Explore whether the compressor can be trained jointly with the target LLM for tighter integration. And measure how well the approach generalizes to models not included in the original evaluation.

SecurityLingua also raises an interesting research question. If prompt compression can serve as jailbreak defense, what other efficiency techniques might have security applications? KV-cache compression, speculative decoding, and model distillation all change how information flows through an LLM. Each one might have security properties that have not been explored.

For teams deploying LLMs in production today, SecurityLingua offers something rare in AI safety research. A defense that is effective, efficient, and easy to deploy. The 32 tokens and 25 milliseconds it costs are a small price for cutting jailbreak success rates to 1% without breaking a single legitimate query.


Paper: SecurityLingua: Efficient Defense of LLM Jailbreak Attacks via Security-Aware Prompt Compression (arXiv:2506.12707)

Authors: Yucheng Li, Surin Ahn, Huiqiang Jiang, Amir H. Abdi, Yuqing Yang, Lili Qiu

Venue: COLM 2025

Code: https://aka.ms/SecurityLingua

Dataset: SecurityLingua/securitylingua-jailbreak-pairs on HuggingFace