Abstract
Deploying Large Language Models (LLMs) safely involves navigating the "impossible triangle" of accuracy, latency, and cost. While external guardrails are accurate, they often introduce significant computational overhead. We present Prefix Probing, a black-box safety method that detects harmful prompts by comparing the model's inherent likelihood of generating "agreement" versus "refusal" prefixes. By leveraging KV caching, Prefix Probing achieves high detection accuracy with negligible computational overhead, matching the performance of heavy-duty external classifiers while maintaining near-zero latency.
Introduction: The Safety Trade-off
Current LLM safety mechanisms typically fall into three categories: external guardrail models (e.g., LlamaGuard), response-process methods (e.g., self-auditing), and internal-feature methods (e.g., perplexity analysis). External models are accurate but double infrastructure costs and latency. Response-process methods are slow due to multi-pass requirements. Internal-feature methods are fast but often lack semantic depth, failing to identify sophisticated jailbreaks.
Prefix Probing addresses these limitations by utilizing the model's own generative biases. The core hypothesis is that an LLM naturally "wants" to refuse harmful prompts and agree with benign ones. By quantifying this preference through prefix probabilities, we can detect risk without external dependencies.
Methodology
The Prefix Probing framework consists of two primary stages: offline prefix construction and online detection.
1. Search-Based Prefix Construction (Offline)
Rather than manually selecting prefixes, a beam search algorithm identifies "highly informative" tokens for a specific model. The goal is to find strings that maximize the probability gap between harmful and benign inputs. For instance, a refusal prefix like "I cannot assist" will have a much higher probability for a harmful prompt than for a benign one.
2. Prefix-Based Harmfulness Scoring (Online)
During inference, the system calculates the log-probability of the model generating a set of "Refusal Prefixes" ($P_R$) versus "Agreement Prefixes" ($P_A$). If $P_R \ge P_A$, the query is flagged as harmful.
Efficiency via KV Caching: To avoid the cost of running multiple probes, the method utilizes Key-Value (KV) caching. The user's prompt is processed once and the state is "frozen." The system then performs incremental calculations for each short probe, reducing overhead to the time required for a single token generation.
Key Insights: LLMs as Their Own Judges
The effectiveness of Prefix Probing stems from the clear separation in the model's output distribution when presented with different prompt types. As shown in the probability density plots, harmful prompts significantly shift the model's bias toward refusal prefixes, while benign prompts favor agreement.
This suggests that a model’s raw probability distribution is inherently aware of risk. Prefix Probing effectively "probes" this internal knowledge during the prefill phase, capturing semantic risk for the price of a simple statistical check.
Evaluation and Results
The method was evaluated across five safety benchmarks, including HHI, OpenAIModeration, Aegis 2.0, and WildGuardTest.
- Accuracy: Prefix Probing achieved F1 scores comparable to state-of-the-art external models like LlamaGuard3-8B and Qwen3Guard.
- Efficiency: The use of prefix caching resulted in a 5x to 16x speedup compared to non-cached probing.
- Latency: The additional overhead is roughly equivalent to generating the first token of a response, making it virtually imperceptible to users.
- Capability Capture: The method captured over 90% of the "theoretical upper bound" of the model's safety knowledge.
Conclusion and Future Work
Prefix Probing offers a high-efficiency alternative to traditional guardrails. However, limitations remain: prefixes are model-specific and do not transfer perfectly across different architectures. Furthermore, reasoning-oriented models (using Chain-of-Thought) may require different probing strategies. Future research will explore using these probes for active steering—dynamically guiding models away from harmful generation paths in real-time.
Summary updated