Quest 01 / 02 · Capstone
Build a prompt-injection gateway for a local support assistant and attack it with garak
- prompt injection defense
- text classification
- Transformers fine-tuning
- NeMo Guardrails
- red-team evaluation
- FastAPI
- CI testing
Why now AWS reported on November 20 that attackers used agents to find and exploit a zero-day, and this month's coverage of garak, Promptfoo and NeMo Guardrails described open tools for testing and controlling model input. A support inbox that drafts replies with a model served by Ollama is a small, real target for trying those tools together, with open traces as the Hugging Face evaluation guide recommends.
Build it A local service that screens each support ticket with a fine-tuned injection classifier inside a NeMo Guardrails input rail before an Ollama model drafts the reply. A garak and Promptfoo test suite attacks the service on every change and saves the scores.
From the news
- AWS says attackers used agents to find a zero-day 2026-11-26 · source
- garak makes model failure reports repeatable and inspectable 2026-11-26 · source
- Promptfoo keeps application security tests close to development 2026-11-26 · source
- NeMo Guardrails adds agent checks with defined inspection limits 2026-11-26 · source
- Ollama makes model serving part of the developer workstation 2026-11-26 · source
- Hugging Face publishes a guide to agent evaluation 2026-11-23 · source
Tools
- Transformers
Transformers is free Apache 2.0 software. Model checkpoints, remote model code and paid hosting have separate terms and costs.
- NVIDIA NeMo Guardrails
The NeMo Guardrails library uses Apache 2.0 and has no software subscription requirement. Model-based checks and deployment infrastructure have separate costs and licenses. NVIDIA commercial services are outside the license grant for this library.
- Ollama
Ollama's runtime uses the MIT license, while model weights have their own licenses. Local execution has no Ollama usage charge; optional cloud inference uses metered credits, subscriptions and enterprise terms.
- garak
garak is free Apache-2.0 software. Running it requires suitable compute and access to the selected target or model provider. External model services and test infrastructure can incur their own charges.
- Promptfoo
Promptfoo's open-source code is MIT licensed. Its Community plan is free with stated probe allowances; commercial Enterprise and on-premise offerings add features under separate service terms. Model-provider charges and additional enterprise probes can be separate costs.
Data
- Prompt Injection & Jailbreak Detection Dataset Kaggle
Main labeled attack and benign prompts for training and testing the classifier, including its multilingual rows.
- LLM jailbreak + safety data for chatbot apps Kaggle
Second source of jailbreak and benign chatbot prompts, merged into the training data and checked for overlap.
- Customer IT Support - Ticket Dataset Kaggle
Support tickets in several languages that measure the false-positive rate on ordinary customer-style text.
- deepset/prompt-injections Hugging Face
Held-out out-of-distribution test set that shows how recall changes on data from another source.
Milestones
A data split you can trust
- Download both Kaggle prompt datasets, load them with pandas and inspect the columns, label values and language coverage before writing any mapping code.
- Map both label schemes onto one binary target, attack or benign, and keep any attack category the data provides as a separate column.
- Sample 5,000 tickets from the multilingual support dataset, label them benign and add them to the pool so the classifier sees ordinary customer text.
- Remove exact and near-duplicate prompts across sources and against the deepset set, write seeded train, validation and test splits to Parquet, and run a script that prints counts per split, source and label.
A classifier with a measured threshold
- Choose a small multilingual encoder checkpoint from the Hugging Face Hub that trains on your hardware, and fine-tune it with Transformers on the training split.
- Compute precision, recall and false-positive rate on the validation split across thresholds, then pick the threshold that keeps benign false positives at or below 2 percent.
- Score the deepset prompt-injections set as an out-of-distribution check and record the recall gap against the in-distribution test split.
- Save the model, tokenizer and threshold, and expose a predict function that a command-line script calls on a single string.
A gateway in front of a local model
- Install Ollama, pull an instruction-tuned model whose license allows your use, and confirm the local API answers a test prompt.
- Write a NeMo Guardrails configuration whose input rail calls the classifier as a custom action and returns a fixed refusal above the threshold.
- Wrap the rails in a FastAPI endpoint that returns the drafted reply, the classifier score and the rail decision for each ticket.
- Log every request to SQLite with score, decision, model name and latency, and add a script that prints the day's block rate.
Attack tests that run on every commit
- Point garak's REST generator at the gateway and run its prompt injection and jailbreak probes, then repeat the same probes against bare Ollama.
- Build a Promptfoo configuration from 300 held-out attack rows and 300 held-out tickets that expects a refusal for attacks and a drafted reply for tickets.
- Run both tools against a rail-on build and a rail-off build, saving every report in the dated results folder.
- Add a CI job that runs the Promptfoo suite on each commit and fails when attack pass-through rises above 10 percent.
A review page and the write-up
- Add a review page to the gateway that lists flagged tickets with their scores so a person can mark false positives.
- Append reviewer corrections to a corrections file, retrain once, and compare the new test metrics with the first model.
- Write a README covering setup, the threshold choice, both garak reports and the attack categories the classifier still misses.
Architecture
A FastAPI gateway accepts ticket text and hands it to a NeMo Guardrails configuration. A custom input rail calls a small Transformers classifier fine-tuned on the Kaggle data and refuses text whose score passes a tuned threshold. Allowed tickets reach a local model served by Ollama, which drafts a reply. Each request is logged to SQLite with its score, rail decision and latency. A test script runs garak probes against the gateway endpoint and a Promptfoo suite built from held-out rows, writing both reports to a dated results folder.
Deliverables
- A Git repository with the split script, training script, gateway service and attack test suite.
- A saved classifier with its threshold and a model card naming the training data and their licenses.
- garak and Promptfoo reports for the rail-on and rail-off builds.
- A README write-up with metric tables, known misses and setup instructions.
How to measure it
On the held-out test split, report attack recall, precision and the false-positive rate on benign rows, with a target of 0.90 recall at 2 percent or fewer false positives. Report deepset recall separately as a distribution-shift check. Compare garak attack success rates with the rail on and off over identical probes, and record median and 95th-percentile added latency in milliseconds.
Done when
- The split script prints counts per source, split and label, and no prompt appears in more than one split.
- The classifier reaches at least 0.90 recall on held-out attacks with a false-positive rate at or below 2 percent on held-out benign rows.
- Recall on the deepset prompt-injections set is reported beside the in-distribution recall.
- A request to the gateway returns a drafted reply for a normal ticket and the fixed refusal for a known injection.
- garak reports a lower attack success rate for the gateway than for bare Ollama on the same probes, and both reports are saved.
- The Promptfoo suite runs in CI and fails the build when attack pass-through exceeds the limit.
- The SQLite log holds score, decision and latency for every request, and the classifier adds under 150 milliseconds of median latency.
Stretch goals
- Add an output rail that blocks drafted replies containing system prompt text, and test it with a garak probe aimed at prompt leakage.
- Break recall down by attack category and language where the Kaggle data labels them, and publish the five weakest cells.
- Run a multi-turn attack with Microsoft PyRIT against the gateway and compare its pass-through rate with single-turn probes.
- Package the gateway as a Docker image that downloads the classifier weights at build time.
