Efficient and Adaptable Detection of Malicious LLM Prompts via Bootstrap Aggregation
Organizations: KAUST · LUMS & KAUST
Abstract
Large Language Models have demonstrated remarkable capabilities in natural language understanding. However, they remain susceptible to malicious prompts that induce unsafe or policy-violating behavior. Existing defenses in black-box moderation APIs offer limited transparency and adapt poorly to evolving threats, while white-box approaches using large LLM judges impose prohibitive computational costs and require expensive retraining for new attacks. We present BAGEL (Bootstrap AGgregated Ensemble Layer), a modular, lightweight, and incrementally updatable framework for malicious prompt detection. BAGEL employs a bootstrap aggregation and mixture-of-experts-inspired ensemble of finetuned models, each specialized on a different attack dataset. At inference, BAGEL aggregates predictions from a stochastically selected subset of ensemble members, optionally augmented by a lightweight learned router that predicts the most suitable member to include. When new attacks emerge, BAGEL updates incrementally by finetuning just a single small classifier (86M parameters) and adding it to the ensemble. We evaluate BAGEL on a held-out, source-disjoint set constructed from datasets never used for training or calibration, ensuring that performance reflects generalization to out-of-distribution attacks. In single-turn evaluation, BAGEL achieves an F1 score of 0.757 at a size equivalent to 430M parameters, improving to 0.772 when augmented with the router using fewer ensemble members (324M parameters). These results outperform popular black-box moderation APIs and most white-box baselines at lower costs. In multi-turn evaluation, BAGEL achieves an F1 score of 0.660, outperforming billion-parameter methods. Our results show ensembles of small finetuned classifiers can match or exceed the performance of billion-parameter guardrails while offering the adaptability and efficiency required for production systems.
Figures & tables
| Method | ASR | FPR | F1 | Bal. Acc. | Parameters | Size Ratio | Fine-tunable? |
| BAGEL | 0.342 | 0.307 | 0.757 | 0.675 | 430M for | ✓ | |
| BAGEL w/ DistilBERT | 0.325 | 0.288 | 0.772 | 0.694 | 324M for | ✓ | |
| ToxicDetector | 0.426 | 0.400 | 0.679 | 0.587 | 300M + 7B | ✓ | |
| StruQ | 0.065 | 0.732 | 0.880 | 0.602 | 7B | ✓ | |
| ShieldGemma | 0.431 | 0.068 | 0.717 | 0.751 | 2B | ✓ | |
| OpenAIModerationAPI | 0.528 | 0.089 | 0.631 | 0.692 | Unknown | - | ✗ |
| Strategy | F1 | ASR | FPR | |
| BAGEL ( ) | Full-Conv. | 0.636 | 0.232 | 0.593 |
| Chunk-Level | 0.625 | 0.117 | 0.862 | |
| Full-Conv. | 0.660 | 0.106 | 0.748 | |
| Chunk-Level | 0.648 | 0.054 | 0.894 | |
| Full-Conv. | 0.704 | 0.155 | 0.508 | |
| Chunk-Level | 0.664 | 0.180 | 0.597 |
Appendix figures & tables4 assets
Supplementary material from the paper’s appendix.
Appendix
| Quantity | Value |
| Weights per promptcop | 1.04 GB |
| Storage, full ensemble ( ) | 9.36 GB |
| Active memory, BAGEL ( ) | 5.20 GB |
| Active memory, BAGEL w/ DistilBERT ( ) | 3.12 GB + router |
| Forward pass per promptcop (batch size 64) | 323.8 ms |
| Throughput per promptcop (batch size 64) | 197.05 samples/s |
| Dataset | Number of Samples | Type of Malicious Prompts | ||
| Simple Harmful | Jailbreak | Injection | ||
| synapsecai/synthetic-prompt-injections ( SynapseCAI, 2024 ) | 252,956 | |||
| Malicious Prompt Detection Dataset (MPDD) ( Jebbar, 2025 ) | 39,234 | |||
| TrustAIRLab/in-the-wild-jailbreak-prompts ( Shen et al., 2024 ) | 13,700 | |||
| Harelix/Prompt-Injection-Mixed-Techniques-2024 ( Harelix, 2024 ) | 1,175 | |||
| jackhhao/jailbreak-classification ( Jack Hao, 2023 ) | 1,042 | |||
| Dataset | Malicious | Benign | Total |
| hlyn-labs/prompt-injection-judge-deberta-dataset ( hlyn, 2026 ) | 484 | 516 | 1,000 |
| allenai/wildjailbreak ( Jiang et al., 2024 ) | 2,000 | 210 | 2,210 |
| LLM Past Tense ( Andriushchenko and Flammarion, 2024 ) | 730 | 0 | 730 |
| Necent/llm-jailbreak-prompt-injection-dataset ( Necent, 2026 ) | 629 | 371 | 1,000 |
| TrustAIRLab/JailbreakQR ( Chu et al., 2025 ) | 400 | 0 | 400 |
| Total | 4,243 | 1,097 | 5,340 |