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
Figure 1: Examples of malicious prompt attack types. The malicious task has been redacted here to prevent direct inclusion of harmful content in this paper.
Figure 2: BAGEL overview, divided into two sections. The larger section details the ensemble selection strategy and probability aggregation. The smaller section details the dataset partitioning, finetuning and addition of a new promptcop to the ensemble during system updates.
Figure 3
Figure 4: F1 before ( k=9 ) and after ( k=10 ) adding a promptcop trained on out-of-distribution data.
Method
ASR ↓
FPR ↓
F1 ↑
Bal. Acc. ↑
Parameters
Size Ratio
Fine-tunable?
BAGEL
0.342
0.307
0.757
0.675
430M for n=5
1.0×
✓
BAGEL w/ DistilBERT
0.325
0.288
0.772
0.694
324M for n=3
0.8×
✓
ToxicDetector
0.426
0.400
0.679
0.587
300M + 7B
17.0×
✓
StruQ
0.065
0.732
0.880
0.602
7B
16.3×
✓
ShieldGemma
0.431
0.068
0.717
0.751
2B
4.7×
✓
OpenAIModerationAPI
0.528
0.089
0.631
0.692
Unknown
-
✗
Table 2: Results of evaluating BAGEL against other methodologies on the held-out test set. Size ratio is each method’s parameter count relative to BAGEL (430M, n=5 ).
Strategy
F1 ↑
ASR ↓
FPR ↓
BAGEL ( k=9 ) n=9n=5n=1
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
Table 3: Multi-turn attack detection performance (ToxicDetector with Chunk-Level is not evaluated due to training incompatibilities).
Appendix figures & tables4 assets
Supplementary material from the paper’s appendix.
Appendix
Quantity
Value
Weights per promptcop
1.04 GB
Storage, full ensemble ( k=9 )
9.36 GB
Active memory, BAGEL ( n=5 )
5.20 GB
Active memory, BAGEL w/ DistilBERT ( n=3 )
3.12 GB + router
Forward pass per promptcop (batch size 64)
323.8 ms
Throughput per promptcop (batch size 64)
197.05 samples/s
Appendix
Table 4: Measured per-promptcop inference cost and resulting memory footprint of BAGEL .
jackhhao/jailbreak-classification ( Jack Hao, 2023 )
1,042
∘
∙
∘
Appendix
Table 5: Collection of the nine datasets we used for single-turn finetuning and calibration. ∙ indicates the dataset contains this specific type of malicious prompts, while ∘ represents the lack of any such type.
Table 6: Collection of the five datasets used to construct the source-disjoint test set T . All 210 benign WildJailbreak prompts come from its adversarial_benign split.
Figure 5: Pairwise Jensen-Shannon divergence between the nine training datasets and the five OOD test datasets. Prompts are embedded with all-mpnet-base-v2 , the shared embedding space is partitioned into 50 clusters via k -means, and each dataset’s distribution is represented as its normalized histogram of prompts per cluster. Darker cells indicate greater distributional similarity between a pair of datasets.