The layers I put in front of agents A developer built BleedStop, a layered prompt-injection defence that stacks a phrase-list filter, a DeBERTa classifier served via FastAPI, and an optional 8-bit ONNX sidecar in front of agents and an MCP gateway. On a held-out set of 80, the classifier caught 77.5% of injections at a 5% false positive rate, while the two-stage pipeline reached 80.0% at the same 5.0% rate; the phrase list alone managed only 22.5% on that set despite scoring 96.4% on the dev data it was tuned on. Classifier latency ran about 46-49 ms p50 and 55-132 ms p99 on four CPU threads, with a configurable fail-open or fail-closed mode when the sidecar is unavailable. Prompt injection defence in BleedStop is a stack of checks in front of the model, not one classifier score. The default check is a phrase list. A DeBERTa classifier is a second stage I turn on, and on my held out set it caught 77.5% of injections at a 5% false positive rate. Everything in this post is from the BleedStop case study https://osamamalik.me/bleedstop.html or from the public repo, usmamalik345/bleedstop https://github.com/usmamalik345/bleedstop , especially the README and classifier/server.py . The spend guard around these checks is in the BleedStop deep dive https://osamamalik.me/blog/bleedstop-cost-and-security-guard.html . The phrase list is the default detector. The README says the ONNX sidecar runs only when BLEEDSTOP DETECTOR is classifier or both . Until that flag is set, the live demo's server check is the phrase list. The model that runs in the browser on the demo page is a demo only. It does not protect the API. On the phrase list, the honest held out number is weak. The README's agent guard row calls the held out set 22.5%, with 0% false positives, and calls that the honest number. A later note in the same README, phrase list only, cutoff 0.6, normaliser off, is the same rate as a fraction: 9 of 40 on the held out set N=80, false positive rate 0 of 40 . Dev, which the regex was tuned on, is 53 of 55 N=112, benign 57, false positive rate 0 of 57 , which is the 96.4% in the summary table. Lowering the cutoff to 0.3 did not raise dev recall and raised the dev false positive rate to 1 of 57, so the cutoff stayed at 0.6. Turning normalisation on did not raise dev recall. BLEEDSTOP NORMALIZE stays off. That is why I do not lead with 96.4%. That figure is the set the phrase list was tuned on. classifier/server.py serves protectai/deberta-v3-base-prompt-injection-v2 with FastAPI. With CLASSIFIER URL set, /agent/precheck and the MCP gateway run the regex first, then the classifier. There is also a small ONNX sidecar under services/classifier/ , on CPU, the same 8 bit model the browser demo can load. The case study describes that browser build as a DeBERTa classifier quantized to 8 bit. Mode both runs the phrase list first and sends only text the phrase list allowed on to POST /classify . The timeout is BLEEDSTOP CLASSIFIER TIMEOUT MS , default 800. If the sidecar is down or slow, BLEEDSTOP CLASSIFIER FAILMODE=open is the default: keep the phrase list verdict, log a warning, and increment bleedstop classifier errors total . closed turns that outage into a block. That is safer against injection, and it also means a dead sidecar stops those calls. The README's comparison, which is the table I trust for this post, is: | Set | Phrase list recall / false positive rate | Classifier recall / false positive rate | Two stage recall / false positive rate | |---|---|---|---| | deepset/prompt-injections, all 662 | 4.2% / 0% | 41.4% / 1.0% | 41.4% / 1.0% | | BleedStop held out, 80 | 22.5% / 0% | 77.5% / 5.0% | 80.0% / 5.0% | | BleedStop dev phrase list tuned on it , 112 | 96.4% / 0% | 83.6% / 7.0% | 96.4% / 7.0% | The 77.5% at a 5% false positive rate on the case study is this classifier row, held out, N=80. It is not the phrase list. Two stage recall on that set is 80.0% at the same 5.0% false positive rate, slightly higher than the classifier alone. Latency in the README, on 4 CPU threads: phrase list p50 about 9 microseconds; classifier p50 about 46 to 49 ms, p99 55 to 132 ms. The README's caveats, which I share: deepset includes German rows and the model is English only; training overlap with public sets cannot be ruled out; the PINT row in the report is the public 8 row example file, not a PINT score; Llama Prompt Guard 2 is gated and I did not evaluate it. The browser build is the same DeBERTa v2 model in the visitor's browser with onnxruntime-web, an 8 bit weight only build 256 MB, served from GitHub Pages, loaded only on click . Against the fp32 ONNX it gave identical labels on the held out, dev and deepset test sets. Single threaded inference was p50 245 ms in headless Chrome on the build box. That check is still a demo. Server side enforcement on the live demo remains the phrase list until BLEEDSTOP DETECTOR is set. The README says free Docker hosting for the sidecar was not available, because Hugging Face Docker Spaces need a PRO plan, which is why the demo can run the model in the browser instead. A detector score does not spend money. POST /decide still returns ALLOW, LIMIT, CHALLENGE or DENY from the rules, and Redis still enforces the budget. The golden set on the case study is a different measurement from the injection table: 12,140 labeled requests, precision 100%, benign false positive rate 0.0%, recall 48.0%. The golden set and the rules share an author, so I do not call that a field result. On the MCP path, the README says every tools/call goes through, in order: a definition pin trust on first use, sha256 over name, description, inputSchema and annotations , a tool description poisoning scan, a per tenant Cedar policy in config/mcp-policy.cedar , the agent injection guard on the arguments, then the normal budget decision. Tool results are scanned for indirect injection. MCP GATEWAY MODE=shadow logs without blocking. The threat mapping is in docs/THREAT-MODEL.md . For npm run evals:mcp , 70 hand written tool definitions, the README reports poisoning scan precision 100%, recall 80% 20 of 25 , false positive rate 0% 0 of 45 . Rug pull detection caught 180 of 180 mutations, with 0 false alarms on 45 unchanged lists. Added latency per tools/call over HTTP, n=2000, was p50 2.21 ms, p95 2.84 ms, p99 3.89 ms. The misses are the 5 of 25 poisonings the README calls subtle and polite, with no trigger phrase. I wrote that eval set, so I treat the recall as optimistic. The README says the same. BLEEDSTOP DETECTOR is set. BleedStop repo https://github.com/usmamalik345/bleedstop · Case study https://osamamalik.me/bleedstop.html · Cost guard deep dive https://osamamalik.me/blog/bleedstop-cost-and-security-guard.html · Hire me https://osamamalik.me/hire/ Originally published at https://osamamalik.me/blog/prompt-injection-defence.html https://osamamalik.me/blog/prompt-injection-defence.html