arXiv:2611.02791cs.CLNov 2026

Manuscript Offprint

arXiv:2611.02791

PGuard: A Native, Streaming, and Plug-in Guardrail for Multimodal Large Language Models

Junyu Lin, Mengjie Wu, Yonghao Dong, Yuchuan Fu, Jinfeng Li, Xiaodan Li, Xiaohan Yuan, Yicheng Liu, Yuefeng Chen, Hui Xue, Jingyi Wang, Yitong Yang, Jiyuan Fu, Qinga He

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

As streaming generation becomes the dominant serving paradigm for both text-only and multimodal large language models, ensuring safety throughout the generation process has become a critical challenge. Conventional external guardrails address this challenge at the cost of additional inference overhead and a potential gap between their safety judgments and the backbone model's internal representations. Meanwhile, frontier foundation models possess increasingly sophisticated semantic understanding and rich internal representations, offering an opportunity to build safety capabilities directly into the backbone. Motivated by this, we introduce PGuard, a native, streaming, and plug-in guardrail that transforms safety monitoring from an external serving dependency into an integrated capability of the backbone model. PGuard directly leverages the backbone's intermediate representations for token-level safety detection, without altering its original inference pathway or generation behavior. Specifically, dynamic layer gating selectively aggregates residual-stream representations across layers to extract safety-relevant signals during both prefill and autoregressive decoding. To balance detection accuracy and computational efficiency, PGuard supports multiple representation-modeling architectures, including a lightweight stateless variant and sequence-aware variants built on multi-scale causal EMA-attention and GRU-based recurrent modules. Its design also accounts for the execution characteristics of LLM serving frameworks, such as SGLang, optimizing computation and data access to minimize additional runtime and synchronization overhead. As a result, PGuard incurs only 0.82–2.26% end-to-end overhead on the hundred-billion-parameter backbone Qwen3.5-122B-A10B served by SGLang. Extensive evaluations across more than 30 benchmarks spanning text and multimodal safety, jailbreaks, cyber and CBRN risks, multilingual scenarios, and real-world traffic demonstrate state-of-the-art performance among native guardrails. On text queries with Qwen3.5-9B, PGuard achieves an average F1F_1 score of 0.836, approaching dedicated external guardrails, while supporting deployment-time configuration of category-specific thresholds and enforcement actions.

1 Introduction

Large language models (LLMs) and multimodal large language models (MLLMs) are increasingly deployed in interactive applications, including agentic generation, voice chat, and incremental content rendering. In these settings, model responses are streamed to users as tokens are generated, rather than being presented only after generation is complete, shifting safety moderation from a post-generation task to an online streaming requirement. Specifically, a moderation decision made only after generation completes cannot prevent harmful content that has already been exposed to users. Effective moderation must therefore keep pace with token generation while introducing minimal computational overhead to remain practical at serving scale.

Existing guardrails address this requirement through two broad approaches. External guardrails, such as Qwen3Guard [74], employ separate models to classify user inputs and model responses. Although they can achieve strong detection accuracy, they introduce additional inference costs. More importantly, post-hoc moderation can only identify unsafe content after it has been generated, whereas streaming moderation requires frequent inference by a separate model to detect risks during generation. Furthermore, operating outside the foundation model limits their ability to directly leverage its internal representations. Native guardrails instead exploit signals from the protected model itself. HiddenDetect [25] detects input-side risks before generation, while NExT-Guard [9] monitors internal features at the token level. Despite this progress, existing native approaches remain constrained by the effectiveness of their safety representations and the runtime cost of extracting and processing them. Our evaluations further show that existing native approaches lag behind leading external guardrails in aggregate detection performance while still incurring appreciable serving overhead.

