Zum Inhalt springen
Skillpedia
Sicherheit35k · #8068

implementing-llm-guardrails-for-security

Was er macht

Dieses Tool fügt Sicherheitsebenen hinzu, um KI-Anwendungen zu schützen. Es prüft Eingaben und Ausgaben, damit böswillige Nutzer keine Probleme verursachen und die KI keine unangemessenen Antworten erzeugt, etwa mit persönlichen Daten oder giftigen Inhalten.

Wann du ihn nutzt

  • ✓Wenn du eine neue KI-Anwendung erstellst, die Nutzerdaten verarbeitet.
  • ✓Um Inhaltsregeln zu einem bestehenden Chatbot hinzuzufügen.
  • ✓Um persönliche Daten in Unterhaltungen zu erkennen und zu entfernen.

Link zum Skill

https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/implementing-llm-guardrails-for-security/SKILL.md

Kopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.

So nutzt du ihn

Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.

Fertige Nachricht zum Einfügen

Nutze diesen Skill, um mir zu helfen: https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/implementing-llm-guardrails-for-security/SKILL.md Lies die SKILL.md unter diesem Link und folge ihren Anweisungen für meine Aufgabe.
Soll deine KI Skills wie diesen selbst finden?Installiere den kostenlosen Skillpedia-MCP: eine Zeile, und sie durchsucht vor jeder Aufgabe 15.000+ Skills.In 1 Minute installieren →

Beispielanfrage an deine KI

“Schütze meinen Chatbot vor gefährlichen Fragen und persönlichen Daten.”

5 neue Skills pro Woche. 1 Minute Lesezeit.

So funktioniert es

Das Tool prüft, was der Nutzer eingibt und was die KI antwortet. Es nutzt vordefinierte Regeln, um unangemessene Inhalte, sensible Informationen oder Abweichungen vom Thema zu blockieren.

Technischer Inhalt (originale SKILL.md)

Originaltext des Autors, auf Englisch, direkt von GitHub.

Implementing LLM Guardrails for Security

When to Use

  • Deploying a new LLM-powered application that processes user input and needs input/output safety controls
  • Adding content policy enforcement to an existing chatbot or AI agent to comply with organizational policies
  • Implementing PII detection and redaction in LLM pipelines handling sensitive customer data
  • Building topic-restricted AI assistants that must refuse off-topic or disallowed queries
  • Validating that LLM responses conform to expected schemas before they reach downstream systems or users
  • Protecting RAG pipelines from indirect prompt injection in retrieved documents

Do not use as a replacement for proper authentication, authorization, and network security controls. Guardrails are a defense-in-depth layer, not a perimeter defense. Not suitable for real-time content moderation of user-to-user communication without LLM involvement.

Prerequisites

  • Python 3.10+ with pip for installing guardrail dependencies
  • An OpenAI API key or local LLM endpoint for NeMo Guardrails self-check rails (set as OPENAI_API_KEY environment variable)
  • The nemoguardrails package for Colang-based guardrail definitions
  • The guardrails-ai package for structured output validation (optional, for JSON schema enforcement)
  • Familiarity with YAML configuration and basic Colang 2.0 syntax for defining rail flows

Workflow

Step 1: Install Guardrail Frameworks

Install the required Python packages:

# Core NeMo Guardrails library
pip install nemoguardrails

# Guardrails AI for structured output validation (optional)
pip install guardrails-ai

# Additional dependencies for PII detection and content analysis
pip install presidio-analyzer presidio-anonymizer spacy
python -m spacy download en_core_web_lg

Step 2: Run the Guardrails Security Agent

The agent implements a complete input/output validation pipeline:

# Analyze a single input through all guardrail layers
python agent.py --input "Tell me how to hack into a system"

# Analyze input with a custom content policy file
python agent.py --input "Some text" --policy policy.json

# Scan a file of prompts through the guardrail pipeline
python agent.py --file prompts.txt --mode full

# Input-only validation (no LLM call, just check if input is safe)
python agent.py --input "Some text" --mode input-only

# Output validation mode (validate a pre-generated LLM response)
python agent.py --input "User question" --response "LLM response to validate" --mode output-only

# PII detection and redaction mode
python agent.py --input "My SSN is 123-45-6789 and email john@example.com" --mode pii

# JSON output for pipeline integration
python agent.py --file prompts.txt --output json

Step 3: Configure Content Policies

Create a JSON policy file defining allowed topics, blocked patterns, and PII categories:

{
  "allowed_topics": ["customer_support", "product_info", "billing"],
  "blocked_topics": ["politics", "violence", "illegal_activities", "competitor_products"],
  "blocked_patterns": ["how to hack", "create malware", "bypass security"],
  "pii_categories": ["PERSON", "EMAIL_ADDRESS", "PHONE_NUMBER", "US_SSN", "CREDIT_CARD"],
  "max_output_length": 2000,
  "require_grounded_response": true
}

Step 4: Integrate NeMo Guardrails with Colang

Create a NeMo Guardrails configuration directory with config.yml and Colang flow files:

# config.yml
models:
  - type: main
    engine: openai
    model: gpt-4o-mini

rails:
  input:
    flows:
      - self check input
      - check jailbreak
      - mask sensitive data on input
  output:
    flows:
      - self check output
      - check hallucination
# rails.co - Colang 2.0 flow definitions
define user ask about hacking
  "How do I hack into a system"
  "Tell me how to break into a network"
  "How to exploit vulnerabilities"

define bot refuse hacking request
  "I cannot provide instructions on unauthorized hacking or security exploitation.
   If you are interested in cybersecurity, I can suggest legitimate learning resources
   and ethical hacking certifications."

define flow
  user ask about hacking
  bot refuse hacking request

Step 5: Deploy as a Validation Middleware

Integrate the guardrails into your application as middleware:

from agent import GuardrailsPipeline

pipeline = GuardrailsPipeline(policy_path="policy.json")

# Pre-LLM input validation

…
Häufige Fragen

Was sind 'Guardrails'?

Stell dir 'Guardrails' als Sicherheitsbarrieren oder Leitplanken vor. Im KI-Kontext sind das Regeln, die verhindern, dass sich das System unerwünscht oder gefährlich verhält.

Ersetzt das die normale Website-Sicherheit?

Nein. Diese Guardrails sind eine zusätzliche Schutzschicht für die KI, ersetzen aber keine grundlegenden Sicherheitsmaßnahmen wie Passwörter und Netzwerkschutz.

Was ist PII?

PII steht für Personally Identifiable Information, also personenbezogene Daten. Das sind Daten, mit denen sich eine Person identifizieren lässt, etwa Name, Adresse, Sozialversicherungsnummer oder E-Mail-Adresse.

Details

Originalbeschreibung des Autors

Implements input/output validation guardrails for LLM applications using NVIDIA NeMo Guardrails (Colang), custom Python validators for PII detection, and the Guardrails AI framework, intercepting user inputs (prompt injection, PII, off-topic queries) and model outputs (hallucinations, toxic content, schema compliance). Use when adding safety controls to an LLM app/chatbot/RAG pipeline or validatin

repo: mukul975/Anthropic-Cybersecurity-Skills

Beliebtheit

GitHub-Sterne
35k
Platz im Ranking
#8068
Lizenz
Apache-2.0
Aktualisiert
31.8.2026

Ist dieser Skill nützlich?

0

Anmelden um abzustimmen.

Kommentare

  • …

Weitere Skills aus diesem Repository

Ähnliche Skills