Reproduce the threat comparison¶
At the end of this guide you will have every text of the threat comparison on your own machine, each with its labels and source and checked against our published list, and you will have re-computed the comparison tables from the stored scores of every system. Nothing in the tables has to be taken on trust: the texts come from the public datasets at fixed versions, and the script tells you whether your tables equal ours.
The comparison is the one in the README:
every system scores the same 26,962 held-out texts (the measurement part). Each system's
threshold is set on a separate 26,707 texts (the calibration part). The texts come from 42
sources: 33 public datasets, the text sets we generate with the public generators, our German
translations of public rows, and three sets built from files in this repository. The detailed
tables are in
research/l1-threat/scoreboard/baseline.md.
Before you start¶
- A checkout of the repository (patronus-protect/patronus-security). All commands below run from its root.
- Python 3.11 or newer with three packages:
pip install numpy pyyaml patronus-ark-core. - The reproduction package (about 33 MB) from Hugging Face:
patronus-studio/ark-threat-comparison. - Internet access and about 500 MB of free disk space: the script downloads every public dataset at the exact version we used (about 310 MB). No account or access token is needed; none of the datasets is gated.
- Plan for 30 to 45 minutes: downloading and rebuilding the large datasets (deduplication) takes most of it.
What the package holds:
| File | What it is |
|---|---|
manifest.jsonl.gz |
One line per text (74,270: calibration, measurement and the report sets): source, part, key, labels. No text. |
texts.jsonl.gz |
The texts whose licence allows us to share them (54,154 texts). |
sources.json |
Per source: where it is downloaded from, the pinned version and files, the licence and whether its texts are shared. |
split.json |
How the texts were split into calibration and measurement, and which systems have stored scores. |
predictions/ |
The stored scores of every system per text: Ark rules, Ark rules + L1 models, the Ark cascade, Prompt Guard 2 (22M, 86M), ProtectAI v2 and seven open-source rule sets. |
manifest.jsonl.gz, sources.json and split.json are also in the repository, under
research/l1-threat/scoreboard/reproduction/,
so you can look at the keys and labels without the package.
Step 1: Get the package¶
pip install huggingface_hub
huggingface-cli download patronus-studio/ark-threat-comparison --repo-type dataset --local-dir threat-package
Step 2: Rebuild, check and re-score¶
The script downloads each public dataset at its pinned version and checks every downloaded file against its SHA-256, builds the texts the same way we did, and checks each text against the manifest. Then it re-computes the comparison from the manifest's labels and the stored scores. Output:
calibration: 26707 rows; rebuilt 26265, shipped 442
measurement: 26962 rows; missing 34, rebuilt 26282, shipped 646
report: 20601 rows; rebuilt 20601
split 690db0e4811d (package: 690db0e4811d)
research/l1-threat/scoreboard/baseline.md: identical tables
What each word means:
- rebuilt: the text was downloaded and built again, and its key, its SHA-256 and its labels equal the manifest.
- shipped: the text comes from the package (texts we generated or translated ourselves) and its SHA-256 equals the manifest.
- missing: no text could be checked. The 34 measured texts here are generated texts that contain a row of a dataset whose texts we do not share (see Which texts are shared); they keep their labels and scores in the package. A quote from a web page that changed after we took it would show up here too.
- mismatch: a text differs from the manifest. The script then exits with code 1.
- split: a short hash of which text is in which part. It must equal the package's.
- The last line compares your tables with the checked-in report.
identical tablesmeans every number is the same.
Step 3: Read the texts¶
threat-repro/rows/<source>.jsonl holds one line per text of that source:
{"row_id": "spml:0000123", "source": "spml", "part": "measurement", "language": "en",
"benign": false, "classes": ["instruction_injection"], "reported_classes": [],
"hard_negative": false, "key": "…", "text_sha256": "…", "text_included": true, "text": "…"}
| Field | Meaning |
|---|---|
row_id |
The text's id: source and its number in the source. |
part |
calibration (sets the thresholds), measurement (the 26,962 measured texts) or report (extra report sets, scored at the same thresholds). |
classes |
The attack classes the text is a positive of. |
benign |
true for a harmless text. |
hard_negative |
A harmless text that looks like an attack (counted apart as hard-negative FPR). |
not_scored_for |
Classes the text counts for neither way (only present when not empty). |
key |
SHA-256 of the text with whitespace collapsed and case folded. |
text_sha256 |
SHA-256 of the text exactly as it is. |
text |
The text, or null when it could not be checked. |
How a text counts for one class:
- positive if the class is in
classes; - not counted if the class is in
not_scored_for(the dataset reports the class without enough confidence, or the text is an attack of no class we score); - negative otherwise: every harmless text and every attack of another class.
Step 4: Compare the tables¶
threat-repro/scoreboard/baseline.md is your copy of the report. Every threshold comes from the
calibration part only; the tables show, per class and language, the share of attacks caught
(TPR) and the share of harmless texts flagged (FPR) on the measurement part.
diff <(grep '^|' research/l1-threat/scoreboard/baseline.md) <(grep '^|' threat-repro/scoreboard/baseline.md)
No output means the tables are the same. threat-repro/fair.json has every number in machine
readable form.
Which texts are shared¶
We share a text only when its licence allows it: MIT, Apache-2.0, CC-BY, CC0 or ODC-BY, and texts
we made ourselves. For the other sources the package has the key only, and step 2 downloads the
texts from the source. The decision per source, its licence and where we read it are in
scripts/l1_threat/redistribution.yaml.
| Source | Licence | Why the texts are not shared |
|---|---|---|
| dolly_15k | CC-BY-SA-3.0 | share-alike |
| germeval2017, germeval2021 | not stated | no licence |
| textdetox_de | OpenRAIL++ | use restrictions |
| wildjailbreak, wildguardmix | ODC-BY-1.0 | the original is behind the authors' terms of use |
| bipia | MIT, contexts from third parties | parts come from third-party sources |
| real_agent_quotes | per quote | quotes from public web pages; fetched from each page |
A text we generated around a row of one of these sources is not shared either.
Common problems¶
source not rebuilt: … (ValueError: … SHA-256 …): a file at the pinned version changed or the download broke. Delete that source's folder underthreat-repro/sources/and run again.source not rebuilt: pii_texts (ImportError …): installpatronus-ark-core. The texts of this set are also in the package, so the check still passes.- To re-run without downloading, add
--offline(the download cache inthreat-repro/sourcesmust be complete), or point--sourcesat an existing cache.