Prompt Guard 2
Encoder classifier for prompt-injection and jailbreak detection.
Binary encoder classifier (mDeBERTa / DeBERTa) that labels a single prompt string benign (index 0) or malicious (index 1, i.e. a prompt-injection or jailbreak attempt). Meta's v2 collapsed Prompt Guard 1's separate "injection" class and focuses on explicit jailbreak / injection attacks. It screens prompt text only — it is not designed to judge model responses.
Verdict mapping onto GuardrailOutput:
validisTruewhen the predicted class isbenign(argmax index != 1).score(canonical risk: higher = riskier) is themaliciousprobability.categoriescarries oneCategoryResultper class, each with its probability and atriggeredflag on the predicted class. The gated repos publish only the genericLABEL_0/LABEL_1names, so categories fall back to those when the provider surfaces no label list.
Expected inputs: a single prompt string, or a list[str] for batched classification (the inherited validate dispatches list input to _validate_batch). The 86M default is multilingual; the 22M variant is English-only.
The repos are gated under the Llama 4 Community License — accept the terms on the model page and authenticate with hf auth login before first use.
For more information, please see the model cards:
Llama-Prompt-Guard-2-86M (default) — mDeBERTa-base, multilingual.
Llama-Prompt-Guard-2-22M — DeBERTa-xsmall, English, ~75% lower latency.
Supported Models
meta-llama/Llama-Prompt-Guard-2-86Mmeta-llama/Llama-Prompt-Guard-2-22M
Constructor
model_id
`str
None`
No
None
provider
Optional[Provider[dict[str, Any], dict[str, Any]]]
No
None
Optional pre-configured provider. If None, a default HuggingFaceProvider (targeting AutoModelForSequenceClassification) is built and the model is loaded eagerly.
Initialize the Prompt Guard 2 guardrail.
validate
Default validation pipeline: preprocess -> inference -> postprocess.
Parameters
input_text
`str
list[str]`
Yes
—
Returns: GuardrailOutput | list[GuardrailOutput]
Benchmarks
Prompt Injection
deepset_pi (unspecified)
f1
native-valid
0.235294
guardrail-bench+ag0.7.4
measured:guardrail-bench+ag0.7.4
notinject (unspecified)
fpr
native-valid
0.0315789
guardrail-bench+ag0.7.4
measured:guardrail-bench+ag0.7.4
gandalf (unspecified)
recall
native-valid
0.973214
guardrail-bench+ag0.7.4
measured:guardrail-bench+ag0.7.4
License
Vendor: Meta
Default license:
llama-4(of the default model/service)
Last updated