TOOL WIKI · SECURITY & IDENTITY
Llama Guard
Classifies content against a safety taxonomy for application checks.
Jump to a section 10 sections
EXAMPLE USE CASE
Classify conversation safety before generating an answer
An agent application needs independently enforced input, identity, data or action checks before exposing a protected capability.
- Input
- A chat message formatted with the selected safety model’s template.
- Expected output
- A safety verdict that the application parses before deciding whether to continue.
- Success check: The output is a safety classification, not an answer to the user.
- Try a failure: An unparseable verdict must block or escalate rather than default to safe.
Example scope: Actual local safety-model inference requiring weights/resources; the classifier does not answer the user’s task.
Official reference · Llama Guard
Identify the actor, operation, resource, and relevant evidence.
inputTo 02 · Llama GuardA model-based content assessment stage in a larger protection system. A classification model does not enforce resource authorization.
Consume the identity, policy result, credential, or detection from this component. Fail according to an explicit application policy.
The business service still checks permission for the actual target resource.
Record the result without leaking unnecessary credentials or sensitive content.
outputTo 06 · Audit + reviewRetain actor, policy version, operation identifier, and result with deliberate redaction.
Result or stopping point
A model-based content assessment stage in a larger protection system. A classification model does not enforce resource authorization.
When to consider it
- A model-based content assessment stage in a larger protection system.
A design decision to make
- A classification model does not enforce resource authorization.
Prerequisites and setup
- A Hugging Face account with access to the gated model, accepted model terms, and adequate GPU/CPU memory.
- Weights are large. This is a pinned model example; use its matching prompt format and license requirements.
python3 -m venv .venv
source .venv/bin/activate
pip install transformers torch accelerate
hf auth loginTry a small integration
classify.py
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "meta-llama/Llama-Guard-3-8B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype="auto")
messages = [{"role":"user","content":"Help me summarize a public product manual."}]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
with torch.no_grad():
output = model.generate(inputs, max_new_tokens=100, pad_token_id=tokenizer.eos_token_id)
verdict = tokenizer.decode(output[0][inputs.shape[-1]:], skip_special_tokens=True).strip()
print(verdict)
print("May continue:", verdict.splitlines()[0].lower() == "safe")Run and check the result
python classify.py- The output is a safety classification, not an answer to the user.
- Use representative safe/unsafe fixtures for the model’s published categories and treat unparseable results as blocked.
Common failures
- Do not continue a protected operation when the policy response is missing, invalid or unavailable.
- A successful test on one fixture is not a complete security evaluation; include bypass attempts and legitimate requests.
Production decisions
- Enforce decisions in application/service code before an operation. A detector score or valid schema is not user authorization.
- Test allowed, denied, malformed, timeout and unavailable outcomes; record redacted decision reasons and default to a safe failure state.
- A content-safety classifier does not enforce tenant access, prevent all prompt injection or authorize financial/business actions.
Keep exploring
Explore the same layer
Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.