AI Safety & Guardrails Kit
Input/output filtering, toxicity detection, PII redaction, hallucination detection, and content policy enforcement scripts.
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 SampleFile Structure 36 files
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.*