Guide · Agent skill
How to use the LlamaGuard content moderation agent skill
Updated · written with AI from the project's own documentation and checked against our catalogue data
The llamaguard skill teaches an AI agent how to set up Meta's LlamaGuard, a 7-8 billion parameter model that labels text as safe or unsafe. It is aimed at developers who build chatbots or LLM apps and want an input or output safety filter. After following this guide you will know how to install the skill, ask the agent for moderation code, and what you need in place to run it.
Quick start
- 1Download and unzip the skill. Download the llamaguard ZIP from this page and unzip it to get the llamaguard folder containing SKILL.md.
- 2Place the folder. Move the llamaguard folder into ~/.claude/skills/ for personal use or into a project's .claude/skills/ folder. In the Claude apps, upload the ZIP under Settings → Capabilities → Skills instead.
- 3Set up Hugging Face access. Create a Hugging Face account, accept the LlamaGuard license on the model page, and log in with huggingface-cli login using your token.
- 4Install the Python packages. Install transformers and torch, and add vllm if you plan to use the serving examples.
- 5Ask for the moderation code. Describe where you want the check, such as on user input, on model output, or as an API, and let the agent write the code.
- 6Test with your own prompts. Run the generated code on safe and unsafe examples from your own app and check that the categories and decisions look right.
What an agent skill is and what this one does
An agent skill is a folder of instructions that an AI agent loads when your request matches its purpose. The llamaguard skill is a single SKILL.md file. When it is active, the agent knows how to write code that checks text against LlamaGuard.
Once installed, the agent can write code that checks what a user types, or what an AI model replies, against six safety categories: violence and hate, sexual content, guns and illegal weapons, regulated substances, suicide and self-harm, and criminal planning. The skill also shows how to serve the classifier through vLLM, a FastAPI endpoint, or NeMo Guardrails.
How to install the llamaguard skill
Download the skill ZIP from this page and unzip it. Put the llamaguard folder in ~/.claude/skills/ to make it available to all your projects, or in a project's .claude/skills/ folder to limit it to that project.
If you use the Claude apps instead, upload the ZIP under Settings → Capabilities → Skills.
- Personal install: ~/.claude/skills/
- Project install: .claude/skills/ inside your project folder
- Claude apps: Settings → Capabilities → Skills, then upload the ZIP
What you need before you run the code
The skill's code uses Python with transformers and torch, and vLLM for the serving examples. You need a Hugging Face account and token. You must also accept the LlamaGuard license on the model page before the model will download.
The model is 7-8 billion parameters, so you need GPU resources suited to a model that size. The API example uses FastAPI and uvicorn, and the NeMo Guardrails example needs NeMo Guardrails installed.
- Python with transformers and torch (vllm for serving examples)
- Hugging Face account, token, and accepted LlamaGuard license
- GPU resources suitable for a 7-8B model
- FastAPI and uvicorn for the API example
- NeMo Guardrails for the integration example
pip install transformers torch
huggingface-cli loginHow to trigger the skill with natural requests
You do not need special syntax. Describe what you want in plain language and mention moderation, safety filtering, or LlamaGuard. The agent will load the skill when the request matches it.
Name the part of your app you want to protect, such as the user input step or the model output step. Say which framework you use if it matters, for example vLLM, FastAPI, or NeMo Guardrails.
- Write a function that checks user messages with LlamaGuard before they reach my LLM.
- Add an output filter using LlamaGuard that checks replies before they are shown to users.
- Serve LlamaGuard as a FastAPI endpoint that returns safe true or false and the category.
- Integrate LlamaGuard into my NeMo Guardrails input and output flows.
Example: an input check and a moderation function
The core pattern is a moderate function that formats a chat, runs the model, and returns the text. The skill's input filter builds on it. If the result starts with unsafe, the second line holds the category code, such as S3 for criminal planning in the example.
Expect the agent to write code close to this. Test it with your own prompts before you rely on it.
- Categories: S1 Violence & Hate, S2 Sexual Content, S3 Guns & Illegal Weapons, S4 Regulated Substances, S5 Suicide & Self-Harm, S6 Criminal Planning
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "meta-llama/LlamaGuard-7b"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
def moderate(chat):
input_ids = tokenizer.apply_chat_template(chat, return_tensors="pt").to(model.device)
output = model.generate(input_ids=input_ids, max_new_tokens=100)
return tokenizer.decode(output[0], skip_special_tokens=True)Example: calling the moderation API
For the FastAPI workflow, the agent writes an endpoint at /moderate. The skill's example server is started with uvicorn and returns whether the text is safe, the category, and the full model output.
A request is sent as a JSON list of messages, as in the example below. The sample response shows the shape of the answer.
curl -X POST http://localhost:8000/moderate -H "Content-Type: application/json" -d '{"messages": [{"role": "user", "content": "How to hack?"}]}'Limits, safety notes and tips
The skill itself runs no scripts. The code it writes downloads the model from Hugging Face, so the skill uses the network and the first run needs access to the model page. The skill's own notes cite 94-95% accuracy, which means some unsafe content will be missed and some safe content may be wrongly blocked. Treat the output as one layer of protection, not a guarantee.
If you get false positives, the skill suggests a threshold on the probability of the unsafe token, and 8-bit quantization if GPU memory is tight. Test any threshold on your own traffic first.
- Log blocked and passed messages so you can review mistakes.
- Check the model license terms on Hugging Face before commercial use, since the weights require accepting Meta's license.
- If you see model access denied, log in with huggingface-cli login and accept the license on the model page.
What people use it for
- Filtering user prompts before they reach a chatbot or LLM so harmful requests are blocked early.
- Checking an assistant's replies before they are shown to users in a customer-facing app.
- Running a self-hosted moderation endpoint so text is not sent to a third-party moderation API.
- Adding input and output moderation flows to a NeMo Guardrails pipeline.
Frequently asked questions
Is the llamaguard skill free to use?
The skill is published under the MIT license. The LlamaGuard model is Meta's, and access requires accepting Meta's license terms on Hugging Face, so check those terms before commercial use.
What do I need to install to use llamaguard?
You need Python with transformers and torch, a Hugging Face account and token, and GPU resources suited to a 7-8B model. vLLM, FastAPI with uvicorn, and NeMo Guardrails are needed only for the matching examples.
How accurate is LlamaGuard?
The skill's notes cite 94-95% accuracy. That means some unsafe content will be missed and some safe content may be wrongly blocked, so it should not be your only safety layer.
Why do I get model access denied when I run the code?
Log in with huggingface-cli login using your token, then accept the LlamaGuard license on the model page on Hugging Face. The model will not download until both steps are done.
What are the alternatives to LlamaGuard?
The skill lists the OpenAI Moderation API, Google's Perspective API, NeMo Guardrails as a broader safety framework, and Constitutional AI, which works at training time. The OpenAI and Perspective options are hosted APIs rather than models you run yourself.
Does the skill run any scripts on my computer?
No. The skill is a SKILL.md file with instructions and examples. The code the agent writes uses the network to download the model, so review it before running it.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Use this skill if you are a developer building a chatbot or LLM app who wants a self-hosted input or output safety filter and can provide a GPU and a Hugging Face account. Pick a hosted moderation API or a non-model tool instead if you need a ready-made product, do not have GPU resources, or need guaranteed safety coverage.
Download the skill