Exercise sec-prompt-injection — a red-team eval harness + a tool-call allow-list

Score the provided mock model against the LLM red-teaming harness's 40-attack fixture, build a markdown report from the result, and write a fail-closed allow-list for the tool calls an agent built on that model might make. This mirrors the actual job task: shipping a red-team suite whose report a reviewer can trust run to run, and a tool layer that drops a malformed call instead of executing it. It runs on your Mac, not in the browser.

~120 minruns locally · uv + pytest 6 checkssec-prompt-injection

What you're building

The tests are ordinary pytest and ship in the public folder with the starter — read them first; the names below are the check list. Solutions are not published.

Get the repo (once)

Needs git. uv installs the right Python itself, so nothing else is required.

# once, anywhere on your machine
git clone https://github.com/theDocWho/ai-ml-roadmap.git
cd ai-ml-roadmap

No git? Download the ZIP, unzip it, and cd into the unzipped folder instead.

Run it

From the repo root:

# one-time: uv (https://docs.astral.sh/uv/) manages the venv and pins Python ≥ 3.12
cd exercises/sec-prompt-injection && uv sync && uv run pytest -q

Done when uv run pytest -q prints 6 passed. The untouched starter fails all 6 — every function is ....

The checks

The fixture is fixed, so the rate is a known number: 12 of 40 attacks leak the canary token (4 of 10 override, 5 of 10 exfiltration, 3 of 10 roleplay, 0 of 10 encoding — those ten are obfuscated and never contain a literal trigger phrase, so the mock model always refuses them). The determinism check calls run_harness twice and requires an equal result; the two allow-list checks each isolate one failure mode — a disallowed name (exec_shell with {"cmd": "rm -rf /"} is dropped while search with {"query": "capital of France"} passes through unchanged), and an allowed name with the wrong argument shape (search with {"query": 123} or with no query at all — both dropped).

Files

This is self-attestation — the site cannot see your terminal, so the box and the button are you telling The Path the suite went green on your machine.

If you get stuck