defending-llms-with-guardrails
Makes your agent use safety guardrails to inspect and limit language model inputs and outputs. It's useful for blocking attempts to bypass the system or data leaks.
What it does
This tool adds security layers to applications that use artificial intelligence (AI). It checks the questions asked to the AI and the answers it gives to prevent dangerous or inappropriate information from being sent or received.
When to use it
- ✓When putting an AI application into real-world use.
- ✓To block attempts to trick the AI (jailbreaks).
- ✓To prevent the AI from revealing sensitive information or generating toxic content.
Example of what to ask your AI
“Protect my AI application from malicious prompts.”
Want more? Open the sections below.
How to use
The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.
Skill link
Ready-to-paste message
How it works
It uses three different systems (Llama Guard, NeMo Guardrails, LLM Guard) that work together. One checks content, another controls dialogue, and the third scans inputs and outputs for specific issues.
Installation
Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.
In the terminal (Claude Code, Codex, Cursor), in your project folder:
npx skills add mukul975/Anthropic-Cybersecurity-Skills --skill defending-llms-with-guardrailsOr download just the file:
curl -L https://raw.githubusercontent.com/mukul975/Anthropic-Cybersecurity-Skills/main/skills/defending-llms-with-guardrails/SKILL.md -o SKILL.mdTechnical content (original SKILL.md)
Original text by the author, straight from GitHub.
Defending LLMs with Guardrails
Defensive scope: This skill describes runtime defenses for production LLM applications. The example jailbreak/injection payloads exist only to validate that guardrails block them. Test against systems you own or are authorized to assess.
Overview
Large language model (LLM) applications are exposed to adversarial input (jailbreaks, prompt injection, toxic content) and can emit unsafe, biased, or sensitive output. A guardrail is a runtime control that inspects and constrains the data flowing into and out of an LLM. Three production-grade, open-source guardrail systems dominate the ecosystem and are complementary rather than mutually exclusive:
- Llama Guard 3 (Meta) — a Llama-3.1-8B model fine-tuned as a safety classifier. Given a prompt or a response, it emits
safeorunsafeplus the violated MLCommons hazard categories (S1–S14). It is the strongest semantic content-safety classifier of the three and supports prompt classification, response classification, and tool-call/code-interpreter classification across 8 languages. - NeMo Guardrails (NVIDIA) — a programmable dialogue-rail framework. You define
input,output,dialog,retrieval, andexecutionrails in aconfig.ymlplus Colang (.co) flows. It can call external models (including Llama Guard) as actions, enforce topical boundaries, and add fact-checking/jailbreak-detection rails. - LLM Guard (Protect AI) — a scanner pipeline with 15 input scanners and 20 output scanners (PromptInjection, Toxicity, Anonymize/Deanonymize, Secrets, BanTopics, Sensitive, Regex, etc.). It returns a sanitized string, a validity flag, and a risk score per scanner, making it ideal for a deterministic pre/post pipeline.
This skill maps to MITRE ATLAS AML.T0054 — LLM Jailbreak: the guardrail layer is the mitigation that detects and blocks jailbreak/injection attempts before they reach (or after they leave) the model.
When to Use
- When deploying an LLM/RAG/agent application to production and needing a runtime safety layer.
- When you must block jailbreaks and prompt injection (OWASP LLM01) before they reach the model.
- When you must moderate model output for toxicity, PII leakage, secrets, or off-topic responses.
- When validating that a guardrail configuration actually blocks a corpus of known-bad payloads.
- When layering defense-in-depth: a deterministic scanner (LLM Guard) plus a semantic classifier (Llama Guard) plus dialog rails (NeMo).
Prerequisites
- Python 3.9+ (LLM Guard requires 3.9+; Llama Guard via transformers requires
transformers>=4.43). - GPU recommended for Llama Guard 3 8B (CPU works for the 1B variant or quantized builds).
- A Hugging Face account with accepted Meta Llama license to download
meta-llama/Llama-Guard-3-8B.
# LLM Guard
python -m pip install llm-guard
# NeMo Guardrails
python -m pip install nemoguardrails
# Llama Guard via Hugging Face transformers
python -m pip install "transformers>=4.43" torch accelerate huggingface_hub
huggingface-cli login # accept the Meta Llama license first on the model page
Objectives
- Run Llama Guard 3 as a prompt and response safety classifier and parse its category output.
- Build an LLM Guard input/output scanner pipeline with PromptInjection, Toxicity, Secrets, and Anonymize scanners.
- Author a NeMo Guardrails
config.ymlplus Colang flows with input/output/jailbreak rails. - Wire Llama Guard into NeMo as a content-safety check.
- Validate the combined stack against a corpus of jailbreak and injection payloads.
MITRE ATT&CK Mapping
| ID | Tactic | Official Technique Name | Role in this skill |
|---|---|---|---|
| AML.T0054 | ATLAS: Defense Evasion / Impact | LLM Jailbreak | Guardrails detect and block the jailbreak attempt this technique describes |
| AML.T0051 | ATLAS: Initial Access | LLM Prompt Injection | Input rails / PromptInjection scanner block direct injection |
| AML.T0051.001 | ATLAS: Initial Access | LLM Prompt Injection: Indirect | Retrieval/input scanning blocks injection in retrieved content |
| AML.T0057 | ATLAS: Exfiltration | LLM Data Leakage | Output scanners (Sensitive, Secrets, Deanonymize) block leakage |
Workflow
Step 1: Classify prompts and responses with Llama Guard 3
…
FAQ
What are 'jailbreaks' and 'prompt injection'?
'Jailbreaks' are attempts to make the AI ignore its safety rules. 'Prompt injection' is when someone inserts malicious commands into the prompt for the AI.
What kinds of harmful content does it block?
It blocks toxic content, personally identifiable information (PII), secrets, and off-topic responses, in addition to jailbreak and prompt injection attempts.
Do I need to use all three systems (Llama Guard, NeMo, LLM Guard)?
They are complementary and offer different types of protection. Using more than one increases the overall security of your application.
Details
Original description by the author
Deploys Llama Guard 3 safety classification, NeMo Guardrails programmable dialogue rails, and LLM Guard input/output scanner pipelines as complementary runtime defenses that inspect and constrain LLM prompts and responses. Use when adding a production runtime safety layer to an LLM, RAG, or agent application to block jailbreaks, prompt injection (OWASP LLM01), toxic content, or sensitive-data leak
Popularity
- GitHub stars
- 35k
- Ranking position
- #5612
- License
- Apache-2.0
- Updated
- 8/31/2026
Comments
- …
More skills from this repository
abusing-dpapi-for-credential-access
Gives your AI agent ready-made instructions for a specific task, so it does it better and faster.
mukul975/Anthropic-Cybersecurity-Skills
abusing-shadow-credentials-for-privesc
Teaches your AI agent to write clear, well-structured text.
mukul975/Anthropic-Cybersecurity-Skills
achieving-cmmc-level-2-compliance
Helps your agent prepare an environment for CMMC Level 2 compliance. It implements security requirements and manages necessary documentation.
mukul975/Anthropic-Cybersecurity-Skills
acquiring-disk-image-with-dd-and-dcfldd
Helps your agent create exact copies of hard drives. This is useful for ensuring no information is lost or altered during investigations.
mukul975/Anthropic-Cybersecurity-Skills
Similar skills
agent-architecture-audit
Makes your agent check if everything is working correctly. It finds and fixes problems in AI systems, ensuring they perform as expected.
affaan-m/ECC
agent-eval
Helps your agent compare different AI coding tools. It measures which one is faster, cheaper, and more reliable for specific tasks.
affaan-m/ECC
agent-harness-construction
Makes your agent better understand how to perform tasks. It optimizes the tools and instructions the agent uses to increase its chances of success.
affaan-m/ECC