The Mirror Design Pattern: Strict Data Geometry over Model Scale for Prompt Injection Detection
Abstract
Prompt injection defenses are often framed as semantic understanding problems and delegated to increasingly large neural detectors. For the first screening layer, however, the requirements are different: the detector runs on every request and therefore must be fast, deterministic, non-promptable, and auditable. We introduce Mirror, a data-curation design pattern that organizes prompt injection corpora into matched positive and negative cells so that a classifier learns control-plane attack mechanics rather than incidental corpus shortcuts. Using 5,000 strictly curated open-source samples -- the largest corpus supportable under our public-data validity contract -- we define a 32-cell mirror topology, fill 31 of those cells with public data, train a sparse character n-gram linear SVM, compile its weights into a static Rust artifact, and obtain 95.97% recall and 92.07% F1 on a 524-case holdout at sub-millisecond latency with no external model runtime dependencies. On the same holdout, our next line of defense, a 22-million-parameter Prompt Guard~2 model reaches 44.35% recall and 59.14% F1 at 49,ms median and 324,ms p95 latency. Linear models still leave residual semantic ambiguities such as use-versus-mention for later pipeline layers, but within that scope our results show that for L1 prompt injection screening, strict data geometry can matter more than model scale.
Figures & tables
| Checkpoint | What changed | Role in argument |
|---|---|---|
| v2 19k train / 2.4k holdout | Initial Mirror baseline | Geometry baseline (0.835 F1); paired with v3 to isolate the effect of data quality |
| v3 19k locked / 1.9k holdout | Source locking and provenance cleanup; model family held fixed | Geometry proof point: 0.918 0.926 F1 from data discipline alone |
| v5 5k curated / 524 holdout | Strict multilingual validity contract; 31/32 cell closure | Headline result: 0.921 F1 / 0.960 recall; direct PG2 comparison |
| Mirror : Non-mirror | Holdout F1 (mean std) |
|---|---|
| 100:0 | |
| 70:30 | |
| 50:50 | |
| 30:70 | |
| 0:100 |
| Protocol item | Setting |
|---|---|
| Holdout artifact | 524 cases total: 248 malicious, 276 benign |
| Split discipline | Holdout carved and frozen before training; training and evaluation are enforced content-hash disjoint |
| Evaluation preprocessing | L0 sanitization enabled at evaluation time for all compared detectors |
| Holdout composition | The 524-case holdout spans the same four-language, eight-reason task space as the training corpus, though not with uniform occupancy |
| Confidence intervals | 95% bootstrap intervals with 10,000 resamples over the 524-case holdout |
| Threshold selection | L1 main results at fixed (natural SVM margin cutoff); PG2 evaluated at default thresholds ( pg_threshold=0.5 , block_threshold=0.5 ) |
| Detector | Prec. | Recall | F1 | FP | FN | Latency |
|---|---|---|---|---|---|---|
| L3 regex (75 patterns) | 0.992 | 0.141 | 0.247 | — | — | 1 ms |
| Mirror L1 SVM (5k, ) | 0.885 | 0.960 | 0.921 | 31 | 10 | 1 ms |
| Prompt Guard 2 (22M) | 0.887 | 0.444 | 0.591 | 14 | 138 | 49 ms |