These limitations motivate a more effective way to leverage the backbone's internal representations for native safety modeling. The intermediate representations of a frontier foundation model encode rich semantic and contextual information about the content being generated, providing a natural basis for identifying safety risks without duplicating much of the computation performed by a separate guardrail model. However, effectively translating these representations into safety signals raises two challenges. First, safety-relevant features are not uniformly distributed across layers or token positions, making adaptive layer selection important for effective representation extraction. Second, risks may emerge from relationships among tokens and evolve as a response unfolds, which cannot always be captured by classifying each position independently. Addressing these challenges requires both adaptive representation extraction and effective modeling of dependencies across token positions.

To address these challenges, we present PGuard, a native, streaming, and plug-in guardrail built on a frozen foundation model backbone. PGuard introduces dynamic layer gating to adaptively select and aggregate residual-stream representations at each token position, enabling the guardrail to capture safety-relevant features across different layers. Based on these representations, PGuard supports two complementary modeling paradigms. The stateless variant classifies each token position independently, while the sequence variants explicitly model dependencies across positions to capture how risks emerge and evolve during generation. We instantiate sequence modeling with multi-scale causal EMA-attention and GRU-based recurrent modules, offering different trade-offs between detection quality and computational cost. To enable localized safety supervision without requiring exhaustive token-level annotations, PGuard adopts segment-level supervision, computing loss only at annotated positions and for tasks with available labels. Our experiments show that sequence modeling improves response-level detection over the stateless variant across both text and multimodal tasks.

Beyond detection efficacy, deploying native guardrails efficiently requires coordinating safety computation with the backbone's generation process. Mainstream language model inference and serving engines (e.g., vLLM [29] and SGLang [76]) coordinate batching, parallel execution, and GPU synchronization to sustain high throughput. Accessing intermediate representations and reporting risk scores introduces additional dependencies into this execution process. In particular, poorly placed synchronization can stall active batches, making the resulting overhead substantially greater than the guard computation itself. PGuard therefore incorporates serving-engine constraints into its execution design. We integrate PGuard with SGLang, aligning risk computation and reporting with the engine's scheduling mechanisms. The integration supports both stateless and sequence variants without modifying the SGLang codebase. Beyond SGLang, we are currently working on a vLLM integration to extend the same serving-aware execution design to another widely used inference and serving engine.

We evaluate PGuard on more than 30 benchmarks covering text and multimodal safety, jailbreaks, cyber and CBRN risks, multilingual scenarios, and real-world traffic. On text-query benchmarks with Qwen3.5-9B, PGuard achieves an average F1F_1 score of 0.836, approaching that of Qwen3Guard. On multimodal query benchmarks with Qwen3.5-9B, it achieves an average F1F_1 score of 0.741, compared with 0.638 for HiddenDetect and 0.474 for Llama Guard 4. On the 100B-scale Qwen3.5-122B-A10B backbone, end-to-end latency overhead remains below 1.3% for stateless and 2.4% for sequence variants. These results demonstrate that native guardrails can achieve competitive detection quality while imposing limited overhead on large-scale model serving.

Our main contributions are:

We propose PGuard, a native streaming guardrail that leverages dynamic layer gating to extract token-wise safety representations from a frozen backbone. We further introduce complementary stateless and sequence-based modeling architectures to support both independent token classification and sequential risk modeling.

  • We develop a serving-aware execution strategy that coordinates safety computation with the scheduling and execution mechanisms of model inference engines. Our SGLang integration supports both modeling variants while minimizing redundant computation and synchronization overhead, without modifying the inference engine's codebase.

  • We conduct extensive evaluations across more than 30 text and multimodal safety benchmarks and real-world traffic. Our analysis demonstrates the benefits of sequence modeling, characterizes the trade-offs between detection quality and serving overhead, and examines the complementary roles of native screening and external adjudication.

Figure

Figure 1: Overview of PGuard. (a) PGuard extracts intermediate representations from selected layers of a frozen backbone during prefill and decode. (b) Dynamic layer gating combines layer features for stateless, EMA-attention, or GRU modeling, and task-specific classifiers produce risk scores. Serving co-design integrates selective computation, parallelism, non-blocking execution, and fusion (Section 3). (c) Per-token risk scores are returned through engine metadata, and the application applies its policy when a score crosses the threshold.

References (72)