llm-guardrails
Comprehensive guide for LLM safety and guardrails implementation.
npx skills add majiayu000/claude-skill-registry --skill llm-guardrails --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
What it does
Guides the implementation of safety guardrails for LLMs, including definitions of guardrail categories (input, output, content moderation, PII detection, prompt injection, topic control, format and length control, tone control) and a workflow where input is checked, processed by an LLM, then passed through output guardrails with fallbacks if violations occur. It includes example Python code blocks illustrating input and output filtering, PII detection, prompt-injection prevention, and a NeMo Guardrails setup with a RailsConfig for an OpenAI model.
How it works
The skill lays out concrete guardrail concepts and a workflow: User Input -> Input Guardrails -> LLM Processing -> Output Guardrails -> Final Output, with a Fallback Response if checks fail. It defines guardrail data structures and common guardrails (hate_speech_filter, pii_redaction, prompt_injection_prevention, topic_restriction, response_length_limit) and provides runnable code examples for:
- A Python InputFilter class that loads blocked words and patterns, detects prompt injection indicators, and filters inputs with clear rejection messages.
- An OutputFilter class that checks for prohibited content categories, detects PII, detects excessive length, and returns a fallback response tied to the violation type.
- Open-source guardrails tooling examples (NeMo Guardrails) showing configuration snippets for input/output flows and sample YAML/flows for jailbreak, prompt injection, hate speech, and self-harm handling.
When to use it
Use this skill when you need a structured, rule-based approach to guardrails in an LLM deployment, including input validation, content moderation, and safe output handling. It is appropriate when you rely on explicit guardrail categories and want concrete code patterns for filtering and fallback responses.
What it can touch
The skill references and demonstrates:
- Python code modules/classes: InputFilter, OutputFilter
- Protected keywords and patterns for input filtering
- Protobuf-like guardrail definitions and Enum/DataClass usage for guardrails
- YAML/flows for NeMo Guardrails configuration (config.yml, flows/*.yml), and knowledge of guardrails concepts
- OpenAI moderation integration scaffolding (OpenAIModerator) with API calls to a moderation endpoint
Caveats
License: MIT. It provides example code and configurations but does not guarantee safe operation; responsibilities for deployment risk are implied. Some sections present as illustrative configurations and may require adaptation to your environment and guardrail policies. The skill does not claim to cover all safety scenarios or replace professional compliance review.
# LLM Guardrails ## Overview Comprehensive guide for LLM safety and guardrails implementation. --- ## 1. Guardrails Concepts ### 1.1 What Are Guardrails? ```python """ LLM GUARDRAILS: Mechanisms to ensure safe, appropriate, and compliant AI outputs. Types of Guardrails: 1. INPUT GUARDRAILS - Filter and validate user inputs 2. OUTPUT GUARDRAILS - Filter and validate model outputs 3. BEHAVIORAL GUARDRAILS - Constrain model behavior 4. CONTEXTUAL GUARDRAILS - Apply rules based on context Why Guardrails Matter: - Safety: Prevent harmful content - Compliance: Meet regulatory requirements - Quality: Ensure consistent, useful outputs - Brand Protection: Maintain brand voice and values - Legal: Avoid liability from inappropriate content """ # Guardrail workflow example GUARDRAIL_WORKFLOW = """ User Input ↓ Input Guardrails ↓ (if passes) LLM Processing ↓ Output Guardrails ↓ (if passes) Final Output ↓ (if fails) Fallback Response """ ``` ### 1.2 Guardrail Categories ```python from enum import Enum from typing import List, Callable from dataclasses import dataclass class GuardrailType(Enum): """Types of guardrails.""" INPUT_FILTER = "input_filter" OUTPUT_FILTER = "output_filter" CONTENT_MODER
- Overview
- 1. Guardrails Concepts
- 1.1 What Are Guardrails?
- 1.2 Guardrail Categories
- 2. NeMo Guardrails
- 2.1 Setup and Installation
- 2.2 Rail Definitions
- 2.3 Fact-Checking
- 2.4 Jailbreak Prevention
- 3. Content Moderation
- 3.1 Input Filtering
- 3.2 Output Filtering
- 3.3 OpenAI Moderation API
- 4. Prompt Injection Prevention
Install NeMo Guardrails pip install nemoguardrails Install with additional dependencies pip install nemoguardrails[langchain] pip install nemoguardrails[openai]
What does the llm-guardrails skill do?
Comprehensive guide for LLM safety and guardrails implementation.
How do I install it?
Run `npx skills add majiayu000/claude-skill-registry --skill llm-guardrails --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From majiayu000/claude-skill-registry, a repository with 534 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
