NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Efficient and Adaptable Detection of Malicious LLM Prompts via Bootstrap Aggregation

Shayan Ali Hassan, Tao Ni, Zafar Ayyub Qazi, Marco CaniniarXiv 2026

TL;DR

This paper introduces BAGEL, a novel framework for detecting malicious prompts sent to Large Language Models (LLMs). BAGEL uses an ensemble of smaller, specialized models that can be efficiently updated to counter new threats, achieving high accuracy with significantly fewer parameters than existing solutions. This approach offers a practical and adaptable path to LLM safety, moving away from computationally expensive monolithic models.

What Problem Does This Paper Address?

Large Language Models (LLMs) are increasingly integrated into various applications, but they are vulnerable to malicious prompts designed to elicit harmful or policy-violating behavior. Existing defenses fall into two main categories: black-box moderation APIs (like OpenAI's) which lack transparency and adaptability, and white-box approaches using large LLM judges, which are computationally prohibitive and require expensive retraining for new attacks. This creates a trade-off between performance, efficiency, and adaptability, forcing system designers to compromise. The paper aims to bridge this gap by proposing a solution that is modular, lightweight, and incrementally updatable.

Methods

BAGEL employs a modular, lightweight, and incrementally updatable framework inspired by bootstrap aggregation and mixture-of-experts.

  • Ensemble of Specialized PromptCops: Instead of a single large model, BAGEL uses an ensemble of smaller, fine-tuned "promptcops." Each promptcop is a fine-tuned instance of a base model (Prompt Guard 2, an 86M parameter classifier) trained on a specific type of malicious prompt dataset. This specialization allows for efficient detection of diverse threats.
  • Bootstrap Aggregation with Diverse Datasets: Unlike traditional bagging which uses subsets of the same data, BAGEL trains each promptcop on entirely different datasets representing distinct attack categories. This enhances robustness.
  • Dynamic Routing via Random Forest: A Random Forest classifier acts as a router, analyzing structural features of an incoming prompt (e.g., length, character proportions) to predict the most suitable promptcop for classification. This provides interpretability and initial efficiency.
  • Stochastic Selection and Aggregation: To mitigate potential errors from the router and ensure robustness, BAGEL selects the predicted "ideal" promptcop and then randomly samples a subset of other promptcops. The final prediction is an aggregation of probabilities from this selected subset.
  • Incremental Updates: When new attack datasets emerge, a new promptcop is fine-tuned and added to the ensemble. The router and decision threshold are then retrained, allowing the system to adapt without expensive full-system retraining.

Datasets

The paper utilizes a collection of nine large-scale, real-world datasets for finetuning and evaluation, covering various types of malicious prompts:

  • synapsecai/synthetic-prompt-injections
  • Malicious Prompt Detection Dataset (MPDD)
  • TrustAIRLab/in-the-wild-jailbreak-prompts
  • Harelix/Prompt-Injection-Mixed-Techniques-2024
  • jackhhao/jailbreak-classification
  • qualifire/prompt-injections-benchmark
  • jayavibhav/prompt-injection-safety
  • ToxicDetector Evaluation Dataset
  • guychuk/benign-malicious-prompt-classification

These datasets were aggregated to form a corpus of 839,140 samples, with 20% held out for evaluation.

Key Insights and Ideas

  • "Safety in Depth" through Ensemble Diversity: By training specialized models on distinct attack datasets and combining their predictions, BAGEL achieves a "safety in depth" approach, where different promptcops can compensate for each other's weaknesses.
  • Modularity as a Key to Adaptability: The framework's modular design, where new promptcops can be added incrementally, is crucial for keeping pace with the rapidly evolving landscape of LLM attacks.
  • Interpretability from Structural Features: The use of a Random Forest router based on prompt structural features provides insights into what characteristics are indicative of malicious intent, making the system more transparent and auditable.
  • Efficiency through Subsetting: Selecting a small subset of promptcops (n=5) for inference, rather than the entire ensemble, significantly reduces computational cost while maintaining high performance, validating the efficiency goal.

Key Results

  • High Accuracy with Efficiency: BAGEL achieved an F1 score of 0.922 using an effective 430M parameters (5 promptcops), outperforming black-box APIs like OpenAI Moderation API and white-box baselines like ShieldGemma, which require billions of parameters.
  • Robustness to Evolving Threats: The system maintained robust performance, with F1 scores never dropping below 0.92, even after nine incremental updates simulating the addition of new attack datasets over time.
  • Near-Oracle Performance with Subsetting: The proposed selection strategy (predicted expert + random subset) closely tracked the performance of an "ideal" strategy where the best promptcop is always known, demonstrating the effectiveness of the ensemble and random forest routing.
  • Computational Savings: Selecting just 5 promptcops reduced the computational cost by approximately 45% compared to using the full ensemble, while performance gains from larger subsets were marginal.
  • Interpretable Features: Analysis revealed that features like prompt length, whitespace proportion, and special character proportion are highly indicative of malicious prompts, aiding in understanding and future defense strategies.

Limitations and Future Work

  • Binary Classification Scope: BAGEL currently performs binary classification (benign vs. malicious). Future work could extend this to multi-class classification for finer-grained policy violation identification.
  • Multi-turn Conversation Handling: The current evaluation focuses on single prompts. Future research should investigate BAGEL's effectiveness in moderating multi-turn conversations, where malicious intent can be distributed across turns.
  • Base Model Coverage: While BAGEL adapts well to new attacks, its effectiveness relies on the base model having learned relevant underlying attack classes. The paper acknowledges that fundamentally novel attack paradigms might require more than just fine-tuning.
  • Dataset Requirements: The need for sufficiently large and representative datasets for new attack types presents a challenge for rapid adaptation. Future work could explore few-shot or zero-shot detection capabilities.

Summary updated

BibTeX
@misc{hassan2026efficient,
  author = {Shayan Ali Hassan and Tao Ni and Zafar Ayyub Qazi and Marco Canini},
  title = {{Efficient and Adaptable Detection of Malicious LLM Prompts via Bootstrap Aggregation}},
  year = {2026},
  eprint = {2602.08062},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.08062},
}
Figure