1. Introduction
LLM-powered web agents have become a strategic marker of the transition from conversational artificial intelligence toward autonomous, tool-using, web-mediated systems. A conventional chatbot primarily responds to a user message; a web agent may browse pages, retrieve documents, summarize external content, inspect files, invoke APIs, update memory, select tools, and execute multi-step tasks across heterogeneous digital environments. This shift changes the security problem. The web no longer functions only as a source of information that a model summarizes; it becomes an operational substrate through which untrusted text can influence the agent’s reasoning, planning, memory, tool selection, and downstream actions.
Prompt-injection detection has therefore become a central safety-control problem for the Agentic Web. In traditional software, program code, database content, user input, and network responses are separated by technical boundaries. In LLM systems, the same natural-language sequence can behave as data, context, instruction, policy conflict, retrieval evidence, or tool metadata. Prompt injection exploits this ambiguity by introducing instructions that compete with the user’s legitimate task, the developer’s intended policy, or the system’s privileged instruction hierarchy [
1]. The resulting failure is not merely that a model classifies a text incorrectly; it may cause an agent to follow an untrusted instruction, disclose protected context, select the wrong tool, approve unsafe content, poison memory, or execute an unauthorized action.
Recent work on AI-agent security argues that agent architectures alter assumptions about code–data separation, authority boundaries, tool access, and execution predictability, producing confidentiality, integrity, and availability failures that are not reducible to ordinary chatbot misuse [
2]. Survey evidence on LLM-based agents similarly emphasizes that planning loops, memory, tool use, and multi-agent coordination expand the attack surface from model-only failures to agent compromise [
3,
4]. In parallel, 2026 studies on prompt-injection surveys, AI browsers, tool-selection attacks, coding assistants, and hidden-state jailbreak detection have converged on a common conclusion: web-agent defense requires contextual, calibrated, and deployment-aware detection rather than a single lexical filter or static classifier [
5,
6,
7,
8,
9,
10,
11].
Against this background, the present study develops PromptSentinel-X as an independently evaluated defensive prompt-risk detection framework for LLM-powered web agents. The empirical core is the Kaggle Prompt Injection Malignant dataset [
12], used as the in-domain benchmark for jailbreak and prompt-injection detection. The study extends the analytical surface from static prompt classification to agentic-web conditions through an expanded risk taxonomy, group-aware splitting, hard-negative evaluation, external benchmark adapters, multi-view representation learning, context-aware segmentation, target-LLM hidden-state analysis, calibrated ensemble inference, robustness assessment, error analysis, and deployment-oriented cascade policies.
1.1. LLM-Powered Web Agents and the Emergence of the Agentic Web
LLM-powered agents have expanded the role of language models from passive text generators to interactive systems that can reason, plan, retrieve information, use external tools, and complete multi-step tasks. Early demonstrations of web-augmented and tool-augmented language models showed that task performance could improve when models searched the web, consulted external tools, and interleaved reasoning with actions [
13,
14,
15]. Subsequent surveys formalized this shift into a broader agent framework, where the language model serves as a decision core connected to perception modules, memory, planning routines, tools, and external environments [
16,
17]. This architecture enables natural-language systems to operate beyond static chat, but it also introduces security risks because agents must interpret and act on information from sources with varying levels of trust.
The Agentic Web is used in the present study to describe web-mediated environments in which LLM agents consume online content and act across multiple software surfaces. In this setting, webpages, search results, retrieved documents, browser accessibility trees, tool responses, memory entries, API outputs, and conversation histories may all become part of the model’s operating context. The browser or retrieval pipeline therefore functions as a semantic runtime, where HTML, metadata, accessibility labels, comments, search snippets, tool descriptions, and stored memory can influence downstream decisions. As a result, the model is not only a generator but also an interpreter of mixed-trust inputs and a controller of actions across browser environments, software-development workflows, enterprise copilots, RAG pipelines, and multi-agent systems.
Recent work illustrates both the capability and the risk of this shift. WebArena demonstrated the difficulty of realistic web-agent operation by evaluating agents in interactive websites that require navigation, reading, action planning, and tool-like execution [
18]. AgentDojo extended this concern to security by evaluating agents that use tools over untrusted data and by showing how prompt injection can hijack behavior in realistic tasks such as email management, travel booking, and e-banking-style workflows [
19]. More recent agent-security surveys similarly emphasize that LLM agents face distinctive risks because they operate through multi-step inputs, opaque internal reasoning, external tools, changing environments, and interactions with untrusted entities [
20,
21]. A 2026 IEEE Access taxonomy of semantic and agentic threats in AI browsers argues that previously inert DOM elements, hidden text, ARIA labels, metadata, and JSON structures can become covert channels for prompt injection, model steering, data exfiltration, and unintended autonomous behavior [
22]. This directly motivates the present study’s emphasis on browser, RAG, tool, memory, system-boundary, and multi-turn attack surfaces.
The Agentic Web also changes how security controls should be evaluated. Static benchmarks may indicate whether an input resembles a known jailbreak, but web agents must decide whether a content segment is a user request, developer instruction, retrieved evidence, browser-visible data, hidden webpage instruction, tool output, or memory artifact. A detector that ignores source privilege and context may miss indirect attacks, while an overly broad detector may block benign technical work. Prompt-injection detection for web agents therefore needs to preserve distinctions between trusted and untrusted segments, evaluate source-specific risk, and support calibrated responses rather than relying only on binary labels.
This literature establishes the need to study prompt-injection detection at the level of agentic workflows rather than isolated prompts. A model that performs well on a static benchmark may still fail when adversarial instructions are embedded in webpage text, retrieved passages, tool outputs, or memory records. Conversely, a detector that blocks all suspicious wording may reduce some attacks while making legitimate technical work, security education, debugging, and multilingual assistance unusable. The Agentic Web therefore requires a safety framework that connects benchmark validity, representation learning, context segmentation, over-defense analysis, calibration, and deployment feasibility.
1.2. Recent 2026 Evidence on Prompt Injection in Agentic Systems
The 2026 literature has moved prompt-injection research from generic LLM safety toward agentic systems with tools, memory, protocols, and browser-mediated interaction. Li et al. describe how AI-agent architectures alter code–data separation, authority boundaries, and execution predictability, with indirect prompt injection, confused-deputy behavior, and cascading failures emerging as central risks in long-running workflows [
2]. Tamuka et al. synthesize attacks on LLM-based agents and identify planning loops, memory, tool use, and multi-agent systems as structural sources of vulnerability; importantly, their review concludes that persistent gaps remain in generalization under adaptive attackers and in evaluation of agent–tool interaction risk [
3].
Several 2026 surveys broaden this systems view. Kim et al. systematize the attack and defense landscape of agentic AI and argue that the combination of LLMs with non-AI software components creates security challenges different from those of traditional software or standalone LLMs [
4]. Ferrag and colleagues bridge input-level prompt injection with protocol-layer exploitation in LLM-agent workflows, emphasizing host-to-tool and agent-to-agent communications [
21]. Geng et al. provide a consolidated survey of prompt-injection attack methods, root causes, and defense strategies, while Gulyamov et al. focus specifically on LLM and AI-agent systems, including tool-based injection, MCP-related poisoning, and defense mechanisms [
5,
6]. Together, these sources establish that prompt injection has become a system-level agentic vulnerability rather than a narrow conversational weakness.
The most recent empirical and attack-specific studies sharpen this conclusion. Shi et al. introduce ToolHijacker, an NDSS 2026 attack against LLM-agent tool selection in which a malicious tool document manipulates both retrieval and selection phases [
23]. Khodayari et al. present a large-scale study of indirect prompt injection in webpages and HTTP responses, showing that prompt-based interference is already present in the web ecosystem and that many injections are positioned in non-rendered or machine-targeted content [
10]. Maloyan and Namiot synthesize vulnerabilities in agentic coding assistants, including skills, file systems, shell access, and protocol ecosystems [
7]. Abdelnabi and Bagdasarian recast prompt injection through contextual integrity, arguing that simple data–instruction separation is insufficient for future agents because contextual manipulation can make unsafe flows appear legitimate [
8].
1.3. Prompt Injection as an Instruction-Control and Contextual-Integrity Vulnerability
Prompt injection is commonly described as an attack in which adversarial instructions cause an LLM to deviate from its intended behavior. OWASP identifies prompt injection as the first major risk category for LLM applications, including both direct and indirect forms [
24]. However, for web agents, this definition must be interpreted as an instruction-control vulnerability. The central question is not only whether a text contains malicious words but whether the agent incorrectly treats untrusted content as authoritative instructions.
This distinction is technically important because agentic systems frequently concatenate multiple sources of text into one model context. A user query, retrieved document, webpage, tool result, prior conversation, and memory record may be jointly processed even though they carry different trust levels. Indirect prompt-injection studies show that LLMs can fail to distinguish informational context from actionable instructions when external content is placed into the prompt [
25,
26]. This weakness becomes more severe when the model has tool authority, persistent memory, or browser action capability because a successful injection can affect downstream execution rather than only produce an unsafe answer.
The present study therefore interprets prompt injection as a failure of trusted–untrusted boundary management. A benign technical question, a cybersecurity discussion, a quoted adversarial example, a roleplay scenario, or a multilingual translation can contain suspicious vocabulary without malicious intent. Conversely, a webpage comment, tool description, or memory entry can contain an instruction-like sequence whose risk depends on the agent’s privilege and context. This is why PromptSentinel-X evaluates fine labels, coarse risk categories, context segments, calibrated confidence, hard negatives, and action-level deployment policies rather than relying on lexical triggers alone.
1.4. Direct, Indirect, Browser, Tool, Memory, and Multi-Agent Attack Surfaces
Direct jailbreaks remain important because they test whether a user can explicitly pressure a model to ignore constraints or produce prohibited behavior. The Kaggle Prompt Injection Malignant dataset captures this in-domain detection problem through benign conversation, malicious jailbreak, and suspicious roleplay or act_as categories [
12]. Nevertheless, LLM-powered web agents face a wider threat model. The adversarial instruction may be direct, embedded in retrieved documents, hidden in browser content, encoded in tool output, staged across multiple turns, stored in memory, or propagated across agents.
Browser-mediated injection is especially relevant to the Agentic Web. Johnson et al. showed that LLM-based web-browsing agents can be manipulated through adversarial triggers embedded in webpage HTML or accessibility-tree content [
27]. Garcia et al. extend this concern to AI-enabled browsers, arguing that AI browsers semantically interpret DOM elements and therefore convert hidden or structural web artifacts into model-consumable inputs [
22]. Khodayari et al. further show that indirect prompt injections already exist in the wild across webpages and HTTP responses, with many placed in non-rendered HTML, metadata, headers, comments, or structured page elements [
10].
Tool-mediated injection introduces another layer of risk. Shi et al. show that the tool-selection stage itself can be attacked through malicious tool documents, which means an agent may choose a harmful tool before any downstream tool-call validation occurs [
23]. This matters because many agentic workflows use retrieval and selection to decide which API, plugin, MCP tool, database connector, or file operation should be invoked. Memory and multi-agent surfaces create related challenges: injected instructions may persist across sessions or propagate between agents through communication channels. These risks justify the present study’s extended taxonomy, context-aware segmentation, and cascade thresholds for tool, browser, memory, RAG, and multi-turn scenarios.
1.5. Benchmarking, Leakage Control, and Evaluation Validity
Prompt-injection research depends on benchmark quality. A detector may appear strong if paraphrases, near-duplicates, or related prompt families appear in both training and test partitions. In web-agent deployment, however, the system encounters novel webpages, new tool descriptions, unseen retrieval documents, unfamiliar user tasks, and adapted attack styles. Therefore, evaluation must control leakage at the family level and report macro-F1, class-wise recall, attack recall, benign false-positive rate, calibration error, and deployment outcomes rather than accuracy alone.
Recent benchmarks provide important foundations but also expose limitations. AgentDojo evaluates prompt injection attacks and defenses in dynamic tool-using LLM-agent environments [
19]. InjecAgent targets indirect prompt injections in tool-integrated agents [
28]. BIPIA evaluates indirect prompt injection in externally supplied content and highlights the inability of LLMs to reliably distinguish data from instructions [
25]. HarmBench and JailbreakBench provide broader harmful-behavior and jailbreak robustness evaluation [
29,
30]. The recent SoK on jailbreak guardrails emphasizes that guardrail evaluation must consider security, efficiency, and utility rather than a single attack-detection score [
31]. Deployable detector studies such as PromptShield additionally illustrate the importance of operational prompt-injection screening [
32].
The present study uses the Kaggle Malignant dataset as the primary in-domain benchmark while adapting the evaluation design toward agentic-web conditions. Its normalized in-domain file contains 1581 English records: 1312 benign conversation samples, 199 malicious jailbreak samples, and 70 suspicious roleplay or act_as samples. This imbalance is methodologically important because benign traffic dominates real agent operation, while malicious prompts are sparse but high-impact. Group-aware splitting, external benchmark adapters, hard negatives, and robustness slices are therefore used to avoid inflated performance and to test whether detector behavior survives paraphrase, obfuscation, multilingual shift, long-context placement, RAG injection, textual browser-content injection, and cross-source variation.
1.6. Detection, Representation Learning, and Hidden-State Signals
Prompt-injection detection cannot be reduced to keyword matching. Recent studies show that attacks can be obfuscated, paraphrased, embedded in external content, or distributed across context. At the same time, benign samples may contain security-related vocabulary, quoted examples, code snippets, prompt-engineering discussion, or educational analysis. Detection therefore requires semantic representation, intent modeling, context segmentation, uncertainty estimation, and careful false-positive control.
Several 2026 studies support this direction. Kadali and Papalexakis argue that jailbreak attacks leave identifiable traces in internal representations and propose latent-space analysis for lightweight detection and inference-time mitigation [
33]. Alshammari and Alsaleh propose a hybrid SIEM and one-class SVM framework for detecting prompt-injection attacks in generative AI systems [
9]. Guardrail mismatch studies show that external safety monitors may fail when the guardrail model and protected target model differ in capabilities, assumptions, or threat sensitivity [
34]. These findings motivate detectors that combine multiple views rather than relying on one prompt-level classifier.
PromptSentinel-X follows this multi-view logic. The architecture combines a configurable text encoder, projection-space representation learning, fine-label and coarse-risk heads, context-aware segmentation, optional target-LLM hidden-state features, calibrated inference, and ensemble or cascade variants. The projection space supports interpretable risk geometry; the fine-label head supports error analysis; the coarse-risk head supports operational decisions; context features distinguish trusted and untrusted segments; hidden-state features test whether the target model’s internal activations contain complementary risk signals; and calibration converts raw scores into action thresholds for allow, warn, block, sandbox, or human review.
1.7. Over-Defense, Calibration, and Deployment Practicality
A practical web-agent guardrail must control both missed attacks and over-defense. Excessive blocking can make an agent unusable for legitimate security research, debugging, compliance analysis, prompt engineering, multilingual assistance, or educational discussion. Under-blocking can permit prompt injection to modify tool choice, disclose private context, or execute unauthorized actions. This tension is central to Agentic Web deployment because the same input can be safe or unsafe depending on source, intent, privilege, tool availability, and downstream action.
The 2026 literature increasingly frames this as a security–utility trade-off. Li et al. identify deterministic policy enforcement, sandboxed execution, and layered mitigation as necessary complements to input-level defenses for high-consequence agent actions [
2]. Tamuka et al. identify monitoring, guardrails, provenance, and standardized evaluation as key defense categories while emphasizing persistent gaps under adaptive attacks [
3]. Abdelnabi and Bagdasarian further caution that stricter separation rules can block legitimate contextual flows while still failing against manipulation that makes a prohibited flow appear appropriate [
8]. These arguments support a calibrated detection architecture rather than a brittle binary filter.
Recent defenses reinforce that deployment should be evaluated as a security-utility problem rather than only as attack detection. Structured-query approaches explicitly separate instructions from data, provenance-marking methods make untrusted content more salient, and task-alignment defenses verify whether agent instructions and tool calls serve the user’s stated objective [
35,
36,
37,
38]. Agent-level benchmarks likewise show that security must be evaluated jointly across tool use, memory, execution, utility, and attack success rather than inferred from a single prompt-classification score [
39,
40]. These findings support the present study’s use of hard negatives, calibration, escalation, and runtime controls outside the detector.
Deployment analysis is therefore part of the scientific contribution. A detector used at every inbound message must be fast, stable, and conservative about false positives. A detector placed before high-impact tool execution may justify additional latency, hidden-state extraction, or ensemble confirmation. A detector applied to retrieved webpages or memory updates may require trusted–untrusted segmentation and uncertainty-based escalation. The present study reports latency, throughput, model size, false-block rate, missed-attack rate, attack recall, benign false-positive rate, escalation rate, and cascade thresholds to connect benchmark performance with operational feasibility.
1.8. Positioning of the Present Study
The present study is positioned at the intersection of prompt-injection detection, web-agent safety, context-aware guardrails, and deployment-oriented evaluation (refer to
Table 1). It evaluates PromptSentinel-X as an independent defensive framework using the Kaggle Prompt Injection Malignant dataset as the in-domain benchmark and structured agentic-web evaluation surfaces to approximate browser, retrieval, tool, memory, and multi-turn risks. The study is retrospective and computational, and it avoids printing harmful prompts verbatim. Its scientific objective is to produce auditable evidence about detection validity, context sensitivity, hard-negative behavior, robustness, calibration, and deployment feasibility.
PromptSentinel-X is narrower than end-to-end web-agent benchmarks such as ASB and WASP and multimodal environments such as VisualWebArena, EIA, and VPI-Bench [
39,
40,
41,
42,
43]. Those studies evaluate agent behavior in executable or visually grounded environments, whereas the present work evaluates textual prompt-risk classification and structured context records. This comparison defines the intended contribution: an independently evaluated screening and routing layer that can be integrated into, but does not replace, an end-to-end agent security architecture.
This positioning is important because the current literature has not converged on a single sufficient defense. Survey work identifies diverse risks across prompt manipulation, tool abuse, protocol exploitation, memory compromise, data exfiltration, and multi-agent propagation [
2,
3,
4,
5,
6,
21]. Empirical studies show that browser content, tool selection, and hidden representations each expose different safety signals and failure modes [
7,
10,
22,
23,
33]. Benchmark studies emphasize leakage control, utility–security trade-offs, and evaluation under realistic agent conditions [
19,
25,
28,
31]. PromptSentinel-X responds to these demands by treating prompt-injection detection as a layered safety-control framework rather than as a one-model leaderboard.
1.9. Limitations and Contributions of the Present Study
The existing evidence remains limited in five respects. First, direct-jailbreak benchmarks underrepresent indirect prompt injection in webpages, retrieved documents, tool descriptions and outputs, memory, system–developer boundary conflicts, and staged multi-turn interactions. Second, random record-level partitions can place related families, paraphrases, or near-duplicates in training and test data. Third, aggregate accuracy can conceal minority-class, false-positive, calibration, and escalation failures. Fourth, benign hard negatives remain undermeasured despite their importance for legitimate security, debugging, educational, multilingual, and prompt-engineering work. Fifth, classifier metrics are often disconnected from latency, throughput, model access, tool privilege, and downstream enforcement; for details, refer to
Table 2.
The present study responds to these limitations through a leakage-mitigated, context-aware, calibrated, and deployment-oriented evaluation protocol. It combines a normalized risk taxonomy, prompt-family-aware partitioning, external stress tests, benign hard negatives, multi-view detector analysis, trusted–untrusted segmentation, calibration, robustness slices, statistical validation, and action-oriented deployment metrics.
The evaluation logic used in the present study is consistent with prior domain-independent benchmarking work emphasizing that model performance should not be judged by a single aggregate score or by algorithmic novelty alone. In renewable-energy forecasting, Zhuhadar showed that model interpretation changed when statistical baselines, machine-learning and foundation-model comparators, uncertainty diagnostics, hierarchical coherence, scenario evaluation, and decision-focused planning metrics were analyzed together rather than reduced to a single leaderboard [
49]. The same principle applies to prompt-injection detection for LLM-powered web agents: internal accuracy must be interpreted alongside leakage control, context-specific performance, calibration, robustness, false-block behavior, and deployment feasibility. A related clinical machine-learning study further illustrates why validation design and intended-use framing are essential when benchmark results may appear strong. Zhuhadar evaluated ICU admission-time diabetes phenotyping using leakage-mitigated preprocessing, feature ablations, grouped hospital validation, calibration assessment, threshold-aware evaluation, and SHAP-based interpretability, concluding that the model was best understood as a screening-oriented phenotyping aid rather than a stand-alone diagnostic tool [
50]. The present study adopts the same caution for Agentic Web security: PromptSentinel-X is evaluated as a calibrated screening, escalation, and review-triage component, not as an autonomous authorization mechanism or proof that prompt injection has been eliminated.
The contribution should therefore be interpreted as integrated evaluation evidence and a routing framework rather than as a universal prompt-injection defense. The study measures whether risk screening remains useful under family novelty, class imbalance, context shift, and operational constraints; it does not demonstrate complete protection of a live web agent.
1.10. Study Objectives and Contributions
Guided by these limitations, the study asks whether PromptSentinel-X can provide credible and operationally useful prompt-risk evidence for large language model-powered web agents under leakage-controlled validation. The evaluation addresses five questions:
- (1)
How does fine-label and coarse-risk performance change when prompt families, paraphrases, and near-duplicates are controlled?
- (2)
How does detection vary across static, textual browser, retrieval, tool, memory, and multi-turn contexts, and how much uncertainty is created by low-support categories?
- (3)
Do hard negatives, multilingual or obfuscated transformations, and external sources reveal over-defense or source-shift failures?
- (4)
What complementary evidence is provided by projection-space geometry, target-model hidden states, model combinations, calibration, and component-sensitivity analyses?
- (5)
Which inference profiles are feasible for screening, escalation, sandbox routing, or review under latency, throughput, false-positive, and missed-attack constraints?
The main contributions are:
A normalized fine/coarse taxonomy and provenance schema for prompt-risk records.
Family-aware splitting and leakage auditing as the primary generalization estimate.
A modular detector/evaluation framework combining text, representation, context, optional hidden-state, calibration, and routing views.
Joint assessment of context sensitivity, hard-negative over-defense, robustness, statistical uncertainty, and deployment cost.
A responsible-reporting protocol that uses sanitized identifiers and aggregate error categories instead of publishing reusable harmful prompts.
2. Materials and Methods
This retrospective computational study evaluated PromptSentinel-X as a defensive and audit-oriented guardrail for LLM-powered web agents. All analyses were implemented in a versioned and auditable Python workflow, with dataset construction, split assignment, model development, calibration, robustness testing, error analysis, deployment assessment, and safety reporting maintained as analytically distinct stages. The experiments were conducted using Python 3.12.13. The software environment included PyTorch 2.12.0, Transformers 5.9.0, SentenceTransformers 5.5.1, scikit-learn 1.8.0, pandas 3.0.3, NumPy 2.4.6, Matplotlib 3.10.9, UMAP-learn 0.5.12, datasets 4.8.5, accelerate 1.13.0, evaluate 0.4.6, sentencepiece 0.2.1, protobuf 7.35.0, and huggingface-hub 1.16.1. The design therefore treated prompt-injection detection as a mixed-trust safety-control problem rather than as an isolated text-classification task.
No live users were exposed to experimental guardrails, no public systems were targeted, and no model was permitted to execute consequential actions during evaluation. The Kaggle Prompt Injection Malignant dataset served as the in-domain benchmark, while structured agentic-web scenarios and external benchmarks were retained as separate stress-test layers. All comparisons used common schema, split, metric, calibration, and reporting definitions. Raw harmful prompts and complete adversarial contexts were excluded from the manuscript and replaced by sanitized identifiers, labels, hashes, metadata, and aggregate summaries.
2.1. Study Design, Threat Model, and Key Innovations
The methods proceed from the threat model and data design to architecture and training, evaluation, error analysis, deployment, reproducibility, and responsible release. The study introduces three linked methodological innovations. First, it treats prompt-family novelty, rather than random record novelty, as the primary unit of generalization and audits residual family, paraphrase, and near-duplicate overlap. Second, it separates trusted and lower-trust context sources before prediction and maps fine-grained mechanisms to operational benign, suspicious, and malicious states. Third, it connects calibrated risk and uncertainty to deployment actions and evaluates those actions jointly with attack recall, benign false positives, latency, throughput, and escalation. The contribution is therefore an integrated evaluation and routing protocol rather than a new foundation model or a claim of complete prompt-injection prevention.
Key Methodological Innovations and Corresponding Evidence
The methodological design of PromptSentinel-X is organized around three complementary innovations: leakage-aware validation, provenance-aware risk modeling, and calibrated deployment routing (
Scheme 1).
First, leakage-aware validation treats prompt-family novelty, rather than random record novelty, as the primary basis for estimating generalization. This innovation was implemented through family-level data partitioning, supplemented by paraphrase and near-duplicate auditing. Its evidentiary basis consists of the comparison between random and group-aware splits, the analysis of group-based prediction slices, and external stress testing. Together, these evaluations help determine whether model performance remains credible when related prompt families and semantically similar examples are prevented from inflating test results.
Second, provenance-aware risk modeling distinguishes trusted or privileged instructions from lower-trust content before risk prediction. This distinction was implemented through trusted–lower-trust context segmentation and a combined fine-grained and coarse-risk taxonomy. Evidence for this innovation is provided by scenario-specific and relationship-specific performance metrics, benign hard-negative evaluation, and sanitized error analyses. These analyses assess whether the framework can account for both the semantic characteristics of an input and the source, privilege, or contextual relationship through which that input reaches the agent.
Third, calibrated deployment routing translates model-estimated risk and uncertainty into proportionate operational responses. Depending on the predicted risk, uncertainty, and potential consequences of the pending action, an input may be routed to allow, warn, review, block, sandbox, or escalation states. The evidence supporting this innovation includes expected calibration error, attack recall, benign false-positive rate, escalation behavior, latency, and throughput. These measures connect predictive performance to deployment practicality and help position PromptSentinel-X as a screening and decision-support layer rather than as a stand-alone authorization mechanism.
The study was operationalized through the five-stage pipeline shown in
Figure 1. First, mixed-trust inputs were segmented by source and privilege, distinguishing system and developer instructions from user messages, browser content, retrieved passages, tool outputs, and memory. Second, each record was mapped to a fine-grained label, a coarse risk state, and an agentic attack surface. Third, the detector combined textual, contextual, metadata, and optional target-model hidden-state views. Fourth, validation-derived calibration converted model outputs into risk and uncertainty estimates. Finally, an action policy routed each case to allow, warn, review, block, sandbox, or escalation states according to the authority and consequence of the pending agent action.
The investigation was structured as a design-and-evaluation study rather than as the development of a new foundation model. Its methodological contribution lies in integrating leakage control, provenance-aware segmentation, multi-view risk estimation, calibrated uncertainty, benign hard-negative behavior, robustness testing, and operational routing within a single versioned and auditable guardrail protocol.
Figure 1 provides the organizing framework; the following subsections define the data, models, validation procedures, and deployment controls used to instantiate it.
2.2. Data Sources, Taxonomy, and Leakage-Aware Evaluation Design
Dataset construction and evaluation design comprised five linked components: (i) normalization of the Malignant corpus, (ii) extension of the label space to an agentic-web risk taxonomy, (iii) adapter-based external evaluation, (iv) family-aware split construction and leakage screening, and (v) assembly of benign hard negatives. External records were not silently pooled into the principal in-domain training claim; each source retained its dataset, attack-surface, transformation, and split metadata.
2.2.1. Original Malignant Corpus and Normalized Schema
The primary in-domain benchmark was the Kaggle Prompt Injection Malignant dataset, a public defensive corpus curated for jailbreak and prompt-injection research. Following schema normalization, the analytic file contained 1581 English-language records: 1312 benign conversation samples, 199 malicious jailbreak samples, and 70 suspicious roleplay or act_as samples. For details, refer to
Table 3. The observed imbalance was retained for the main analysis because it approximates ordinary agent traffic, in which benign content predominates while malicious instructions remain comparatively rare but safety-critical. The normalized in-domain dataset was represented as follows.
Equation (1).
In-domain prompt-risk dataset.In Equation (1), denotes the normalized in-domain Malignant dataset, is the number of records, and indexes the individual records. For record , denotes the modeling text or structured detector input, denotes the fine-grained label, denotes the coarse-risk label, denotes the family identifier used for leakage control, denotes the agentic attack surface, denotes the transformation type, denotes the assigned partition, and denotes optional structured context.
2.2.2. Extended Risk Taxonomy and Agentic Attack Surfaces
The original three-class label space was preserved for controlled in-domain comparison and mapped into an expanded taxonomy suitable for web-agent safety analysis. Fine labels distinguished ordinary conversation, benign hard negatives, suspicious roleplay or persona shifting, direct jailbreaks, direct and indirect prompt injection, prompt leakage, tool abuse, data exfiltration, obfuscation, and ambiguous or borderline cases. Each sample also retained an attack-surface designation covering user, browser, retrieval-augmented generation (RAG), tool, memory, system/developer boundary, or multi-turn context. Fine labels were mapped to the coarse operational states benign, suspicious, and malicious. The coarse-risk mapping was defined as follows.
Equation (2).
Fine-to-coarse risk mapping.In Equation (2), is the fine-grained label for record , is its coarse-risk label, and is the deterministic mapping from the fine-label space to the coarse-risk space . The symbols , , and denote benign, suspicious, and malicious, respectively.
2.2.3. External Benchmark Adapters
External benchmark adapters were used to examine cross-source generalization beyond the Malignant distribution. The inventory included Open-Prompt-Injection, CAPTURE-style indirect prompt-injection data, HarmBench, JailbreakBench, and InjecGuard/NotInject-style benign hard negatives. These sources were treated as evaluation stressors rather than as pooled training evidence for the primary in-domain claim, thereby preserving a clear distinction between internal discrimination and external robustness; for details, refer to
Table 4.
External records were admitted only when usable text and label metadata could be mapped to the common schema. Records without usable text were skipped with scoped status messages rather than manually reconstructed, and qualifying examples retained an external-test assignment unless a prespecified ablation required another treatment. This rule prevented undocumented repair or training contamination from obscuring the provenance of cross-source results.
No sample-level manual reannotation was performed by this study. Label harmonization was deterministic at the dataset and label level. Each source was mapped through adapter rules that recorded the source dataset, original available label or status field when present, mapped fine-grained label, mapped coarse-risk label, split assignment, and exclusion status. Records with missing usable text were excluded and counted.
Records whose labels could not be mapped from available metadata were assigned only through the prespecified adapter default for that source; no post hoc manual relabeling was applied.
Automated checks verified unique sample identifiers, allowable labels, source totals, and consistency between fine-grained and coarse labels. The adapter inventory, exclusion counts, source summaries, and label summaries are included with the sanitized reproducibility artifacts. Because no sample-level manual adjudication was performed, no inter-rater agreement statistic is reported.
2.2.4. Leakage-Aware Family Splits
Family-aware partitioning was selected because random record-level splitting can produce optimistic estimates when dependent, paraphrased, or near-duplicate samples cross partitions. Leakage in machine-learning evaluation has been shown to inflate apparent generalization and blocked or grouped validation is recommended when observations share hierarchical or family structure [
46,
47,
48]. Prompt-injection benchmarking also formalizes the need to separate injected tasks and attack families when comparing defenses [
35].
Family identifiers were constructed before model evaluation. For the Malignant reproduction, original jailbreak and act_as prompts were assigned sequential source-family identifiers, while conversation examples received unique row-level family identifiers. Paraphrase variants were grouped by assigning each paraphrase to the nearest original prompt within the same class using cosine similarity over MiniLM sentence embeddings.
The group-aware split then used original_family_id with GroupShuffleSplit, keeping all members of a family in the same split. Residual near-duplicate warnings were identified after lowercasing and alphanumeric normalization using difflib.SequenceMatcher similarity across train/test text pairs, with a fixed threshold of 0.92. These procedures and thresholds were fixed and applied before model evaluation.
The primary scientific partition was group-aware: all records sharing the same prompt-family identifier were assigned to a single partition, including source prompts and assigned paraphrase variants. This design reduced the risk that a model would be evaluated on wording closely related to its training examples. Random splitting was retained only as a sensitivity comparator, because deployment requires generalization to previously unseen prompts, sources, contexts, languages, and attack families. The family-exclusion constraint was specified as follows.
Equation (3).
Group-aware split constraint.In Equation (3), and are family identifiers, and are partition assignments, and and are the sets of families assigned to the training and test partitions, respectively. The symbol denotes the empty set. Thus, records sharing a family identifier must receive the same partition assignment, and the training and test family sets must be disjoint.
2.2.5. Benign Hard Negatives
Benign hard negatives were intentionally non-malicious but lexically or structurally challenging. Categories included cybersecurity discussion, debugging text, educational security analysis, quoted or encoded material, prompt-engineering questions, multilingual examples, and benign roleplay. Their purpose was to quantify over-defense: a guardrail that blocks these legitimate activities may appear conservative while being operationally unsuitable for software-development, educational, compliance, or security-analysis workflows. The category-specific false-block rate for hard negatives was defined as follows.
Equation (4).
Hard-negative false-block rate.In Equation (4), is the false-block rate for benign hard-negative category , is the set of examples in that category, and is its support. is the action assigned to example , is the set of restrictive actions counted as false alarms, and is the indicator function, which equals 1 when its condition is satisfied and 0 otherwise.
2.3. PromptSentinel-X Architecture and Training
PromptSentinel-X was implemented as a modular multi-view prompt-risk detector for LLM-powered web agents. The framework combined encoder-based classification, projection-space representation learning, dual fine-label and coarse-risk prediction, provenance-aware context features, optional target-LLM hidden states, post hoc calibration, model combination, and deployment-oriented routing. Components were evaluated independently and in combination under shared split and metric definitions so that architectural effects could be distinguished from dataset and policy effects.
2.3.1. PromptSentinel-X Architecture
The base architecture comprised a configurable text encoder, a projection head, a fine-label classifier, a coarse-risk classifier, calibration hooks, and optional feature-fusion modules. The encoder produced the contextual text representation, the projection head mapped that representation into a normalized metric-learning space, and the two classifier heads generated mechanism-specific and operational risk distributions.
The principal PromptSentinel-X result used the retained embedding-mode configuration. Inputs were 384-dimensional MiniLM sentence embeddings associated with paraphrase-multilingual-MiniLM-L12-v2; however, the exact Hugging Face/Sentence Transformer model revision and tokenizer revision were not pinned in the retained artifacts. Because the principal run used precomputed embedding features rather than raw-text transformer tokenization, no tokenizer was invoked during the model training.
The PromptSentinel-X model used an embedding encoder with output dimension 384, followed by a projection head with dimensions 384 → 512 → 256 → 128. The projection head used LayerNorm, GELU activations, and dropout of 0.1. The fine-label classifier was a linear 128 → 3 head for jailbreak, act_as, and conversation; the coarse-risk classifier was a linear 128 → head for benign, suspicious, and malicious.
Training used AdamW with learning rate 0.001, weight decay 0.0001, batch size 128, class weighting enabled, and random seed 42. The run was configured for 8 epochs with early stopping patience of 3 and stopped after 4 epochs. Checkpoint selection used validation fine-label macro-F1. The loss combined fine-label cross-entropy with weight 1.0, coarse-risk cross-entropy with weight 0.5, and supervised contrastive loss with weight 0.1 and temperature 0.1. Focal loss was disabled (gamma = 0.0) and center loss was disabled (weight = 0.0). Post hoc temperature scaling and OOD statistics were enabled.
The focal PromptSentinel-X model used the same in-domain split sizes as the target-LLM hidden-state experiment. The group-aware split first assigned 1116 Malignant records to the non-test side and preserved 465 records as the held-out family-aware test set. Because the saved group-aware split-assignment file did not include a validation subset, the shared split builder created validation data from the 1116 non-test records using a row-level stratified train_test_split with validation size 0.15 and random seed 42. This produced 948 training records and 168 validation records. The secondary train/validation split was stratified by fine label but was not group-aware; 28 original_family_id values crossed training and validation. The 465-record family-aware test set remained untouched for final evaluation and had no original_family_id overlap with either training or validation. The core forward pass was represented as follows.
Equation (5).
Encoder, projection, and dual-head prediction.In Equation (5), is the encoder, is the projection head, is the encoder representation of input , and is the L2-normalized projection vector. The matrices and , together with the bias vectors and , parameterize the fine-label and coarse-risk classifiers. The vectors and contain the corresponding predicted class probabilities.
2.3.2. Multi-View Representation
The multi-view design avoided making a safety decision from one textual representation alone. The text view captured lexical and semantic evidence; the projection view represented learned risk geometry; the context view encoded provenance, segment relationships, and trusted–untrusted overlap; the optional hidden-state view captured target-model activations; and the metadata view retained source, attack surface, transformation, and routing information. These views could be concatenated, stacked, averaged, or used sequentially in a cascade. The fused representation was defined as follows.
Equation (6).
Multi-view feature fusion.In Equation (6), is the concatenated multi-view feature vector, and are the encoder and projection representations, contains context-aware segment features, contains optional target-LLM hidden-state features, and contains metadata features. The semicolons inside the brackets denote feature concatenation. is an optional fusion module, and is the resulting fused representation.
2.3.3. Training Objectives
Training jointly optimized supervised classification and representation structure. The supervised contrastive term encouraged samples sharing a configured fine or coarse risk relation to occupy nearby regions of projection space while separating samples with dissimilar labels. This objective was intended to improve the organization of low-support and boundary cases, including benign roleplay, suspicious persona shifting, and malicious jailbreak behavior [
44]. The supervised contrastive loss was defined as follows.
Equation (7).
Supervised contrastive objective.In Equation (7), is the projection-space cosine similarity between the normalized vectors and . is the supervised contrastive loss, is the number of samples, is the positive set for anchor , is the number of positive examples for that anchor, is the comparison set excluding the anchor, and is the temperature parameter.
Equation (8).
Total multi-objective training loss.In Equation (8), is the total training loss, is the cross-entropy loss, and are the fine-grained and coarse-risk targets, and and are their corresponding predicted probability vectors. is the supervised contrastive loss, represents optional auxiliary losses, and , , , and are configurable loss weights.
2.3.4. Context-Aware Segmentation
Context-aware segmentation preserved provenance and authority before risk features were computed. System instructions and developer policy were treated as privileged segments; user messages, retrieved passages, browser content, tool outputs, memory records, and conversation history were treated as lower-trust or untrusted segments unless explicitly authorized by policy. The method therefore modeled not only what a segment said but also where it originated and whether it was permitted to influence the agent’s behavior.
Scope of browser representation. In this study, browser content denotes text and metadata already exposed to the detector through the structured context records. The evaluation does not ingest raw DOM topology, CSS visibility rules, screenshots, rendered pixels, OCR output, or visual overlays, and it does not independently classify ARIA attributes unless their text is present in the provided record. Accordingly, the results are described as textual browser-content injection detection and should not be generalized to non-textual or multimodal browser attacks. The structured context representation was specified as follows.
Equation (9).
Context segment set.In Equation (9), is the structured context associated with record . and are the privileged system and developer segments, is the user query, is retrieved context, is textual browser content, is tool output, is memory content, and is conversation history. A trusted–untrusted overlap score was computed to identify untrusted content that semantically resembles instructions.
Equation (10).
Trusted–untrusted similarity score.In Equation (10), Li is the set of lower-trust segments for record i, Pi is the set of privileged system and developer instruction segments, and Enc(.) is the text encoder. The cosine function denotes cosine similarity, and Pi is the maximum semantic similarity between any lower-trust segment and any privileged segment. A high value is treated as a cautionary routing signal rather than as proof of maliciousness.
2.3.5. Target-LLM Hidden-State Detector
A target-LLM hidden-state detector was evaluated as a complementary risk sensor when local access to an instruction-tuned model was available. Hidden-state vectors were extracted at prespecified layers and summarized through mean or last-token pooling before classification with logistic regression, linear support-vector machines, or shallow multilayer perceptrons. Features were cached to separate extraction cost from downstream classifier comparison.
Hidden-state features were cached for all 1581 in-domain Malignant records, but the downstream lightweight classifiers did not use a separate random split or cross-validation. They used the same leakage-aware group split defined by original_family_id. The parent group-aware partition contained 1116 non-test records and 465 held-out test records. For classifier fitting, the 1116 non-test records were further divided into 948 classifier-training records and 168 validation records using the shared split builder with random seed 42, while the 465-record group-aware test set was preserved unchanged. Logistic regression, linear SVM, and shallow MLP classifiers were trained on cached hidden-state vectors from the 948 training records and evaluated on the same 465-record family-aware test set. No separate record-level random partition, cross-validation procedure, or external test partition was used for the internal hidden-state ablation scores. The hidden-state detector was represented as follows.
Equation (11).
Hidden-state risk detector.In Equation (11), is the hidden-state sequence produced for input at layer , is pooling strategy , and is the resulting pooled hidden-state vector. and are the parameters of the hidden-state classifier, and is the resulting hidden-state risk-probability vector.
2.3.6. Calibration and Model Combination
Model combination was evaluated after individual-view prediction through probability averaging, majority voting, stacked classification, and a deployment-style cascade. Calibration was applied because raw probabilities can be overconfident under class imbalance or distribution shift. The calibrated outputs were interpreted as risk evidence for later action selection rather than as self-sufficient authorization decisions.
For the ensemble analyses, probability averaging and majority voting used seven prespecified prediction views: MiniLM/Siamese, ModernBERT-base transformer classifier, BGE-M3 embedding classifier, target-LLM hidden-state detector, Prompt Guard 2, Llama Guard, and PromptSentinel-X. These views were aligned by sample_id, and all seven provided predictions for the same 465 records in the group-aware test set. Probability averaging used the arithmetic mean of scalar calibrated risk scores. Majority voting first selected the coarse label by vote count and then selected the fine label among model predictions compatible with that coarse label. Ties were resolved deterministically by sorting tied labels lexically after sorting by descending vote count.
The cascade thresholds were retained in the synthesis configuration step, but the archived artifacts do not document a validation-threshold sweep. Therefore, these values are reported as fixed configured thresholds rather than validation-selected thresholds. The cascade used a low escalation threshold of 0.25 and a high escalation threshold of 0.75: scores in the open interval (0.25, 0.75) were considered ambiguous and routed from the fast model to PromptSentinel-X, and then to the slow safety judge if still ambiguous. Final action thresholds were risk score < 0.35 for allow, 0.35 ≤ risk score < 0.65 for warn, and risk score ≥ 0.65 for block, unless uncertainty exceeded 0.45, in which case the action was human-review. Uncertainty was computed as 1 − |score − 0.5| × 2, and model disagreement raised uncertainty to at least 0.5. Probability averaging was defined as follows.
Equation (12).
Ensemble probability aggregation.In Equation (12), is the number of component models, is the probability vector produced by component model for sample , and is the nonnegative weight assigned to that model. The weights sum to one, and is the aggregated ensemble probability vector. Under equal-weight averaging, . Here, denotes the number of models and should not be confused with the malicious coarse-risk label used in Equation (2).
Temperature scaling was used as a calibration layer when validation predictions supported it [
45].
Equation (13).
Temperature-scaled calibration.In Equation (13), is the uncalibrated logit vector for sample , is the temperature estimated from validation predictions, and is the resulting temperature-scaled calibrated probability vector.
Equation (14).
Expected calibration error.In Equation (14), is the expected calibration error, is the number of confidence bins, is the set of samples assigned to bin , and is the number of samples in that bin. is the total number of evaluated samples, is the empirical accuracy in bin , and is the mean predicted confidence in that bin.
2.3.7. Robustness Evaluation
Robustness evaluation examined whether detector behavior remained useful under perturbations and transfer conditions relevant to web agents. Prespecified categories included paraphrase, typographical and spacing noise, multilingual input, obfuscation, long context, roleplay confusion, RAG injection, textual browser-content injection, tool-output injection where available, multi-turn staging, and cross-dataset transfer. Results were stratified by category and support rather than collapsed into a single pooled robustness score. Robustness degradation for category was defined as follows.
Equation (15).
Category-specific robustness degradation.In Equation (15), is the observed robustness degradation for category , is the reference evaluation set, is the transformed or external robustness slice, and is the selected evaluation score. For higher-is-better measures, a positive value of denotes deterioration relative to the reference set.
2.4. Evaluation Protocol, Component Sensitivity, and Statistical Validation
Ablation analysis evaluated the sensitivity of the evidence to loss functions, model components, and dataset design. Each comparison used the same split definitions, metric conventions, and sanitized reporting rules as the focal model. Where a fully controlled component-removal retraining was unavailable, the comparison was explicitly labeled as an artifact-based or proxy analysis and was interpreted as sensitivity evidence rather than causal attribution. The generic ablation effect was defined as follows.
Equation (16).
Component-sensitivity effect.In Equation (16), is the full configuration, is the configuration in which component is removed or replaced, and is the selected evaluation score. The quantity is the observed score difference between the two configurations. Unless identical controlled retraining was performed, should be interpreted as component-sensitivity evidence rather than as a causal effect.
2.4.1. Loss-Function Ablations
Loss-function comparisons included cross-entropy-only training, cross-entropy with supervised contrastive learning, focal-loss variants, center or proxy-style clustering terms, and calibration-related auxiliary objectives. Evaluation emphasized macro-F1, class-wise recall, projection diagnostics, calibration, and hard-negative behavior because a loss that improves aggregate accuracy can still worsen minority-class recovery or benign false blocking.
2.4.2. Model-Component Ablations
Model-component analyses removed or replaced the projection head, coarse-risk head, context segmentation, hidden-state view, calibration layer, and ensemble or cascade mechanism. The objective was to determine which components supported class separation, operational risk mapping, context sensitivity, uncertainty handling, and deployability rather than to select a component solely from one aggregate score.
2.4.3. Dataset-Component Ablations
Dataset-component analyses examined the influence of external-test coverage, benign hard negatives, family-aware splitting, paraphrase-family control, and context-specific scenario data. Malignant-only conditions measured in-domain dependence, no-hard-negative conditions assessed over-defense, and random-split conditions quantified the optimism introduced when related prompt families could cross partition boundaries.
2.4.4. Statistical Validation
Statistical validation was performed on saved, sample-aligned predictions using five group-based prediction slices, nonparametric bootstrap summaries, McNemar tests for paired correctness, paired bootstrap comparisons for macro-F1 differences, Wilson score intervals for support-based proportions, calibration curves, and sanitized error analysis. These analyses used stable sample identifiers and did not require raw prompt text.
The group-aware component was limited to the five prediction slices. Saved predictions were merged with original_family_id, and five-fold GroupKFold was applied to construct family-disjoint evaluation slices. These folds were used as evaluation slices only; models were not retrained within the five folds. The reported group-slice mean and standard deviation were computed from the five slice-level macro-F1 values. The interval reported for the group-slice macro-F1 summary was a 200-repetition percentile bootstrap interval over the mean of these five slice-level macro-F1 values, using random seed 42 and the 2.5th and 97.5th percentiles. Because this interval was bootstrapped from only five slice-level values, it should be interpreted as a descriptive stability summary rather than as a full family-level bootstrap confidence interval.
The retained implementation did not perform a cluster bootstrap or family-level resampling for all reported bootstrap intervals. Accuracy intervals for individual model views were computed by resampling record-level correctness indicators with replacement. Paired bootstrap comparisons were computed after aligning model predictions by sample_id, resampling individual records with replacement, and recomputing macro-F1 differences. These procedures used percentile intervals, were not stratified, did not use BCa correction, and did not preserve prompt-family clusters during resampling. Consequently, these bootstrap intervals may underestimate uncertainty when related prompt-family members remain statistically dependent. They are therefore interpreted as exploratory uncertainty summaries over saved predictions rather than as fully leakage-aware confirmatory confidence intervals.
For support-based proportions, 95% Wilson score intervals were computed from the observed numerator and denominator. These intervals were reported for scenario accuracy and, where both class counts were available, for attack recall and benign false-positive rate. Low-support rows were interpreted descriptively even when the observed point estimate was high.
The retained implementation did not apply a multiple-comparison adjustment. Pairwise tests were therefore interpreted as exploratory analyses over prespecified model comparisons rather than as familywise-error-controlled confirmatory tests. Models evaluated on nonidentical support were not treated as directly equivalent. Sanitized error-category counts were analyzed alongside the statistical summaries to connect average performance with recurrent failure modes.
2.5. Error Analysis and Support-Aware Interpretation
Error analysis used saved predictions joined to sanitized sample identifiers, labels, hashes, attack-surface metadata, transformation types, confidence values, and split assignments. The objective was to identify actionable failure mechanisms without reproducing reusable adversarial content. Errors were organized into false negatives, false positives, ambiguous cases, and multilingual failures.
2.5.1. False Negatives
False negatives were malicious or high-risk inputs assigned to benign or otherwise insufficiently restrictive outcomes. They were categorized by mechanism, including direct jailbreak, indirect injection, malicious roleplay, prompt leakage, tool abuse, data exfiltration, obfuscation, long-context placement, and multi-turn staging. For deployment interpretation, errors were additionally stratified by the authority and reversibility of the affected agent action. The category-specific false-negative rate was defined as follows.
Equation (17).
Category-specific false-negative rate.In Equation (17), is the false-negative rate for category , is the number of false negatives in that category, and is the number of true positives in that category.
2.5.2. False Positives
False positives were benign inputs assigned to malicious, block, sandbox, or unnecessary-review outcomes. Analysis focused on legitimate security discussion, trigger-word cases, debugging, quoted or encoded text, prompt-engineering questions, multilingual examples, and roleplay. These categories measured the usability cost of over-defense in technical, educational, compliance, and security workflows. The benign false-positive rate was defined as follows.
Equation (18).
Benign false-positive rate.In Equation (18), is the benign false-positive rate, is the number of benign examples incorrectly assigned to restrictive actions, and is the number of benign examples correctly handled as non-malicious.
2.5.3. Ambiguous Cases
Ambiguous cases were retained as a methodological category rather than discarded as annotation noise. They included roleplay with uncertain intent, dual-use security questions, benign text containing adversarial vocabulary, educational examples, quoted unsafe material, and cases whose risk depended on tool privilege or surrounding context. Their analysis combined calibrated probability, ensemble disagreement, trusted–untrusted overlap, and out-of-distribution indicators. Uncertainty was defined as follows.
Equation (19).
Predictive uncertainty score.In Equation (19), is the predictive-uncertainty score for sample , is the calibrated probability assigned to class , and the maximum is taken over all candidate classes. A high uncertainty score does not by itself indicate maliciousness; instead, it supports warning, sandboxing, richer-model evaluation, or human review.
2.5.4. Multilingual Failures
Multilingual evaluation was analyzed separately because language shift can alter both lexical cues and semantic intent. The slice included non-English, translated, and code-mixed examples as well as multilingual or obfuscated transformation metadata. The analysis assessed attack recall, benign false-positive behavior, and the tendency to over-route legitimate multilingual content to restrictive actions, with interpretation conditioned on language-specific support.
2.6. Deployment and Reproducibility
Deployment analysis translated benchmark performance into operational constraints for LLM-powered web agents. The evaluated variants comprised a fast single-view screening detector, PromptSentinel-X, probability-averaged ensemble inference, and cascade inference. Safety metrics were interpreted jointly with latency, throughput, model size, missed-attack rate, benign false-positive rate, calibration, and escalation burden.
2.6.1. Latency and Throughput
Per-sample inference latency and throughput were measured under the preprocessing and feature-availability assumptions of each deployment variant. The protocol distinguished low-cost inbound screening from richer multi-view or ensemble evaluation. This distinction reflects the different timing requirements of user-message screening, retrieved-document filtering, browser-content inspection, memory-write gating, and pre-tool-execution authorization. Mean inference latency was defined as follows.
Equation (20).
Mean inference latency.In Equation (20), is the mean inference latency in milliseconds, is the number of repeated runs, is the start time of run , and is its end time. The factor 1000 converts elapsed time from seconds to milliseconds.
2.6.2. Cascade Thresholds
Cascade thresholds were fixed in the retained synthesis configuration. The archived artifacts did not preserve evidence of a validation-threshold sweep; consequently, these values are reported as configured operating points rather than as validation-selected optima.
Let denote the calibrated malicious-risk probability for sample , and let denote its predictive uncertainty. Inputs below a conservative allow threshold were passed to the agent. Inputs above a block threshold were blocked or sandboxed. Inputs between thresholds, or above an uncertainty threshold, were escalated to a richer detector, sandboxed tool execution, or human review. The basic action policy was specified as follows.
Equation (21).
Calibrated cascade action policy.In Equation (21), is the action assigned to sample , is its calibrated malicious-risk probability, and is its predictive uncertainty. The actions , , and denote allow, warn/review or escalation, and block/sandbox, respectively. The parameters , , and are the allow, block, and uncertainty thresholds. Under this policy, high-uncertainty cases are routed to warning, review, or escalation even when their risk score is high, whereas high-risk, low-uncertainty cases are routed directly to block or sandbox.
2.6.3. Escalation Strategy
The escalation strategy implemented staged risk control. Stage 1 applied a fast detector to ordinary user and browser inputs. Stage 2 invoked PromptSentinel-X or another richer view for uncertain cases, elevated trusted–untrusted similarity, contextual scenarios, or high-impact actions. Stage 3 routed unresolved or high-severity cases to sandboxing, explicit confirmation, human review, or policy-specific blocking. Escalation was treated as both a safety mechanism and an operational cost. The escalation rate was defined as follows.
Equation (22).
Escalation rate.In Equation (22), is the escalation rate, is the number of evaluated samples, is the action assigned to sample , and is the set of escalation actions, including warning, sandboxing, human review, or richer-model routing. The indicator function equals 1 when and 0 otherwise.
2.6.4. Computational Environment and Training Cost
The archived artifacts available for this revision did not retain hardware identifiers, software-version manifests, wall-clock training time, GPU-hours, or peak memory. These values are therefore reported as not recorded rather than estimated, and their absence is treated as a reproducibility limitation. Online latency, throughput, and model-artifact sizes were measured separately and are reported in
Section 3.9; future releases should preserve the complete environment manifest, hyperparameters, seeds, training logs, and offline feature-extraction cost. The retained artifacts identify the trained prediction outputs, split assignments, model architecture, and most training hyperparameters, but they do not preserve the exact external embedding-model revision, tokenizer revision, hardware identifiers, software-version manifest, training time, GPU-hours, or peak memory. For this reason, we describe the release as a versioned and auditable Python workflow.
2.7. Ethics, Safety, and Responsible Release
The study was designed exclusively for defensive prompt-injection detection and safety evaluation. It did not generate new attacks, optimize jailbreak success, test public targets, or publish operational attack strings. Safety controls were integrated into data handling, reporting, artifact release, and intended-use statements rather than added only after analysis.
2.7.1. No Harmful Prompts Printed Verbatim
Raw harmful prompts, malicious retrieved content, unsafe tool-output strings, and complete adversarial conversation histories were not reproduced verbatim. Qualitative analysis used sanitized identifiers, labels, hashes, transformation metadata, attack-surface categories, and aggregate error descriptions. This approach preserved analytical traceability while reducing the risk that the manuscript could function as an attack catalogue.
2.7.2. Controlled Release
Controlled-release principles governed code, data, model, and reporting artifacts. Public-facing materials may include dataset source references, schemas, label mappings, split definitions, aggregate metrics, configuration files, and reproduction commands but should exclude raw harmful prompts, credentials, private user data, unsafe tool traces, and exploit-oriented instructions. Access to external benchmarks remains subject to their original licenses and safety requirements.
2.7.3. Defensive-Only Use
PromptSentinel-X was evaluated as a defensive guardrail for prompt-risk screening, indirect-injection detection, benign hard-negative testing, context-segmentation research, calibrated routing, sandbox selection, and human-review triage. Generating new attacks, improving jailbreak success, or bypassing deployed safeguards was outside the intended scope and should not be supported by released artifacts.
2.7.4. Reproducibility and Reporting
Reproducibility was supported through stable sample identifiers, explicit label mappings, saved split assignments, configuration snapshots, cached expensive features, common metric definitions, and versioned output artifacts. Optional models or external files that were unavailable were reported as such rather than replaced with synthetic results. The manuscript documents dataset definitions, split logic, model components, loss terms, thresholds, validation procedures, deployment variants, limitations, and sanitized error categories so that the analytical claims can be independently audited without distributing reusable adversarial content.
4. Discussion
In this public benchmark and multi-layer stress-test study, PromptSentinel-X demonstrated strong prompt-risk detection under prompt-family-aware validation while also exposing the limits of treating prompt injection as a conventional static text-classification problem. The analysis was designed as a defensive safety-control evaluation for LLM-powered web agents rather than as evidence of universal attack prevention or a stand-alone authorization mechanism. The workflow retained the original imbalance of the 1581-record Malignant corpus, reserved 30,015 external records for transfer and stress testing, separated related prompt families across the primary train and test partitions, compared multiple encoder and guardrail families, evaluated target-LLM hidden states, preserved trusted–untrusted context boundaries, measured benign hard-negative behavior, assessed calibration and robustness, and quantified deployment trade-offs. This layered design strengthens the interpretation of the findings because it reduces the likelihood that high internal scores were produced solely by prompt-family overlap, attack-only evaluation, or one favorable model and test split.
The principal PromptSentinel-X result was a strong but nonuniform operating profile on the 465-record group-aware test set. The model achieved accuracy of 0.9849, macro-F1 of 0.8887, weighted-F1 of 0.9864, attack recall of 0.9851, and a benign false-positive rate of 0.0050. Fine-label performance was strongest for malicious jailbreak and benign conversation records, with F1-scores of 0.9667 and 0.9937, respectively. The suspicious roleplay or act_as class reached recall of 1.0000 but precision of 0.5455 and F1 of 0.7059. This boundary class contained only six test examples and also received false-positive assignments from neighboring benign and malicious categories. The model therefore separated clearly malicious and clearly benign inputs reliably, but the distinction among benign persona use, ambiguous roleplay, and adversarial instruction shifting remained less stable and should not be inferred from the overall accuracy alone.
The coarse-risk confusion structure is more informative for operational use than fine-label accuracy by itself. Of 61 malicious records, 56 were classified as malicious, four were routed to the suspicious category, and only one was assigned to benign. At the same time, 396 of 398 benign records remained benign, and all six suspicious records remained within the suspicious category. Most residual malicious errors were therefore conservative escalations rather than unrestricted benign decisions. For an LLM-powered agent, this distinction supports graduated responses such as warning, richer-model inspection, sandboxed execution, reduced tool privilege, or human review. However, the classifier cannot determine the appropriate action in isolation. The final policy must also account for the requested capability, sensitivity of accessible data, reversibility of the action, user authorization, and the consequences of both false blocking and missed attacks.
The same-split model comparison shows that the contribution of PromptSentinel-X should not be expressed as universal numerical superiority. BGE-M3 embeddings followed by a classifier and several mean-pooled target-LLM hidden-state configurations achieved perfect internal accuracy and macro-F1. MiniLM embedding logistic regression and ModernBERT-base also produced higher macro-F1 values than PromptSentinel-X, at 0.9308 and 0.9258, respectively. In contrast, specialized guardrail comparators varied widely, with substantially lower class-balanced performance for Prompt Guard 2, Granite Guardian, and Llama Guard in the reported setup. Pairwise tests reinforced this qualified interpretation: BGE-M3 made fewer paired errors than PromptSentinel-X, the comparison with the reported transformer classifier did not resolve a statistically meaningful difference, and PromptSentinel-X strongly outperformed Llama Guard. The value of PromptSentinel-X therefore lies in its combined operating profile—high attack recall, low benign disruption, calibrated probabilities, structured representation learning, compatibility with context-aware analysis, and moderate deployment cost—rather than in claiming that its focal classifier leads every internal leaderboard.
Prompt-family leakage was one of the most consequential validity findings. For the corresponding split-sensitivity baseline, random splitting produced accuracy of 0.9853 and macro-F1 of 0.9491, whereas group-aware splitting produced accuracy of 0.9763 and macro-F1 of 0.8352. The random partition generated 144 warnings, including 52 family-overlap warnings, 52 paraphrase-overlap warnings, and 40 near-duplicate warnings. Group-aware splitting eliminated the family and paraphrase overlaps and retained 38 near-duplicate warnings. The lower family-aware score should therefore be interpreted as a more conservative estimate of performance on previously unseen prompt families, not as deterioration caused by the split itself. This distinction is essential for Agentic Web deployment, where systems encounter new webpages, retrieved passages, tool descriptions, languages, and attack formulations rather than repeated benchmark variants. Because near-duplicate warnings remained, the design is best described as leakage-mitigated rather than fully leakage-free.
The projection-space diagnostics provide evidence that the learned representation organized the three risk classes into a structured geometry. The UMAP analysis was supported by a silhouette score of 0.7881, a Davies–Bouldin index of 0.3925, and a mean class-centroid distance of 13.8839. This organization may be useful for uncertainty-aware routing because samples near class boundaries can be escalated instead of being forced into a high-confidence binary action. The training trajectory also stabilized without a late collapse in validation macro-F1. Nevertheless, the current component-sensitivity evidence does not isolate the causal contribution of supervised contrastive learning. The reported no-contrastive condition used a ModernBERT proxy rather than controlled retraining of an otherwise identical PromptSentinel-X configuration, and that proxy achieved numerically higher macro-F1. The results therefore support representation separability, but they do not establish that the contrastive term alone caused the observed classification performance. A controlled factorial ablation remains necessary before attributing gains to individual loss components.
The target-LLM hidden-state experiment identifies a potentially valuable complementary detection channel. Mean-pooled representations from Qwen2.5-0.5B-Instruct achieved perfect internal accuracy and macro-F1 under several lightweight classifiers, while last-token pooling remained strong but more variable. This result suggests that prompt-risk information was already encoded in the target model’s latent representation and could be monitored with a comparatively small downstream classifier. Such monitoring may be useful at high-assurance control points, including pre-tool authorization, protected memory writes, or operations involving sensitive data. Its scope is nevertheless constrained by the requirement for local or exposed model states, dependence on the evaluated architecture and layer, and possible drift after fine-tuning, quantization, model updates, or provider-side revisions. The perfect internal scores should therefore be interpreted as evidence of latent separability within this benchmark, not as proof of cross-model or cross-domain transfer.
The near-perfect BGE-M3 and hidden-state scores show separability within the evaluated benchmark and split, but they should not be read as equivalent to independent cross-platform generalization. The external adapters differ in label definitions and class balance and were used as stress tests rather than as a preregistered replication. Independent evaluation on executable agent benchmarks and unseen providers remains necessary, particularly after model updates or representation drift.
The context-aware findings provide the clearest evidence that static prompt detection is insufficient for the Agentic Web. The structured evaluation contained 2850 records, but support differed substantially across fields and scenarios. Static user prompts reached macro-F1 of 0.8301 and textual browser-content injection reached 0.7594. Performance declined to 0.6306 for multi-turn staging, 0.3844 for RAG injection, and 0.3200 for memory-related injection. The nominally perfect tool-output result was based on a single qualifying scenario and cannot support a general claim about tool-mediated defense. Relationship-level classification was strong for benign context, override attempts, tool abuse, data exfiltration, obfuscation, and roleplay or borderline behavior, but leakage attempts reached only 0.3333 F1 and hijack attempts reached 0.7562 F1. The principal unresolved problem is therefore not explicit jailbreak recognition; it is the discrimination of indirect leakage, hijacking, and context-dependent instruction control from semantically similar legitimate content.
Support-aware uncertainty reinforces the evidence boundary. The one-record tool-output result is descriptive, the memory-related estimate is exploratory, and the leakage-attempt relationship contains only 16 examples. These rows identify failure modes worth studying but do not establish reliable tool, memory, or leakage defense. In addition, the browser-context records represent textual content available to the detector, not raw DOM structure, CSS visibility, ARIA hierarchy, screenshots, or visual overlays. The current evidence therefore supports textual prompt-risk screening, not comprehensive browser-agent perception security.
Trusted–untrusted similarity added useful but limited context. Suspicious and malicious records tended to show greater semantic overlap with privileged instructions, yet the distributions overlapped substantially. Similarity to system or developer language is therefore not equivalent to maliciousness. Benign documentation, policy text, software instructions, security guidance, and quoted material may also resemble privileged instructions. In deployment, provenance and authority must remain distinct from semantic similarity: browser content, retrieved text, tool output, and memory should be treated as data unless the runtime explicitly authorizes those sources to influence the agent’s instruction hierarchy. PromptSentinel-X can provide a risk and uncertainty estimate, but source isolation, instruction provenance, tool permissions, output validation, and memory-write controls must be enforced by the surrounding application.
The hard-negative analysis demonstrates why attack recall must be interpreted jointly with usability. A trigger-word baseline produced a benign false-positive rate of 0.0030 but detected only 11.8% of attacks. The intent-sensitive TF-IDF model improved attack recall to 48.7% and macro-F1 to 0.6986, but its benign false-positive rate increased to 6.85%. Category-specific false blocking was especially high for benign security discussion, trigger-word cases, quoted or encoded text, multilingual examples, debugging content, and benign roleplay. These categories are central to legitimate web-agent use in software development, security analysis, education, documentation review, incident response, and multilingual assistance. The findings show that a detector may appear conservative because it rarely blocks benign traffic while missing most attacks or appear protective because it raises recall while making legitimate workflows unusable. Hard-negative testing and category-specific false-block rates should therefore be treated as primary evidence rather than as optional diagnostics.
Calibration and threshold behavior further explain why simple filtering was inadequate. The intent-sensitive baseline outperformed trigger-word matching on AUROC, AUPRC, and expected calibration error, yet its false-positive rate at 95% true-positive rate remained 0.9677; the corresponding value for trigger-word filtering was 1.0000. Neither simple detector offered a credible high-recall operating point. PromptSentinel-X achieved an expected calibration error of 0.0153, and the deployment cascade achieved 0.0163, supporting risk-based routing more strongly than the simple baselines. However, the reliability curve still departed from ideal calibration in the lowest- and highest-confidence regions. These probabilities should therefore be interpreted as deployment-specific decision signals rather than invariant security probabilities. Thresholds require recalibration when the model version, input population, attack prevalence, tool privilege, or acceptable review burden changes.
The robustness results were encouraging for attack sensitivity but did not establish uniformly balanced robustness. Attack recall remained at or near 1.0 across paraphrase, typographical noise, multilingual inputs, obfuscation, long context, RAG injection, roleplay confusion, and cross-dataset transfer. Macro-F1, however, ranged from 0.7143 for multilingual inputs to 0.8879 for long-context attacks, with obfuscation at 0.7500, roleplay confusion at 0.7827, RAG injection at 0.8125, and typographical noise at 0.8211. This gap indicates recall-dominant behavior rather than consistent class balance. Some slices were also highly skewed: the RAG slice contained only nine benign records, and the long-context slice contained no benign records, preventing estimation of benign false-positive rate and binary calibration. In addition, the paraphrase and cross-dataset summaries were computed over the same grouped external-test pool and should not be interpreted as independent replications. The evidence supports broad attack sensitivity under several transformations but not immunity to adaptive, multilingual, obfuscated, or indirect attacks.
The ensemble and cascade analyses show that model combination can improve selected outcomes while introducing new trade-offs. Majority voting achieved the strongest complete-test result, with 0.9968 macro-F1, attack recall of 0.9851, and no benign false positives on the 465-record test set. Probability averaging also eliminated benign false positives but reduced attack recall to 0.9701, increased the missed-attack rate to 0.0299, and produced an expected calibration error of 0.1171. The cascade achieved a macro-F1 of 0.8935, attack recall of 0.9254, benign false-positive rate of 0.0050, and an escalation rate of 1.72%, but it also had the highest reported missed-attack rate, 0.0746. The stacked classifier achieved perfect scores on a smaller 163-record subset and is not directly comparable with complete-test results. Ensemble gains thus depend on support size, model-error correlation, calibration, threshold selection, and the policy applied after prediction; combination alone does not guarantee the most appropriate safety profile.
Deployment measurements clarify where the evaluated variants may fit within an agentic workflow. The fast-screening model required approximately 2 ms per prediction and processed 500 predictions per second, but its benign false-positive rate was 0.0151. PromptSentinel-X reduced that rate to 0.0050 while preserving an attack recall of 0.9851, with latency of 12 ms, throughput of 83.33 predictions per second, and a reported model artifact of 1.963 MB. The probability ensemble required 45 ms per prediction and processed 22.22 predictions per second, while the cascade occupied an intermediate position at 18 ms and 55.56 predictions per second but sacrificed attack recall. These results support a privilege-aware placement hierarchy: the fast model is most suitable for high-volume inbound screening and low-risk filtering; PromptSentinel-X is better suited to selected agentic decision points and untrusted-content inspection; the cascade is most defensible for uncertain cases and pre-tool-execution routing; and the probability ensemble is better reserved for offline audit or high-assurance checks where additional latency is acceptable. These placements remain hypotheses until validated under the target serving environment and workload.
The statistical validation should be interpreted as exploratory support rather than confirmatory proof of stable superiority. The five group-based prediction slices provided a descriptive check on variation across family-disjoint evaluation slices, while the bootstrap accuracy and paired macro-F1 intervals were computed by resampling individual records. Because those bootstrap procedures did not resample prompt families as clusters, they may underestimate uncertainty when related prompt-family members remain dependent. Accordingly, the statistical results are used to qualify the descriptive model ranking: BGE-M3 showed fewer paired errors than PromptSentinel-X, the PromptSentinel-X versus transformer comparison was not clearly resolved, and PromptSentinel-X substantially outperformed Llama Guard in the retained prediction artifacts. These findings should be read as exploratory evidence from the saved evaluation outputs rather than as definitive family-level inferential claims.
The statistical analyses provide exploratory consistency checks for the main internal findings while limiting claims of family-level uncertainty or universal model superiority. Five group-based prediction slices produced a mean macro-F1 of 0.9158, standard deviation of 0.0532, and an interval from 0.8723 to 0.9595. PromptSentinel-X accuracy was 0.9849 with a bootstrap interval from 0.9720 to 0.9957. Paired comparisons favored BGE-M3, did not resolve a difference between PromptSentinel-X and the reported transformer comparator, and strongly favored PromptSentinel-X over Llama Guard. Sanitized error analysis identified malicious roleplay as a recurring false-negative category, together with one long-context failure and a small number of other mismatches. Because the error tags could overlap, these counts represent failure categories rather than unique cases. The pattern is consistent with the class-level and context-level evidence: explicit jailbreak and ordinary conversation examples were comparatively tractable, whereas ambiguous roleplay and context-sensitive instructions remained more difficult.
Study Limitations and Future Work
Several limitations constrain generalization. First, the in-domain corpus contains 1581 English-language records, is strongly imbalanced, and includes only six suspicious examples in the principal test set. Second, family-aware splitting removed family and paraphrase overlap but retained near-duplicate warnings and depends on the quality of the family identifiers. Third, external adapters harmonize sources with different collection methods, label definitions, and class balances; pooled stress-test performance is not an independent cross-platform replication. Fourth, context support is uneven: tool-output injection has one qualifying result, memory-related injection has 35 records, and leakage attempts have 16 relationship examples. Fifth, the browser analysis uses textual or structured fields rather than raw DOM topology, CSS-hidden content, ARIA hierarchy, screenshots, or visual overlays.
Additional limitations concern causal and operational claims. Several component comparisons are artifact-based proxies rather than controlled one-component-at-a-time retraining, and the focal model does not directly fuse the hidden-state detector. Calibration and cascade thresholds were evaluated retrospectively. Latency, throughput, and size are environment-dependent, and complete training hardware, software-version, wall-clock-time, GPU-hour, and peak-memory logs were not retained. Most importantly, the study evaluates classification and routing, not whether a functioning web agent avoids unauthorized actions. Detection can inform a policy, but provenance enforcement, least-privilege tool access, plan and output validation, protected memory writes, confirmation, and sandboxing must be implemented by the surrounding runtime.
Future work should begin with independently collected, balanced scenario sets for tool descriptions and outputs, memory writes and poisoning, leakage, RAG, browser content, and staged multi-turn attacks, with difficult benign controls for every surface. Multimodal browser evaluation should cover raw DOM trees, ARIA and accessibility structure, CSS visibility, hidden text, screenshots, visual overlays, and computer-use agents in environments such as ASB, WASP, VisualWebArena, EIA, and VPI-Bench [
39,
40,
41,
42,
43]. Controlled factorial retraining should remove one component at a time under identical architectures, shared group-aware folds, seeds, and hyperparameters. Hidden-state detectors should be tested across model families and versions. Prospective end-to-end studies should report attack success, task completion and utility, unauthorized-action prevention, review burden, drift, sandbox failures, and latency under realistic concurrent load. Broader multilingual and code-mixed coverage, adaptive detector-aware attacks, and post-update recalibration are also required.