← Back to all products

AI Safety & Guardrails Kit

$39

Input/output filtering, toxicity detection, PII redaction, hallucination detection, and content policy enforcement scripts.

📁 31 files
MarkdownYAMLPythonLLM

📄 Product Preview

Try the interactive reader and demo tools below, or get the full product with all content unlocked.

📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample

📁 File Structure 31 files

ai-safety-guardrails/ ├── LICENSE ├── README.md ├── free-sample.zip ├── guide/ │ └── 01-safety-guide.md ├── guides/ │ └── safety-guide.md ├── index.html ├── policies/ │ ├── default_policy.yaml │ └── strict_policy.yaml ├── requirements.txt ├── src/ │ ├── __init__.py │ ├── __pycache__/ │ │ ├── __init__.cpython-312.pyc │ │ ├── groundedness_checker.cpython-312.pyc │ │ ├── injection_detector.cpython-312.pyc │ │ ├── input_filter.cpython-312.pyc │ │ ├── output_filter.cpython-312.pyc │ │ ├── pii_detector.cpython-312.pyc │ │ ├── policy_engine.cpython-312.pyc │ │ └── toxicity_detector.cpython-312.pyc │ ├── groundedness_checker.py │ ├── injection_detector.py │ ├── input_filter.py │ ├── output_filter.py │ ├── pii_detector.py │ ├── policy_engine.py │ └── toxicity_detector.py └── tests/ ├── __pycache__/ │ ├── test_injection_detector.cpython-312.pyc │ ├── test_pii_detector.cpython-312.pyc │ └── test_policy_engine.cpython-312.pyc ├── test_injection_detector.py ├── test_pii_detector.py └── test_policy_engine.py

📖 Documentation Preview README excerpt

AI Safety Guardrails

Input/output filtering, PII detection, prompt injection defense, toxicity

screening, and configurable policy enforcement for LLM applications.

Runs entirely on Python stdlib — no external dependencies required.

Why This Exists

Every LLM application needs safety guardrails, but most teams either:

  • Ship without them ("we'll add safety later")
  • Build ad-hoc regex checks that miss obvious attacks
  • Pay for a hosted safety API that adds latency and vendor lock-in

This toolkit gives you a complete safety stack that runs locally with zero

latency overhead, zero external dependencies, and full auditability. Use it

as your primary safety layer for internal tools, or as a fast pre-filter

before a heavier ML-based classifier for high-stakes applications.

Features

  • PII Detection & Redaction — Regex-based detection of emails, phone numbers

(US/international), credit cards (with Luhn validation), SSN-format numbers,

IP addresses, passport-style IDs, and custom patterns. Context-aware confidence

scoring reduces false positives.

  • Prompt Injection Defense — 4-layer detection: known attack patterns,

structural analysis, encoding/obfuscation detection, and statistical anomaly

scoring. Catches direct overrides, DAN jailbreaks, delimiter injection,

conversation injection, base64 payloads, and unicode homoglyphs.

  • Toxicity Screening — Keyword and heuristic-based detection of threats,

self-harm content, harassment, hate speech, and profanity (configurable).

  • Groundedness Checking — Heuristic analysis of whether LLM output is

supported by provided source material. Catches hallucinated entities, numbers,

and unsupported claims.

  • Policy Engine — Configurable rule-based system that combines all detectors

into unified allow/redact/flag/block decisions. Three built-in presets

(default, strict, permissive) plus custom policy support via JSON/YAML.

  • Input & Output Filters — Unified pre/post-processing wrappers for

the full safety pipeline.

Quick Start

5-Minute Integration


from src.input_filter import InputFilter
from src.output_filter import OutputFilter

input_guard = InputFilter()
output_guard = OutputFilter()

def safe_chat(user_message: str) -> str:
    # Check user input
    input_result = input_guard.check(user_message)
    if not input_result.allowed:
        return input_result.rejection_message

    # Call your LLM with filtered text (PII already redacted)
    response = your_llm(input_result.filtered_text)

    # Check model output

*... continues with setup instructions, usage examples, and more.*

📄 Code Sample .py preview

src/groundedness_checker.py """ Groundedness Checker — AI Safety Guardrails ============================================= Checks whether an LLM's output is grounded in provided source material. Hallucination — where the model generates factually incorrect or unsupported claims — is one of the hardest safety problems in LLM applications. This module provides heuristic checks that catch common hallucination patterns without requiring a second LLM call. Detection strategies (stdlib-only): 1. Named entity coverage: Do entities in the response appear in the source? 2. Numerical consistency: Do numbers in the response match the source? 3. Claim density: High density of specific claims without source backing suggests confabulation. 4. Hedging analysis: Lack of appropriate hedging on uncertain claims. For higher accuracy, combine with an LLM-as-judge groundedness check. Runs on Python stdlib. """ from __future__ import annotations import logging import re from dataclasses import dataclass, field from typing import Any, Dict, List, Optional, Set logger = logging.getLogger(__name__) @dataclass class GroundednessResult: """Result of groundedness analysis.""" response: str source: str is_grounded: bool # True if response appears grounded overall_score: float # 0.0 (hallucinated) to 1.0 (fully grounded) entity_coverage: float # What fraction of response entities appear in source number_consistency: float # How well numbers match between source and response claim_density_score: float # Penalizes high claim density without source backing unsupported_entities: List[str] unsupported_numbers: List[str] details: Dict[str, Any] = field(default_factory=dict) class GroundednessChecker: """Checks whether a response is grounded in provided source material. # ... 271 more lines ...
Buy Now — $39 Back to Products