Skip to content

Back to the catalog

Context-Aware Prompt Injection Detection via Small Language Models in RAG Pipelines: nokast-secureRAG
arxiv.orgpaper

Context-Aware Prompt Injection Detection via Small Language Models in RAG Pipelines: nokast-secureRAG

nokast-secureRAG is a roughly 0.5B-parameter small language model that works as a semantic firewall between retrieval and generation in local RAG systems. It classifies each query and context pair as safe, suspicious or malicious. It reaches 0.994 recall at a 0.026 false-positive rate in-distribution, beating Llama Guard 3 1B and Prompt-Guard-86M (0.900 recall, 0.690 FPR). Recall on PoisonedRAG falls to near zero, and single-request latency is 293-404 ms.

TL;DR Presents an open-source 0.5B small language model that screens retrieved RAG context for indirect prompt injection, with benchmarks and stated limits.
Document

What it is

nokast-secureRAG is an open-source ~0.5B-parameter classifier by Abhishek Rai (independent researcher, accepted at the Lifelong Agent Workshop, COLM 2026). It reads the user query Q and the retrieved context C together, emits a short reasoning trace, then labels the pair safe, suspicious or malicious-instruction. The model, data pipeline and evaluation harness are released. The page text cuts off at the LoRA fine-tuning section, so training hyperparameters are not covered here.

How it works

A 35B teacher model generates 5,233 synthetic (Q, C) records. A 120B judge from a different model family re-labels each one blind, and the two agree on 95.0%. Agreed records train the student with reasoning-first LoRA: 3,835 train, 479 validation, 659 test.

Attack families are indirect prompt injection (818 records), knowledge-base poisoning (500), context hijack (400) and PII exfiltration (200). There are also 3,115 benign records and 200 borderline ones. Payloads always sit in C (HTML comments, footers, "ignore previous instructions" clauses), never in Q.

The paper also builds 120 "judgment-flip" pairs, held out for testing. Each pair places the same sentence in a benign documentation context and in an injected context.

Results beyond the headline

Recall on the in-distribution test set:

DetectorRecall
nokast-secureRAG0.994 (FPR 0.026)
ProtectAI DeBERTa0.888
Prompt-Guard-86M0.900 (FPR 0.690)
Regex baseline0.688
Llama Guard 3 1B0.437
Same base model, untuned0.116

On flip pairs, where both halves must be labelled correctly, the model scores 75%. Keyword filter 17.5%, ProtectAI DeBERTa 54%, Llama Guard 27%.

In ablations, masking C drops recall to zero. Adding Q to C lowers false positives, so the attack signal is in the context and the query helps only with over-flagging.

Latency is 293-404 ms per single request depending on the serving runtime, above the paper's own sub-100 ms target. Batched throughput is 37 ms amortized.

Preconditions / Affected

The threat model assumes a benign user query and an attacker who controls retrievable content (web pages, documents, memory entries) and embeds instructions in it. It targets local deployments on 16 GB-class VRAM.

Caveats

  • All headline numbers are in-distribution on data generated by the same teacher. The author states there is no validated robustness against adaptive adversaries.
  • On PoisonedRAG, an external benchmark, recall collapses to near zero. The author attributes this to fluent fact-fabrication attacks falling outside an instruction-consistency threat model. The detector will not catch poisoned passages that contain no instructions.
  • The 75% flip-pair score means one in four injected-versus-benign pairs is still mislabelled.
  • Prompt-Guard-86M's 0.690 FPR is measured on this synthetic benign set, which includes instructional documentation text.
  • The baseline comparison uses the 1B Llama Guard 3 checkpoint run locally.

Organisations named here

  • nokast-secureRAG
  • Prompt-Guard-86M

Technologies named here

  • Local Retrieval-Augmented Generation systems
  • Prompt-Guard-86M
  • Llama Guard 3 1B
  • Public prompt-injection classifier
  • Regex baseline
  • PoisonedRAG benchmark
  • 35B teacher model
  • 120B judge model
  • Llama Guard 3
  • LLM

Techniques named here

  • Retrieval poisoning
  • Judgment-flip test
  • Ablations
  • Indirect prompt injection
  • PoisonedRAG