Submitted:
15 September 2026
Posted:
16 September 2026
You are already at the latest version
Abstract
Large Language Models (LLMs) suffer from the problem of prompt injection vulnerability, but typical one-step defenses generally fail at the task by having a high amount of false positives. We introduce an innovative two-sided defense architecture that applies semantic multi-vector diversification and ensemble modeling to provide LLM protection without the need for closed black-box solutions. In our framework, we use three different semantic spaces mapping via publicly available embedding algorithms, where each is then scored by parallel classifiers based on gradient boosting machines. The inputs go through an adaptive voting-based routing process; those that receive low entropy ratings are classified normally, while high entropy items are sent through a secondary classifier – a local LLM expert, the Llama Guard 3, that handles the input. Importantly, this solution uses a two-way protection method, which checks the generated outputs and catches late execution and context manipulation vectors. Our experiments on a 93K dataset show that the ensemble approach performed better than any individual sub-model, reaching 90.69 % accuracy and 94.11 % specificity, minimizing any user experience disturbances. The multi-vector layer demonstrated high empirical resilience to tokenization errors, while the output layer filtered out many bypassed malicious items.

Keywords:
prompt injection attacks
; ensemble learning
; Large Language Models
; semantic diversity
1. Introduction
The use of Large Language Models (LLMs) in modern software environments, such as RAG models and autonomous agents, has greatly enhanced data analysis and generation [1]. Nonetheless, this rapid adoption has increased the vulnerability of these models to prompt injection attacks, in which a user sends a malicious instruction to the model to carry out a task other than the intended one. There is a unique susceptibility of RAG models to indirect prompt injection since they pull information from untrusted data sources, such as documents or websites, which contain malicious prompts to the model [2,3]. Attackers have become more sophisticated in their attacks; they now create effective prompts using automated and optimized tools. In addition, there is a transferability challenge in which an attacker creates prompts for local use with open-source models and then uses them on black-box models online [4].
Currently, there is an issue of achieving a secure yet functional equilibrium for these defenses. The current defenses, which include easy instruction-based separation of data, are too weak and do not generalize against the threat of attackers that try to exploit queries disguised as legitimate ones. Fine-tuning methods cannot provide the information necessary for the model not to do certain things during an attack customized for that exact model [5,6]. As a result, many detection methods face the problem of base rate fallacy and generate an abundance of false positives, causing problems for legitimate users trying to submit queries and thus creating an unpleasant user experience [7,8]. The compromise of LLMs that have access to sensitive tools or operating systems can have dangerous consequences, including exfiltration of data, financial operations, and system command executions [9,10].
This research presents an innovative, multi-layered defense strategy to combat prompt injection attacks within practical deployments of LLMs. This research goes further than mere input validation, acknowledging the computational cost of fine-tuned models and their inherent risks related to manipulative guardrails [11]. While [12] showed that one embedding classifier is sufficient for detecting prompt injections, our work goes a step further with (i) a redundant multiple-embeddings classifier based on Triple Modular Redundancy concepts, (ii) an adaptive routing system to fall back on LLMs using confidence thresholds, and (iii) an input-output verification layer. The main contributions of this paper are:
- Open-Source Architecture: Proving that effective defense does not necessitate closed-source APIs. Open-source embeddings and Llama Guard 3 can enable privacy-centric architectures that do not require data to leave secure infrastructure.
- Multi-vector defense mechanism: Applying an ensemble of three different types of embeddings. This redundancy is essential for fault tolerance, as failure of any one of the embeddings to produce the proper vectors will be mitigated by the remaining two embeddings [13].
- Voting-Based Routing Mechanism: In order to achieve maximum efficiency and accuracy, the system uses a voting-based routing mechanism. Classifications that have high confidence are processed using the fast route, whereas low-confidence input is sent to an additional expert classifier named Llama Guard 3.
- Bidirectional Verification: Going beyond checking only inputs and verifying both inputs and outputs. This multi-step process will detect more advanced attacks by ensuring that attempts to tamper with the LLM will not succeed in generating harmful outputs for users.
This research attempts to answer the following research questions:
- RQ1: How will the integration of a multi-vector representation approach with a voting-based routing method influence the efficiency of prompt injection detection?
- RQ2: Will a two-way verification approach (input and output filtering) be able to deal with "silent failures," should the input guardrails be circumvented?
- RQ3: Is it possible to design an effective prompt injection protection mechanism using only open-source models?
2. Literature Review
Prompt injections are a new set of potential dangers brought about by the incorporation of Large Language Models (LLMs) into production environments, such as autonomous agents and retrieval-augmented generation (RAG) systems. These types of attacks take advantage of the architectural challenge LLMs face in differentiating between user-provided data and system commands. This review concentrates on recent studies in three areas: universal detection frameworks for rapid injection, defensive mechanisms in LLM agents, and security in RAG systems.
2.1. Security in RAG Systems
Current protections are still vulnerable to attacks, according to research. They either lack the specificity to reject malicious inputs or prompts, or they are primarily ineffective against optimization-based assaults. In order to achieve this, SecAlign turns security into a preference optimization problem. By using Direct Preference Optimization to train models to favor secure replies over unsafe ones, SecAlign significantly lowers attack success rates [4]. In the same direction, the BIPIA assessment highlights how most LLMs are unable to differentiate between active directives and informational context. In order to effectively contain these attacks, the authors then propose a white-box defense mechanism that uses adversarial fine-tuning with specific tokens to clearly demarcate data boundaries [14].
Among the elements in the RAG, some components require hardening to enhance their security. CodeGuarder helps in providing extra protection for the Retrieval-Augmented Code Generation, which involves Security Knowledge and the Function Code Snippet Types in a way that even if a particular model gets poisoned information from an online repository, it can learn from its mistakes [15]. The chatbot architecture that utilizes reverse RAG becomes more secure since the chatbot uses only the retrieved data to respond to any requests raised through the chatbot and cannot be used to substitute other already verified data [16]. The chatbot is integrated with the primary pipeline using an Archias expert model to classify the user inputs and mitigate particular domain-specific risks, such as manipulation of prices or questions regarding the price [17].
A concept called InstructDetector uses the internal behavioral states of the LLM, namely hidden states and gradients, to locate hidden instructions inside returned text in order to achieve high detection accuracy with minimal data [3]. Another AI firewall system is CONTROLNET, which filters malicious requests by detecting changes in a model’s activation state or shifting patterns brought on by the presence of malicious information [6].
Regarding privacy security, LeakSealer offers a semi-supervised system that uses static forensic analysis and dynamic active defense to identify PII leaks in RAG responses [18]. An innovation called Jatmo suggests task-specific fine-tuning, which effectively eliminates a model’s general instruction-following capability, limiting its application to a single task and rendering prompt injections ineffective, in contrast to some other approaches that operate at the levels of model specialization or ecosystem-level threats [19]. Another technique, the RAGworm, shows how a viral threat can propagate self-replicating adversarial prompts across a networked ecosystem of GenAI apps. By comparing input retrieval to created output, the proposed defense, which makes use of the DonkeyRail solution, offers a mechanism for their detection [20]. In order to safeguard RAG agents, a thorough benchmark of 847 test cases confirms the necessity of multi-layered defenses that combine content filtering, hierarchical guardrails, and response verification [2].
2.2. Defense Mechanism for LLM Agents and ChatBots
LLM agents, who can perform actions and invoke tools, are more vulnerable than passive chatbots. Ensuring that every agent action precisely complies with user intent is the primary purpose of security in this domain.
By tracking system calls to detect and prevent harmful "side effects" like illegal file access that conventional text-based logs can miss, AgentSentinel offers a kernel-level defense for computer-use agents [9]. Task Shield is an alternative strategy. Task Shield enforces "Task Alignment," which filters out irrelevant and potentially dangerous instructions, by continuously confirming that each tool call or sub-task generated by the agent clearly relates to the user’s aim [21]. In order to particularly prevent indirect injections, IntentGuard employs a "instruction-following intent analyzer" to interpret the internal planning process of the model and notify the user if an intended instruction comes from an untrusted data segment [22].
A multi-layered security architecture that uses Keyword Identification along with a Cryptographic Signature scheme for security in high-risk financial domains is currently under development. Here, the idea is that the set of specific "commands" used has already been encoded using an unknown "signed" key. Thus, it is ensured that these "valid" commands cannot be reissued or modified by any attacker in order to include some additional command [10]. An Event-driven Architecture (EDA), in which security services collaborate through events for authentication and real-time defense adaptation, is another approach that can be adopted [5]. In PPA, the predictability associated with static defenses is overcome by making random changes in the prompt structure of the system for every new request. This prevents the attacker from overfitting his attacks on a particular configuration [7]. Finally, DataSentinel formulates detection as a game-theoretic problem, thereby enhancing robustness against adaptive adversaries by fine-tuning a detector on attacks optimized to evade it [23].
2.2.1. General Prompt Injection Detection and Guardrails
The "base-rate" problem of detectors misidentifying harmless conversational queries as assaults is the focus of PromptShield; the authors developed a detector to maintain a very low false-positive rate appropriate for deployment in industry-strength applications [24]. Linguistic and semantic analysis are used in a number of methods. By using language profiling, "Prompter Says" enables a classifier to distinguish between the "more straightforward" approach of a legal query and the "more complex command-driven" approach of a jailbreak assault [25]. A multi-agent system called JailGuard combines several analytical agents—linguistic, psychology-based, or semantic—to fend against complex attacks that make use of multiple interaction channels [26]. To effectively train the supervised classifiers, MalPID provides a complete dataset of malicious prompts [27].
Other approaches use the model’s internal generation stream or logic. Before reacting, Careful Thought Defender forces the model to perform a kind of "self-check" using a unique, dedicated CoT method to identify potential hazards [28]. Because StreamGuard monitors the generating stream in real time, it may instantly truncate a response when it senses a jailbreak attempt, revealing less sensitive data [29]. In order to prevent attackers from extracting or overriding system prompts via a standard text-based injection, SysVec recommends encoding them as internal vectors rather than text tokens [30].
There are also heuristic and hybrid defenses. The Hybrid Constitutional Classifier, which balances speed and security, is presented in one work. It consists of a quick, rule-based keyword filter and a slower, but more accurate, model-based evaluator [31]. An alternative method uses heuristic feature engineering and a pre-trained model to identify injections by examining unique characteristics in the prompt [32]. By employing the model itself to identify and eliminate quick injection vulnerabilities, an LLM-driven defense strengthens system security [33]. Lastly, to add an extra layer of security, a machine learning-based security layer was created especially for ChatGPT to detect dangerous cybersecurity prompts [12].
To provide context for the technical environment and highlight the need for the new framework, it is essential to analyze the strengths, verification ranges, and drawbacks of current state-of-the-art cybersecurity approaches. Modern defenses certainly bring improvements in comparison with the previous generation, but often face some limitations either related to their architecture or implementation. Approaches focused on defending input, like Preference Optimization or calibration of detectors, expose systems to all kinds of manipulation or "silent failures" after bypassing the first layer. In addition, purely generative or streaming approaches are known to create latency bottlenecks for inference. In many cases, robust solutions demand intrusive white-box modification of model weights which makes them useless in enterprise settings. As can be seen in Table 1, the Multi-Vector Ensemble combines the low-latency operation of a free classifier ensemble and bidirectional verification.
3. Methodology
3.1. Architectural Overview
This designed methodology takes into account a robust and multilayered defense against prompt injection attacks. This defense mechanism leverages the architecture and semantic analysis of open-source language models, using a two-way validation technique to detect any loopholes in both the input and output stages. This defense mechanism works through a five-stage pipeline that can be seen in Figure 1 and consists of:
- 1.
- Input Ingestion: Textual queries are collected from user environments or external data streams such as Retrieval-Augmented Generation (RAG) pipelines.
- 2.
- Multi-Vector Space Mapping: Input text is simultaneously transformed into three independent vector spaces using different open-source embedding encoders.
- 3.
- Ensemble Classification Inference: The generated vectors are analyzed by parallel gradient-boosting classifiers, yielding six simultaneous predictions.
- 4.
- Confidence-Based Consensus Routing: An adaptive voting mechanism filters incoming requests. High-confidence benign inputs are directly forwarded to the LLM, confirmed malicious prompts are rejected immediately, and uncertain cases are passed to an expert fallback model, Llama Guard 3.
- 5.
- Output Interception Filter: Responses generated by the target LLM are evaluated by a secondary output guardrail before being delivered to the client.
3.2. Dataset and Feature Engineering
The proposed framework was evaluated based on the use of a large-scale non-duplicate prompt injection dataset [34]. Initially, there were 553,185 prompts in the dataset, which were then deduplicated to improve the model’s generalization and prevent overfitting. The final dataset consists of 467,057 unique prompts obtained from various Hugging Face repositories such as:
- imoxto (Prompt Injection cleaned dataset)
- reshabhs (SPML Chatbot Prompt Injection)
- Harelix (Prompt Injection Mixed Techniques)
- JasperLS (Prompt Injections)
- fka (Awesome Chatgpt Prompts)
- rubend18 (ChatGPT Jailbreak Prompts)
Here is the distribution of the dataset:
- Malicious Prompts (Class 1): 109,934 (23.54%) - jailbreak attacks and token manipulations.
- Benign Prompts (Class 0): 357,123 (76.46%) - normal prompts by users.
The datasets consist of four columns as follows:
- ID: Unique identifier for the prompt.
- Source: Repository where the data came from.
- Text: The raw text prompt.
- Label: Safety label (0 for benign and 1 for malicious).
To ensure the model is evaluated correctly and minimize the initial impact of class imbalance, the dataset was split using a stratified 80/20 train/test split. Stratified splitting is a widely recognized fundamental practice aimed at ensuring the proportional representation of classes within both training and test datasets, preventing distribution distortions that would bias the classifier’s predictions toward the majority class [35,36,37]. With this, stratification provides additional stability during model training and allows to avoid distorting final performance due to random partitioning. Although, according to recent research, stratification doesn’t entirely solve the problem of prediction bias and is significantly outweighed by the choice of classifier and subsequent data manipulations, it still remains an important prerequisite for representative baselines [38]. For this reason, it is used here not as a solution to imbalance per se, but as a fundamental structural step. In this way, it reduces initial bias toward the majority class and ensures the statistical correctness of the test dataset, thus creating a solid foundation on which advanced model selection, such as hyperparameter tuning of XGBoost and LightGBM, can be performed effectively [39,40].
3.3. Multi-Vector Semantic Diversity Layer
Relying solely on a single embedding space leads to a critical weakness, as any adversarial prompt that semantically resembles legitimate prompts in the latent space of the encoder becomes undetectable by the classifiers used subsequently.
In order to strengthen resilience against faults and intrusions, the system represents every prompt in three semantic spaces via embedding models that are open-sourced and contain fewer than one billion parameters:
- Snowflake Arctic-Embed (33M): An embedding model that creates sentence embeddings based on the last hidden state from the [CLS] token. The model was trained with InfoNCE loss, hard-negative sampling, and source stratification [41].
- IBM Granite-Embedding (30M): An enterprise-scale bi-encoder fine-tuned with Retro-MAE masking autoencoder and further fine-tuned with multi-head knowledge distillation [42].
- Sentence-Transformers MiniLMv2 (33M): A lightweight version of the student model trained using deep self-attention relation distillation for general semantic understanding with ultra-low latency [43].
The architectural decision for using three embedding models aims at achieving a balance between operational fault tolerance and computational efficiency, borrowing the principles of Triple Modular Redundancy (TMR) [44]. Despite the similarity in terms of constraints on the model parameters ( 30–33M) and architecture (bi-encoders outputting 384-dimensional embeddings), these three models were purposely chosen due to non-overlapping semantic blind spots resulting from completely different approaches to pre-training. Snowflake makes use of [CLS] token pooling and InfoNCE loss based on strict source stratification; IBM Granite uses Retro-MAE masking and multi-step contrastive fine-tuning; while MiniLMv2 leverages deep self-attention relation distillation (query, key, value relations transfer) [41,42,43].
Hence, this three-pronged approach serves as a fail-safe operationally. In spite of the impossibility of perfect statistical independence of semantic errors within transformer-based bi-encoders, the structural independence is sufficient to avoid catastrophic failure on the system level. This has been experimentally confirmed during the dataset preprocessing stage, as even though there were heavy individual cases of dropouts due to non-standardized Unicode (which is explained in Results section), no concurrent dropouts have ever happened in all three encoders [45]. Increasing the system from three to five, or even seven, models would yield very little semantic variety in exchange for a linear increase in VRAM usage and inference time [46,47].
3.4. Ensemble Machine Learning Classifiers
Though deep learning algorithms are quite efficient for homogeneous data, the tree-based ensemble classifier tends to be more efficient at classifying high-dimensional static tabular vectors [48]. The proposed system utilizes two leading gradient boosting techniques, which include:
- XGBoost – (Extreme Gradient Boosting): Minimization of a regularized empirical risk function based on second-order Taylor approximation in additive regression trees to control complexity and minimize overfitting [49].
- LightGBM – (Light Gradient Boosting Machine): Efficiency improvement through: Gradient-Based One-Side Sampling (GOSS), Exclusive Feature Bundling (EFB), Leaf-wise histogram optimization [50].
Each of these two classifiers is trained independently on the embeddings of each semantic model. Thus, a total number of:
The choice of six machine learning classifiers is a combinatorial approach intended to maximize diversity of decision boundaries through mathematical creation of algorithmic ambiguity [51,52]. Using precisely two tree-based algorithms with complementary properties in XGBoost and LightGBM to create a classifier with high specificity and sensitivity, respectively, across three embedding spaces leads to the creation of a classifier ensemble. The use of just three classifiers (one per embedding space) would force the system to have the specific bias of one algorithm, greatly reducing its representational and robust nature. On the other hand, using an odd number of classifiers (such as nine) would greatly tilt the voting distribution towards achieving a majority in the decision, virtually making a perfect tie vote impossible [53,54]. In intentionally creating an even number of six classifiers, the system creates statistical ambiguity (e.g., a vote tie or a vote margin with ) when faced with highly ambiguous or obscure prompts. This statistical ambiguity created in the system perfectly fits into the CBR (Case-Based Reasoning) logic, helping the system clearly determine whether the primary ensemble lacks confidence and needs to activate the Llama Guard 3 "Slow Route," which is explained below [55,56].
3.5. Adaptive Confidence Routing and Voting Logic
In real-time inference, low latency is achieved through an adaptive routing mechanism based on the level of consensus among the ensemble classifiers. Let denote the number of classifiers predicting a prompt as safe, and denote the number of classifiers predicting it as malicious. Since the ensemble consists of six classifiers, the total number of votes satisfies:
The confidence of the ensemble decision is quantified through the consensus margin , defined as:
A larger value of indicates stronger agreement among the classifiers, whereas a smaller value suggests uncertainty or disagreement. Based on the value of , the framework applies one of two routing policies:
Fast Route ()
A consensus margin greater than two indicates a high-confidence prediction, corresponding to vote distributions such as or . In these cases, the ensemble decision is considered sufficiently reliable to bypass further analysis. If the majority vote classifies the prompt as safe, the request is forwarded directly to the target LLM. Conversely, if the majority vote classifies the prompt as malicious, the prompt is immediately rejected, thereby preventing unnecessary computational overhead and reducing inference latency.
Slow Route ()
A consensus margin of 2 or less indicates an ambiguous classification, corresponding to vote distributions such as or . Such cases often arise from sophisticated jailbreak attempts, prompt injection attacks, or linguistically obfuscated malicious prompts that produce conflicting classifier predictions. To improve detection reliability, these uncertain cases are routed to the expert model, Llama Guard 3, which performs a more comprehensive semantic and safety analysis before a final decision is made.
This adaptive routing strategy balances security and computational efficiency by reserving the more expensive expert-model evaluation only for prompts that exhibit low ensemble confidence.
As the ensemble has six classifiers, the consensus margin will be limited to discrete, even integers: 0 (3:3 tie), 2 (4:2 weak majority), 4 (5:1 strong majority), and 6 (6:0 unanimous agreement). The choice of as the threshold value enforces a strict superiority requirement (5 out of 6 models agree) to trigger the Fast Route. A stricter threshold would result in the need for complete unanimity. This would unnecessarily reroute thousands of high-confidence (5:1) predictions to the computationally expensive expert model, thus increasing system latency [57,58]. In addition, a count-based rather than soft-based (probabilistic) voting scheme is explicitly used here. Tree-based classifiers tend to be poorly calibrated probabilistically when predicting adversarial text. That is, such models might produce high-confidence (close to 1 or 0) predictions for the classes that are incorrect. The use of the count-based threshold protects the architecture from such a scenario where the model gives a confident prediction (0.99), while other models disagree with it [59].
3.6. Bidirectional Intercept
To counter more complex attacks where the malicious code remains inactive until response creation, there is an added step of output validation [60,61]. This takes place after the target LLM creates a response but prior to delivering that information to the end-user. The generated response undergoes scrutiny using the specialist safety model, known as Llama Guard 3.
It looks for any of the following criteria in the response:
- Attempts at data leakage
- Commands for unauthorized code execution
- Manipulation of system prompts
If the output complies with the checks as being safe, then the information is delivered to the end-user; otherwise, the response is filtered, and only a generic security rejection message is displayed.
3.7. Use of Generative AI
In the process of writing this paper, Google Gemini has been employed to aid in three different tasks: (i) help with the development and debugging of the code that was executed experimentally, including the ensemble pipeline, the voting system, and the evaluation code, the latest version of which is publicly available at https://github.com/adolfojara10/blue-team-ai; (ii) enhance the language used in some parts of the manuscript without being limited to superficial grammar corrections; and (iii) aid with interpreting the numerical results provided by the classification, the confidence-based routing, and the bidirectional guardrails. Generative AI was not used in designing the defensive architecture, generating the dataset, assigning safety classifications, or measuring experimental results. The authors are solely responsible for all AI-assisted outputs and conclusions made in this manuscript.
4. Experimental Setup
In order to make our findings reproducible and not affected by the performance limitations due to the hardware, all experiments were performed using the same local workstation. Our computational setup was designed to provide fast multicore calculations with additional GPU acceleration. The hardware used included the Intel Core i7 processor (16 logical cores), an NVIDIA GeForce RTX 4070 with 8 GB of GDDR6 VRAM, and 48 GB of DDR RAM.
The software stack was implemented on top of Ubuntu 22.04 LTS using Python 3.10 and CUDA 12.8 for hardware acceleration. Libraries specific to the infrastructure needs of the pipeline included:
- Machine Learning: XGBoost and LightGBM for classification, along with Scikit-learn and Scikit-optimize (BayesSearchCV) for evaluation and tuning of the model hyperparameters.
- Data Processing: Pandas and NumPy for working with high-dimensional vectors.
- Concurrency: asyncio, threading and joblib for handling asynchronous tasks and parallel extraction of the embeddings.
- Inference: Ollama for communicating with the Large Language Model locally.
4.1. Target LLM Selection
The specific LLM that has been chosen for this experiment is Gemma 3:1B, since it represents the industry’s strategic move towards using Small Language Models (SLMs) on the edge. SLMs are preferred in enterprises, as performing a 1 billion parameter model on the local machine eliminates the threat related to the data security issues of using third-party cloud API services. In terms of security, Gemma 3:1B represents the ideal choice for conducting this experiment.
Smaller models have weaker semantic buffers, making them more susceptible to adversarial prompt injection, jailbreaking, and proportional data poisoning [62,63,64]. Thus, testing this model presents the most severe “worst-case” scenario for proving the effectiveness of the developed guardrails [65]. From the technical point of view, Gemma 3:1B’s architecture is small enough to ensure extremely low latency and to work within 8 GB of VRAM limit of the testing environment.
4.2. Model Optimization and HyperparameterTuning
For the machine learning models LightGBM and XGBoost to perform at their optimal level, Bayesian Optimization was used to fine-tune the algorithms through the BayesSearchCV method. Instead of the conventional grid search method, Bayesian Optimization uses Gaussian process modeling for the search space, thereby enabling the algorithm to learn from previous runs and concentrate only on areas of the search space that can give the most efficient outcome [66].
In the case of both LightGBM and XGBoost, the objective function is set to macro f1-score (f1_macro). The use of this particular function ensures that the algorithm achieves satisfactory performance in both classes, thus giving equal priority to the majority and minority classes to guarantee the highest recall.
4.3. LightGBM Configuration
Table 2.
Hyperparameter search space and rationale.
| Parameter | Range / Value | Rationale |
|---|---|---|
| num_leaves | [20, 100] | Controls the complexity of the leaf-wise tree growth. |
| max_depth | [3, 15] | Limits tree depth to prevent overfitting on specific noise. |
| learning_rate | [0.01, 0.3] | Log-uniform distribution to find the optimal step size. |
| n_estimators | [100, 500] | Number of boosting rounds to allow for sufficient learning. |
| is_unbalance | True | Automatically weighs the minority class to handle dataset skew. |
| boosting | [gbdt, rf] | Evaluates Gradient Boosting Decision Trees versus Random Forest. |
4.4. XGBoost Configuration
In order to make sure that validation is rigorous and avoid overfitting, the Bayesian Optimization was carried out for 25 iterations using the approach of 3-fold stratified cross-validation. In order to achieve reproducibility of experiments, a global random seed value of 42 was used throughout the entire process of sampling, splitting, and optimization. The result of this optimization process was the final configuration of algorithms presented in Table 4.
Table 3.
XGBoost hyperparameter search space and rationale.
| Parameter | Range / Value | Rationale |
|---|---|---|
| max_depth | [3, 10] | Slightly shallower than LightGBM to focus on core features. |
| gamma | [0, 5] | Minimum loss reduction required to make a further partition. |
| min_child_weight | [1, 10] | Prevents the model from creating leaves with very few samples. |
| subsample | [0.5, 1.0] | Fraction of data sampled per tree to introduce randomness. |
| scale_pos_weight | Ratio (0/1) | Custom weight applied to the positive class to combat imbalance. |
Table 4.
Hyperparameter configurations of the machine learning models across different embeddings.
| Model | Embedding | LR | Depth | N | Colsample | Subsample | Alpha () | Lambda () |
|---|---|---|---|---|---|---|---|---|
| LightGBM | MiniLM | 0.30 | 13 | 500 | 0.50 | 0.50 | 10.0 | 10.0 |
| LightGBM | Snowflake | 0.30 | 15 | 500 | 1.00 | 1.00 | 10.0 | 10.0 |
| LightGBM | Granite | 0.30 | 13 | 500 | 1.00 | 0.50 | 10.0 | 10.0 |
| XGBoost | MiniLM | 0.30 | 10 | 300 | 0.50 | 1.00 | 10.0 | 10.0 |
| XGBoost | Snowflake | 0.21 | 10 | 293 | 0.92 | 0.87 | 1.45 | 0.28 |
| XGBoost | Granite | 0.17 | 10 | 300 | 1.00 | 1.00 |
5. Evaluation Metrics
- 1.
-
Accuracy: it helps evaluate classification models. It is a ratio between the number of right predictions and the total number of input samples [67].Where:
- TP: True Positive.
- TN: True Negative.
- FP: False Positive.
- FN: False Negative.
- 2.
- Precision: it tries to recognize the number of positive predictions that were error-free [68].
- 3.
- Sensitivity: It measures the model’s ability to predict positive samples accurately [69].
- 4.
- Specificity: Specificity helps to determine the test’s ability to correctly classify safe prompts as unsafe or possible attack [70].
6. Results
6.1. Data Sanitization and Hardware Profiling
The initial sanitization process yielded a stratified test set of 93,398 prompts, with a real-world class imbalance of 77.8% safe and 22.1% unsafe inputs. The hardware profiling results verified the efficiency of the architecture; average CPU usage was 7.2%, while average GPU usage was 6.43%. Neither the CPU nor the GPU was a bottleneck during execution, and accuracy showed absolutely no degradation (89.24%) at 95th-percentile GPU heat levels (61.0°C).
Of particular interest is the analysis of dropout cases (Figure 2), which indicated occasional errors during the tokenization stage due to non-standard Unicode characters and dense code blocks in specific models, where the Granite model dropped 2,072, the MiniLM model dropped 5,525, and the Snowflake model dropped 8,427. It is important to note that no case occurred where all three models experienced tokenization failures simultaneously.
It is important to note that there was never a case where the three embedding models encountered tokenization problems at once. This is not to say that such a guarantee is architecturally enforced, but it is important to recognize the operational benefit that comes from spreading out parsing among different tokenizers; the system is more robust against failure.
6.2. Model Performance
Six sub-models’ independent predictive accuracy was assessed in order to set a benchmark. The hyperparameters were finely tuned, with the LightGBM architecture tending towards deeper decision tree depths (13–15) coupled with a high learning rate (0.30), which was offset by regularization, whereas for XGBoost, it was the other way around.
As seen from Figure 3, each individual model was able to score an accuracy rate of between 85% and 88%. It becomes apparent that there was a clear behavioral pattern among the two algorithms; while LightGBM algorithms focused on the need for safety with high sensitivity/recall rates (80.40% when using Granite), the XGBoost algorithm emphasized user convenience by having a high specificity rate (92.53% when using MiniLM).
Figure 4 presents the baseline performance of the six individual sub-models, emphasizing the obvious behavioral divide between the two classification algorithms. First, Snowflake XGBoost emerges as the most accurate standalone sub-model with an accuracy of 87.8%, thus making it the most balanced one. But the key aspect of the comparison is the relationship between the False Positive Rate (FPR) and False Negative Rate (FNR). All of the XGBoost models demonstrate themselves as conservative classifiers; they ensure good user experience through lower FPR (with a pipeline-best rate of 7.5% for MiniLM XGBoost), but suffer from higher FNR, thus, making the system susceptible to threat misclassification (up to 33.6%). In turn, the LightGBM models are sufficiently sensitive to security. They provide consistently low False Negative Rate to capture as many threats as possible (the best pipeline result of 19.6% is achieved by Granite LightGBM), but at the cost of a higher FPR (up to 13.1%). This sharp difference directly demonstrates the need for an ensemble approach, since no single model can balance both metrics.
6.3. Ensemble Dynamics and Voting Behavior
The confidence-based routing technique helped to improve the performance of the predictive power of the aggregate models. Figure 5 shows that the aggregated model had an accuracy of 89.23%, which was better than that of any of its components (i.e., Snowflake XGBoost at 87.80%).
Partial Vote (< 6 Active): This denotes infrastructural degradation in terms of the system’s fault tolerance. The presence of non-standard Unicode characters and dense code blocks leads to one or more embedding tokenizers ignoring the prompt (e.g., Snowflake discarding 8,427 prompts), which forces the ensemble to vote using an incomplete set of classifiers. The accuracy rate becomes 82.0% when the prompt is ignored, not because the classifiers are confused, but because the system temporarily loses some of its representational semantic capacity. Split Vote (Conflict): This case involves algorithmic degradation due to classifier disagreement. In such a case, the infrastructure is completely operational as all six models process the prompt, but the prompt in question is too ambiguous or is adversarially obfuscated, leading to a 3-3 or 4-2 vote split. The accuracy rate falls dramatically to 72.3% due to the linguistic camouflage breaking the classifier consensus.
The consensus margin was highly predictive of prediction quality. Unanimous consensus saw an increase in the accuracy score of 95.10%, whereas, in a situation where there is no agreement, the accuracy score dropped to 72.32%. Entropy analysis was conducted, and the results show that the predictions that were made correctly had very low entropy (0.2628), while wrong predictions had a high entropy score of 0.6534.
Performance analysis of the Ensemble Baseline model over the test set with samples demonstrates outstanding predictive ability and acceptable risk balance for quick and proper identification of safe activities. With regard to 72,694 actual benign requests, the classifier identified 68,410 samples as Safe (True Negatives), which resulted in the relatively low False Positive Rate (FPR) of 5.89% (), which is illustrated in Figure 7A. The low level of FPR indicates the operability of the Guardrails principle as it enables avoiding excessive impact on the benign activities of users. The classifier successfully identified 14,930 malicious examples as Unsafe (True Positives) among a total of 20,704 malicious activity examples, yielding a Recall (Sensitivity) of 72.11% and a Precision of 77.70%. Altogether 5,774 malicious inputs managed to evade the baseline protection (False Negatives), which led to the evasion rate of 6.18% across the whole data collection. On average, the baseline classifier demonstrated a global Accuracy of 89.23% and an F1-score of 0.7481. This provides a good empirical starting point, given high accuracy for legitimate traffic and clear optimization targets.
The sensitivity analysis of the parameter confirms the correctness of the selected threshold. Applying only unanimous decisions for the Fast Route () allowed achieving a minimal increase in accuracy (95.10%), while the rest of 11,667 active 5:1 votes would be sent via Llama Guard 3, which results in the total delay cost of about 8,400 seconds. Reducing the threshold value to the level at which 4:2 weak majorities could be used () would expose the entire system to higher mathematical entropy (0.6534) due to adversarial decisions, resulting in reduced precision. Hence, is the optimal mathematical border between efficiency and security.
6.4. Bidirectional Verification and Vulnerability Analysis
The conclusion drawn from the analysis of intercepted attacks justifies the use of the Bidirectional Verification paradigm. As seen in Figure 6, while the Input Guard Rail succeeded in detecting most attacks (particularly Violent Crimes and Intellectual Property attacks), it was not entirely foolproof.
The secondary output guardrail stopped 1,359 instances of malicious inputs that the primary guardrail did not stop at the input stage. In the absence of such a bidirectional filter, these successful injections could penetrate the system and cause “silent failures.”
An analysis of the system’s weaknesses showed that there were 1,987 false negatives (19.7% of all errors) that the ensemble failed to recognize despite a very high level of certainty (). The high level of consensus led to low entropy in these inputs; hence, they evaded the protection offered by the Llama Guard 3 system.
Although Gemma 3:1B was deliberately chosen as the "worst case" subject for testing, as an inevitable result of using SLMs in this experiment, we have to admit that this method constrains the generalization of the bi-directional intercepting rates to the more robust models. Naturally, the generative behaviors and types of failures would differ when using enterprise-level systems. But since the Llama Guard 3 output validation mechanism depends solely on violations of semantic policies and has nothing to do with the architecture of the LLM, we can conclude that the stability of the bi-directional safeguard should remain theoretical regardless of the LLMs used.
6.5. End-to-End Pipeline Performance
Although the ensemble baseline provided an accurate performance of 89.23%, the real efficiency of the proposed system can be proven by considering the complete end-to-end pipeline. The baseline figures (Figure 7A) only demonstrate the performance of the main input layer before the interference of the confidence-based routing and bidirectional guardrails. By routing the ambiguous inputs () to the Llama Guard 3 expert model, the system managed to resolve the issues related to the algorithms that affected the split vote accuracy. In addition, the second filter was able to capture an additional 1,359 malware samples that managed to escape the first round of classification.
As seen in Figure 7B, in which the end-to-end confusion matrix is shown, there has been a considerable increase in performance by our system over the baseline one. The end-to-end pipeline accuracy went up from 89.23% to 90.69% while the overall system Recall (also known as Sensitivity) increased from 72.11% to 78.68%. It is especially worth noting that the Final FPR has stayed at 5.89%, confirming that the incorporation of the Llama Guard 3 additional layers has managed to boost the system’s resilience to silent failures.
7. Conclusions
The findings obtained in this study confirm the effectiveness of the multi-layered defense architecture proposed here and provide unambiguous answers to the three main research questions motivating the current study.
- RQ1: How will the integration of a multi-vector representation approach with a voting-based routing method influence the efficiency of prompt injection detection? The use of multi-vector semantic diversity definitely addressed the problem of a single point of failure associated with single embedding model approaches. Whereas individual tokenizers were dropping thousands of requests because of complex Unicode/complexity, the tri-model redundancy approach did not allow any simultaneous drops among 93,398 prompts, thus assuring fault tolerance of the system. Also, the voting-based routing algorithm helped to overcome the challenge of trade-off between base rate fallacy (the challenge of finding the balance between security and usability) by making LightGBM and XGBoost classifiers, which were exhibiting opposite behavior, vote for their decisions. As a result, the system showed an outstandingly low FPR of 5.89%, while keeping the pipeline efficient by employing Llama Guard 3 only for ambiguous () inputs.
- RQ2: Will a two-way verification approach (input and output filtering) be able to deal with "silent failures," should the input guardrails be circumvented? The threat assessment clearly highlighted that one-layered input filters were not enough for the prevention of adaptive prompt injections. As a result of interception of 1,359 attacks on the output layer—attacks which had managed to bypass the main ensemble filter—the two-way verification process became absolutely necessary in dealing with “silent failures”.
- RQ3: Is it possible to design an effective prompt injection protection mechanism using only open-source models? Empirical evidence from this study proves that enterprise-level security for language models does not have to rely on proprietary and black-box APIs. As a result of leveraging exclusively open source embedding models with sub-billion parameters (Snowflake, IBM Granite, MiniLM) in conjunction with tree-based classifiers (XGBoost, LightGBM) and an open weight expert model (Llama Guard 3), the system managed to achieve the accuracy rate of 90.69%. That shows that companies can build an efficient privacy-preserving defense mechanism solely on their local edge devices.
Production deployment of LLMs requires the ability to provide protection mechanisms that can withstand adversarial attacks in the form of complex prompt injections without compromising fundamental functionalities. The current research confirms that depending only on single detection models is insufficient to provide effective security against adversarial attacks within an enterprise. Experimental outcomes confirm that although embedding models possess inherent weaknesses, namely, their inability to process some prompt queries owing to tokenizer issues or API timeouts, the multi-vector solution developed within this work demonstrated high empirical fault resilience. Although the system misclassified 10,059 inputs, the 93,398 input prompts tested successfully without leading to a system crash, thus guaranteeing a continuous process despite some tokenizers failing.
Apart from physical redundancy, the model relies on behavioral diversity. The design takes advantage of the conflicting nature of the different approaches through the combination of the highly-sensitive Granite classifier (80.40% recall) and the conservative MiniLM+XGBoost approach (92.53% specificity). This way, by using mathematics to combine the conflicting models, the ensemble is able to get an 90.69% accuracy. Notably, this routing mechanism helps address the security vs. usability dilemma, which is prevalent among many single-layer defense strategies [2]. In contrast to the 13.08% false positives of a singular model such as Granite+LightGBM, the ensemble reduces this figure to 5.89%.
Implementation of the second triage level with the Llama Guard 3 was impressively successful. Similar to hybrid constitutional filtering systems [12], sending such prompts to this model introduced a very small delay of 0.72 seconds. The double check not only managed to stop the threats classified as S1 (toxic) on the input side, but also filtered out jailbroken responses at the output side. Therefore, this double filtering not only prevents abuse directly, but also reduces any potential repercussions from compromising the model’s operational parameters.
Though highly accurate predictions—with no decline observed whatsoever, even when subjected to severe GPU temperatures (61.0°C)—are achieved by the system, it still faces some restrictions, imposed not by the system itself, but by its external surroundings. The absence of a relationship between the prompt length and processing duration suggests that the 95th-percentile latency peaks (12.08 seconds) are caused not by computing, but by the network delay and rate limiting issues.
8. Future Research
Even with such a well-established architecture for security, the fast-changing nature of the attacks calls for continuous improvement within three core areas:
Overcoming “Confidently Wrong” Consensus: The main weakness of the proposed framework can be seen in the way in which highly advanced adversarial prompts can fool the entire model by leading to a wrong consensus, with low entropy. Future research on the matter should move beyond the realm of semantic embedding analysis, and also include internal monitoring of behavioral states (hidden states, activations, etc.), to pinpoint any irregularities caused by the processing of mathematical inputs. Specialized Routing: Moving on from general expertise towards domain-specific expertise is one way to significantly improve the security of the system. In the future, research should look into training the ensemble node with specialized instructions regarding particular contexts, such as financial data manipulation, privacy leaks, and code injection attacks. Infrastructure Optimization: In order to remove the unwanted tail latency due to network congestion, future efforts should assess the feasibility of using fully local, heavily quantized embeddings and classification models at the edge. By changing this architecture to an event-driven edge runtime environment, any dependency on API will be removed, making the multi-layer architecture a full-fledged protection system for autonomous LLM agents.
Author Contributions
Conceptualization, A.J.-G., H.D. and R.C.; methodology, A.J.-G., H.D. and R.C.; software, A.J.-G. and A.P.-A.; validation, A.J.-G., V.R.-B., and A.P.-A.; formal analysis, A.J.-G. and A.P.-A.; investigation, A.J.-G.; data curation, A.J.-G. and A.P.-A.; writing—original draft preparation, A.J.-G. and A.P.-A.; writing—review and editing, V.R.-B., H.D., R.C. and A.P.-A.; visualization, A.J.-G. and A.P.-A.; supervision, A.P.-A., V.R.-B., H.D. and R.C. All authors have read and agreed to the published version of the manuscript.
Data Availability Statement
The dataset used in this study is publicly available. The dataset and accompanying code can be accessed at https://github.com/AhsanAyub/malicious-prompt-detection. No new primary data were created during this study.
Acknowledgments
This work has been funded by Cátedra UNESCO “Tecnologías de apoyo para la Inclusión Educativa” initiative, and the Research Group on Artificial Intelligence and Assistive Technologies (GI-IATa) of the Universidad Politécnica Salesiana, Campus Cuenca.
References
- Xu, H.; Kim, Y.J.; Sharaf, A.; Awadalla, H.H. A Paradigm Shift in Machine Translation: Boosting Translation Performance of Large Language Models. arXiv 2024, arXiv:cs.CL/2309.11674. [Google Scholar]
- Ramakrishnan, B.; Balaji, A. Securing AI Agents Against Prompt Injection Attacks. arXiv 2025, arXiv:cs.CR/2511.15759. [Google Scholar]
- Wen, T.; Wang, C.; Yang, X.; Tang, H.; Xie, Y.; Lyu, L.; Dou, Z.; Wu, F. Defending against Indirect Prompt Injection by Instruction Detection. arXiv 2025, arXiv:cs.CR/2505.06311. [Google Scholar]
- Chen, S.; Zharmagambetov, A.; Mahloujifar, S.; Chaudhuri, K.; Wagner, D.; Guo, C. SecAlign: Defending Against Prompt Injection with Preference Optimization. In Proceedings of the Proceedings of the 2025 ACM SIGSAC Conference on Computer and Communications Security, New York, NY, USA, 2025; CCS ’25, pp. 2833–2847. [Google Scholar] [CrossRef]
- Samonte, M.J.C.; Aparize, J.E.R.; Gonzales, E.J.S.; Morilla, J.L. Data Breach Prevention in AI Systems: Employing Event-Driven Architecture to Combat Prompt Injection Attacks in Chatbots. In Proceedings of the 2024 IEEE 12th International Conference on Information, Communication and Networks (ICICN), 2024; pp. 626–632. [Google Scholar] [CrossRef]
- Yao, H.; Shi, H.; Chen, Y.; Jiang, Y.; Wang, C.; Qin, Z. ControlNET: A Firewall for RAG-based LLM System. arXiv 2025, arXiv:cs.CR/2504.09593. [Google Scholar]
- Wang, Z.; Nagaraja, N.; Zhang, L.; Bahsi, H.; Patil, P.; Liu, P. To Protect the LLM Agent Against the Prompt Injection Attack with Polymorphic Prompt. In Proceedings of the 2025 55th Annual IEEE/IFIP International Conference on Dependable Systems and Networks - Supplemental Volume (DSN-S), Los Alamitos, CA, USA, Jun 2025; pp. 22–28. [Google Scholar] [CrossRef]
- Hung, K.H.; Ko, C.Y.; Rawat, A.; Chung, I.H.; Hsu, W.H.; Chen, P.Y. Attention Tracker: Detecting Prompt Injection Attacks in LLMs, 2025. arXiv arXiv:cs.CR/2411.00348.
- Hu, H.; Chen, P.; Zhao, Y.; Chen, Y. AgentSentinel: An End-to-End and Real-Time Security Defense Framework for Computer-Use Agents. In Proceedings of the Proceedings of the 2025 ACM SIGSAC Conference on Computer and Communications Security, New York, NY, USA, 2025; CCS ’25, pp. 3535–3549. [Google Scholar] [CrossRef]
- Joshi, T.; Naik, V.; Mistry, I.; Mangrulkar, R. Prevention of Prompt Injection Attacks Over Financial Applications Integrated with LLM. In In Proceedings of the 2025 3rd International Conference on Advancement in Computation & Computer Technologies (InCACCT), 2025; pp. 225–230. [Google Scholar] [CrossRef]
- Ayyamperumal, S.G.; Ge, L. Current state of LLM Risks and AI Guardrails. arXiv 2024, arXiv:cs.CR/2406.12934. [Google Scholar]
- Obeidat, I.; Alquran, R.; Mughaid, A.; Obeidat, A. Adding extra security layer to chatGPT: machine learning based model to detect malicious cybersecurity prompts. Clust. Comput. 2025, 28, 795. [Google Scholar] [CrossRef]
- Kharchenko, Vyacheslav.; Illiashenko, Oleg. Diversity for security: case assessment for FPGA-based safety-critical systems. MATEC Web Conf. 2016, 76, 02051. [Google Scholar] [CrossRef]
- Yi, J.; Xie, Y.; Zhu, B.; Kiciman, E.; Sun, G.; Xie, X.; Wu, F. Benchmarking and Defending against Indirect Prompt Injection Attacks on Large Language Models. In Proceedings of the Proceedings of the 31st ACM SIGKDD Conference on Knowledge Discovery and Data Mining V.1, New York, NY, USA, 2025; KDD ’25, pp. 1809–1820. [Google Scholar] [CrossRef]
- Lin, B.; Wang, S.; Qin, Y.; Chen, L.; Mao, X. Give LLMs a Security Course: Securing Retrieval-Augmented Code Generation via Knowledge Injection. In Proceedings of the Proceedings of the 2025 ACM SIGSAC Conference on Computer and Communications Security, New York, NY, USA, 2025; CCS ’25, pp. 3356–3370. [Google Scholar] [CrossRef]
- Shih, Y.K.; Kang, Y.K. Design and Implementation of a Secure RAG-Enhanced AI Chatbot for Smart Tourism Customer Service: Defending Against Prompt Injection Attacks – A Case Study of Hsinchu, Taiwan. arXiv 2025, arXiv:cs.CR/2509.21367. [Google Scholar]
- Tsmindashvili, T.; Kolkhidashvili, A.; Kurtskhalia, D.; Maghlakelidze, N.; Mekvabishvili, E.; Dentoshvili, G.; Shamilov, O.; Gachechiladze, Z.; Saporta, S.; Dachi Choladze, D. Improving LLM Outputs Against Jailbreak Attacks With Expert Model Integration. IEEE Access 2025, 13, 134976–134988. [Google Scholar] [CrossRef]
- Panebianco, F.; Bonfanti, S.; Trovò, F.; Carminati, M. LeakSealer: A Semisupervised Defense for LLMs Against Prompt Injection and Leakage Attacks. arXiv 2025, arXiv:cs.CR/2508.00602. [Google Scholar]
- Piet, J.; Alrashed, M.; Sitawarin, C.; Chen, S.; Wei, Z.; Sun, E.; Alomair, B.; Wagner, D. Jatmo: Prompt Injection Defense by Task-Specific Finetuning. In Proceedings of the Computer Security – ESORICS 2024: 29th European Symposium on Research in Computer Security, Bydgoszcz, Poland, September 16–20, 2024; Proceedings, Part I, Berlin, Heidelberg. 2024; pp. 105–124. [Google Scholar] [CrossRef]
- Cohen, S.; Bitton, R.; Nassi, B. Here Comes the AI Worm: Preventing the Propagation of Adversarial Self-Replicating Prompts Within GenAI Ecosystems. In Proceedings of the Proceedings of the 2025 ACM SIGSAC Conference on Computer and Communications Security, New York, NY, USA, 2025; CCS ’25, pp. 3975–3989. [Google Scholar] [CrossRef]
- Jia, F.; Wu, T.; Qin, X.; Squicciarini, A. The Task Shield: Enforcing Task Alignment to Defend Against Indirect Prompt Injection in LLM Agents. arXiv 2024, arXiv:cs.CR/2412.16682. [Google Scholar]
- Kang, M.; Xiang, C.; Kariyappa, S.; Xiao, C.; Li, B.; Suh, E. Mitigating Indirect Prompt Injection via Instruction-Following Intent Analysis. arXiv 2025, arXiv:cs.CR/2512.00966. [Google Scholar]
- Liu, Y.; Jia, Y.; Jia, J.; Song, D.; Gong, N.Z. DataSentinel: A Game-Theoretic Detection of Prompt Injection Attacks. In Proceedings of the 2025 IEEE Symposium on Security and Privacy (SP), Los Alamitos, CA, USA, May 2025; pp. 2190–2208. [Google Scholar] [CrossRef]
- Jacob, D.; Alzahrani, H.; Hu, Z.; Alomair, B.; Wagner, D. PromptShield: Deployable Detection for Prompt Injection Attacks. In Proceedings of the Proceedings of the Fifteenth ACM Conference on Data and Application Security and Privacy, New York, NY, USA, 2025; CODASPY ’25, pp. 341–352. [Google Scholar] [CrossRef]
- Lee, D.; Xie, S.; Rahman, S.; Pat, K.; Lee, D.; Chen, Q.A. "Prompter Says": A Linguistic Approach to Understanding and Detecting Jailbreak Attacks Against Large-Language Models. In Proceedings of the Proceedings of the 1st ACM Workshop on Large AI Systems and Models with Privacy and Safety Analysis, New York, NY, USA, 2024; LAMPS ’24, pp. 77–87. [Google Scholar] [CrossRef]
- Zhang, X.; Zhang, C.; Li, T.; Huang, Y.; Jia, X.; Hu, M.; Zhang, J.; Liu, Y.; Ma, S.; Shen, C. JailGuard: A Universal Detection Framework for Prompt-based Attacks on LLM Systems. ACM Trans. Softw. Eng. Methodol. 2025, 35. [Google Scholar] [CrossRef]
- Omri, S.; Abdelkader, M.; Hamdi, M. MalPID: Malicious Prompt Injection Detection Dataset for Large Language Model based Applications. In Proceedings of the 2024 IEEE Eleventh International Conference on Communications and Networking (ComNet), 2024; pp. 1–5. [Google Scholar] [CrossRef]
- Shi, L.; Kang, Y.; Hu, J.; Li, X.; Yang, M. Meticulous Thought Defender: Fine-Grained Chain-of-Thought (CoT) for Detecting Prompt Injection Attacks of Large Language Models. IEEE Access 2025, 13, 113194–113207. [Google Scholar] [CrossRef]
- Li, L.; Gao, X.; Wang, X.; Zhao, J.; Ye, K. StreamGuard: A Streaming-Based Defense Against Jailbreaking Attacks in Large Language Models. In Proceedings of the Neural Information Processing; Taniguchi, T., Leung, C.S.A., Kozuno, T., Yoshimoto, J., Mahmud, M., Doborjeh, M., Doya, K., Eds.; Singapore, 2026; pp. 301–316. [Google Scholar]
- Cao, B.; Li, C.; Cao, Y.; Ge, Y.; Wang, T.; Chen, J. You Can’t Steal Nothing: Mitigating Prompt Leakages in LLMs via System Vectors. In Proceedings of the Proceedings of the 2025 ACM SIGSAC Conference on Computer and Communications Security, New York, NY, USA, 2025; CCS ’25, pp. 4423–4437. [Google Scholar] [CrossRef]
- Lan, Q.; Kaul, A.; Jones, S.; Westrum, S.; Pandurangan, V.; Das Pattanaik, N.K.; Pattanayak, P. Hybrid Constitutional Classifiers for Prompt Injection Defense. In Proceedings of the 2025 IEEE International Conference on Electro Information Technology (eIT), 2025; pp. 225–229. [Google Scholar] [CrossRef]
- Ji, Y.; Li, R.; Mao, B. Detection Method for Prompt Injection by Integrating Pre-trained Model and Heuristic Feature Engineering. In Proceedings of the Knowledge Science, Engineering and Management; Zhu, T., Zhou, W., Zhu, C., Eds.; Singapore, 2026; pp. 66–73. [Google Scholar]
- Muliarevych, O. Enhancing System Security: LLM-Driven Defense Against Prompt Injection Vulnerabilities. In Proceedings of the 2024 IEEE 17th International Conference on Advanced Trends in Radioelectronics, Telecommunications and Computer Engineering (TCSET), 2024; pp. 420–423. [Google Scholar] [CrossRef]
- Ayub, M.A.; Majumdar, S. Embedding-based classifiers can detect prompt injection attacks. arXiv 2024, arXiv:cs.CR/2410.22284. [Google Scholar]
- Astari, R.A.; Sumertajaya, I.; Soleh, A.M. A Hybrid Sampling Approach for Handling Data Imbalance in Ensemble Learning Algorithms. Sci. J. Inform. 2025. [Google Scholar] [CrossRef]
- Jang, Y. Feature-based ensemble modeling for addressing diabetes data imbalance using the SMOTE, RUS, and random forest methods: a prediction study. Ewha Med. J. 2025, 48. [Google Scholar] [CrossRef]
- Fulazzaky, T.; Saefuddin, A.; Soleh, A.M. Evaluating Ensemble Learning Techniques for Class Imbalance in Machine Learning: A Comparative Analysis of Balanced Random Forest, SMOTE-RF, SMOTEBoost, and RUSBoost. Sci. J. Inform. 2024. [Google Scholar] [CrossRef]
- Tan, J.J.; Kwan, B.H.; Ng, D.W.K.; Hum, Y. Adaptive focal loss with personality stratification for stably mitigating hard class imbalance in multi-dimensional personality recognition. Sci. Rep. 2025, 15. [Google Scholar] [CrossRef]
- Miao, N.; Yang, M.; Han, P.; Qiao, J.; Che, Z.; Xu, F.; Dai, X.; Zhu, M. A new ensemble learning method stratified sampling blending optimizes conventional blending and improves prediction performance. Bioinform. Adv. 2025, 5. [Google Scholar] [CrossRef]
- Toleva, B. Is There a Preferred Cross-Validation Type for Train/Test Split in Imbalanced Classification. Appl. Comput. Intell. Soft Comput. 2026, 2026, 6832228. http://arxiv.org/abs/https://onlinelibrary.wiley.com/doi/pdf/10.1155/acis/6832228. [CrossRef]
- Merrick, L.; Xu, D.; Nuti, G.; Campos, D. Arctic-Embed: Scalable, Efficient, and Accurate Text Embedding Models. arXiv 2024, arXiv:cs.CL/2405.05374. [Google Scholar]
- Awasthy, P.; Trivedi, A.; Li, Y.; Bornea, M.; Cox, D.; Daniels, A.; Franz, M.; Goodhart, G.; Iyer, B.; Kumar, V.; et al. Granite Embedding Models. arXiv 2025, arXiv:cs.IR/2502.20204. [Google Scholar]
- Wang, W.; Bao, H.; Huang, S.; Dong, L.; Wei, F. MiniLMv2: Multi-Head Self-Attention Relation Distillation for Compressing Pretrained Transformers. arXiv 2021, arXiv:cs.CL/2012.15828. [Google Scholar]
- Flad, L.; Leyer, M.; Nitz, F.; Krawutschke, T. A Comprehensive Survey of Redundancy Systems with a Focus on Triple Modular Redundancy (TMR). arXiv 2026, arXiv:abs/2603.14411. [Google Scholar] [CrossRef]
- Caro, M.; Brando, A.; Abella, J. Semantic Diverse DMR and TMR for High-Integrity AI-Based Function Efficiency. ACM Trans. Cyber-Phys. Syst. 2025, 9, 1–26. [Google Scholar] [CrossRef]
- Soroush, K.; Shirazi, N.; Raji, M. Efficient Triple Modular Redundancy for Reliability Enhancement of DNNs Using Explainable AI. arXiv 2025, arXiv:abs/2507.08829. [Google Scholar] [CrossRef]
- Saikawa, Y.; Tomioka, Y. Approximated Triple Modular Redundancy of Convolutional Neural Networks Based on Residual Quantization. In 2024 IEEE 17th International Symposium on Embedded Multicore/Many-core Systems-on-Chip (MCSoC); 2024; pp. 302–309. [Google Scholar] [CrossRef]
- Shwartz-Ziv, R.; Armon, A. Tabular Data: Deep Learning is Not All You Need. arXiv 2021, arXiv:abs/2106.03253. [Google Scholar] [CrossRef]
- Chen, T.; Guestrin, C. XGBoost: A Scalable Tree Boosting System. In Proceedings of the Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, New York, NY, USA, 2016; KDD ’16, pp. 785–794. [Google Scholar] [CrossRef]
- Ke, G.; Meng, Q.; Finley, T.; Wang, T.; Chen, W.; Ma, W.; Ye, Q.; Liu, T.Y. LightGBM: a highly efficient gradient boosting decision tree. In Proceedings of the Proceedings of the 31st International Conference on Neural Information Processing Systems, Red Hook, NY, USA, 2017; NIPS’17, pp. 3149–3157. [Google Scholar]
- Polikar, R. Ensemble based systems in decision making. IEEE Circuits Syst. Mag. 2006, 6, 21–45. [Google Scholar] [CrossRef]
- Chakir, O.; Rehaimi, A.; Sadqi, Y.; Alaoui, E.; Krichen, M.; Gaba, G.S.; Gurtov, A. An empirical assessment of ensemble methods and traditional machine learning techniques for web-based attack detection in industry 5.0. J. King Saud Univ. Comput. Inf. Sci. 2023, 35, 103–119. [Google Scholar] [CrossRef]
- Sléher, R.; Brach, W.; Sloboda, T.; Košťál, K.; Galke, L. Guarded Query Routing for Large Language Models. arXiv 2025, arXiv:abs/2505.14524. [Google Scholar] [CrossRef]
- Bonab, H.; Can, F. Less Is More: A Comprehensive Framework for the Number of Components of Ensemble Classifiers. IEEE Trans. Neural Netw. Learn. Syst. 2017, 30, 2735–2745. [Google Scholar] [CrossRef]
- Zhu, X.; Xia, P.; He, Q.; Ni, Z.; Ni, L. Ensemble Classifier Design Based on Perturbation Binary Salp Swarm Algorithm for Classification. Comput. Model. Eng. Sci. 2022. [Google Scholar] [CrossRef]
- Du, K.L.; Zhang, R.; Jiang, B.; Zeng, J.; Lu, J. Foundations and Innovations in Data Fusion and Ensemble Learning for Effective Consensus. Mathematics 2025. [Google Scholar] [CrossRef]
- Wu, S.; Li, J.; Ding, W. A geometric framework for multiclass ensemble classifiers. Mach. Learn. 2023, 112, 4929–4958. [Google Scholar] [CrossRef]
- Assiri, A.S.; Nazir, S.; Velastin, S.A. Breast Tumor Classification Using an Ensemble Machine Learning Method. J. Imaging 2020, 6. [Google Scholar] [CrossRef]
- Singh, P.; Hasija, T.; Bharany, S.; Naeem, H.N.T.; Rao, B.C.; Hussen, S.; Rehman, A.U. An ensemble-driven machine learning framework for enhanced water quality classification. Discov. Sustain. 2025, 6, 552. [Google Scholar] [CrossRef]
- Yi, S.; Liu, Y.; Sun, Z.; Cong, T.; He, X.; Song, J.; Xu, K.; Li, Q. Jailbreak Attacks and Defenses Against Large Language Models: A Survey. arXiv 2024, arXiv:cs.CR/2407.04295. [Google Scholar]
- Shen, X.; Chen, Z.; Backes, M.; Shen, Y.; Zhang, Y. Do Anything Now": Characterizing and Evaluating In-The-Wild Jailbreak Prompts on Large Language Models. In Proceedings of the Proceedings of the 2024 on ACM SIGSAC Conference on Computer and Communications Security, New York, NY, USA, 2024; CCS ’24, pp. 1671–1685. [Google Scholar] [CrossRef]
- Zhang, W.; Xu, H.; Wang, Z.; He, Z.; Zhu, Z.; Ren, K. Can Small Language Models Reliably Resist Jailbreak Attacks? A Comprehensive Evaluation. arXiv 2025, arXiv:cs.CR/2503.06519. [Google Scholar]
- Yi, S.; Cong, T.; He, X.; Li, Q.; Song, J. Beyond the Tip of Efficiency: Uncovering the Submerged Threats of Jailbreak Attacks in Small Language Models. In Proceedings of the Findings of the Association for Computational Linguistics: ACL 2025; Che, W., Nabende, J., Shutova, E., Pilehvar, M.T., Eds.; Vienna, Austria, 2025; pp. 17221–17234. [Google Scholar] [CrossRef]
- Qi, X.; Zeng, Y.; Xie, T.; Chen, P.Y.; Jia, R.; Mittal, P.; Henderson, P. Fine-tuning Aligned Language Models Compromises Safety, Even When Users Do Not Intend To! arXiv 2023, arXiv:cs.CL/2310.03693. [Google Scholar]
- Yi, S.; Liu, Y.; Sun, Z.; Cong, T.; He, X.; Song, J.; Xu, K.; Li, Q. Jailbreak Attacks and Defenses Against Large Language Models: A Survey. arXiv 2024, arXiv:cs.CR/2407.04295. [Google Scholar]
- Snoek, J.; Larochelle, H.; Adams, R.P. Practical Bayesian Optimization of Machine Learning Algorithms. arXiv 2012, arXiv:stat.ML/1206.2944. [Google Scholar]
- Chen, C.C.; Li, S.T. Credit rating with a monotonicity-constrained support vector machine model. Expert Syst. With Appl. 2014, 41, 7235–7247. [Google Scholar] [CrossRef]
- Cano, J.R.; Gutiérrez, P.A.; Krawczyk, B.; Woźniak, M.; García, S. Monotonic classification: An overview on algorithms, performance measures and data sets. Neurocomputing 2019, 341, 168–182. [Google Scholar] [CrossRef]
- Saito, T.; Rehmsmeier, M. The Precision-Recall Plot Is More Informative than the ROC Plot When Evaluating Binary Classifiers on Imbalanced Datasets. PLoS ONE 2015, 10, 1–21. [Google Scholar] [CrossRef]
- Kovács, A.; Palásti, P.; Veréb, D.; Bozsik, B.; Palkó, A.; Kincses, Z.T. The sensitivity and specificity of chest CT in the diagnosis of COVID-19. Eur. Radiol. 2021, 31, 2819–2824. [Google Scholar] [CrossRef]
Figure 1.
Final system overview.

Figure 2.
Embedding model’s dropout.

Figure 3.
Performance metrics by each combination of Embedding model and ML classifier.

Figure 4.
Performance comparison of individual embedding and classifier combinations, evaluated by Accuracy, False Positive Rate, and False Negative Rate.
Figure 4.
Performance comparison of individual embedding and classifier combinations, evaluated by Accuracy, False Positive Rate, and False Negative Rate.

Figure 5.
Ensemble results.

Figure 6.
Top 5 Threat Categories Intercepted.

Figure 7.
Confusion matrices for (A) the ensemble baseline and (B) the full end-to-end pipeline with bidirectional Llama Guard 3 filtering (). Values indicate sample counts and dataset percentages. The integrated architecture intercepts an additional 1,359 malicious payloads, reducing False Negatives by 23.5% without elevating false alarms.
Figure 7.
Confusion matrices for (A) the ensemble baseline and (B) the full end-to-end pipeline with bidirectional Llama Guard 3 filtering (). Values indicate sample counts and dataset percentages. The integrated architecture intercepts an additional 1,359 malicious payloads, reducing False Negatives by 23.5% without elevating false alarms.

Table 1.
Comparison of existing LLM defense frameworks and the proposed method.
| Framework | Defense Technique | Verification Scope | Model Dependency | Key Limitation |
|---|---|---|---|---|
| SecAlign | Direct Preference Optimization (DPO) | Input | White-Box | Relies on explicit delimiters; vulnerable to data-less jailbreaks. |
| PromptShield | Threshold-Calibrated Classification | Input | Open-Source | Susceptible to evolving attack patterns (concept drift). |
| BIPIA | Adversarial Fine-Tuning | Input | White-Box | Highly dependent on predefined boundary tokens. |
| SysVec | Representation Engineering (Vectorization) | Input | White-Box | Requires intrusive access to internal hidden layers. |
| DataSentinel | Game-Theoretic Minimax Optimization | Input | Open-Source | Requires continuous retraining against adaptive adversaries. |
| StreamGuard | Real-Time Self-Review (In-Generation) | Output | Open-Source | Introduces high latency overhead during token generation. |
| Hybrid Classifiers | Dual-Stage Distillation | Bidirectional | Open-Source | High computational cost due to sequential LLM evaluations. |
| LeakSealer | Semantic Fingerprinting & Clustering | Bidirectional | Model-Agnostic | Dependent on historical server logs for static usage mapping. |
| Proposed Method | Multi-Vector Ensemble & Confidence Routing | Bidirectional | Open-Source | Resolves latency via adaptive routing; mitigates single-point failures. |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2026 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license.
Copyright: This open access article is published under a Creative Commons CC BY 4.0 license, which permit the free download, distribution, and reuse, provided that the author and preprint are cited in any reuse.