Lightweight content safety scanning for Go LLM applications.
guard := guardrails.New(
guardrails.WithScanner(scanners.NewPII(), guardrails.ActionRedact),
guardrails.WithScanner(scanners.NewToxicity(), guardrails.ActionBlock),
guardrails.WithScanner(scanners.NewPromptInjection(), guardrails.ActionBlock),
)
result := guard.Scan(ctx, userInput)
if !result.Passed {
// Input blocked
}go get github.com/promptrails/guardrails| Scanner | Detects | Redaction |
|---|---|---|
| PII | Email, phone, SSN, credit card, IP address | Yes |
| Toxicity | Offensive language (keyword matching) | No |
| BanSubstrings | Custom banned words/phrases | Yes |
| PromptInjection | Override instructions, jailbreaks, role hijacking | No |
| Secrets | API keys, tokens, private keys, connection strings | Yes |
| InvisibleText | Hidden Unicode characters (prompt injection) | Yes |
| NoRefusal | LLM refusal phrases ("I'm sorry", "As an AI") | No |
| TokenLimit | Max word count enforcement | No |
| ReadingTime | Max reading time in seconds | No |
| JSONValidator | JSON structure + required keys | No |
| URLReachability | Hallucinated/unreachable URLs | No |
| BanCode | Code snippets (10 language patterns) | No |
| MaliciousURL | Suspicious TLDs, IP hosts, phishing keywords | No |
| Sentiment | Negative sentiment (lexicon-based) | No |
| Action | Behavior |
|---|---|
ActionBlock |
Stop processing, mark as failed |
ActionRedact |
Replace matches with labels, continue |
ActionLog |
Record violation, continue unchanged |
For ML-powered scanning, the llmguard sub-package connects to LLM Guard:
import "github.com/promptrails/guardrails/llmguard"
client := llmguard.NewClient("http://localhost:8000", "")
guard := guardrails.New(
guardrails.WithScanner(
llmguard.NewScanner(client, "Toxicity", guardrails.ScannerToxicity),
guardrails.ActionBlock,
),
)| Getting Started | Installation and quick start |
| Scanners | All scanners with config options |
| LLM Guard | ML-powered scanning via LLM Guard API |
| Custom Scanners | Build your own scanner |
Full docs: promptrails.github.io/guardrails
MIT — PromptRails
- LangRails — Unified LLM provider
- GuardRails — Content safety scanning
- MemoryRails — Agent memory
- MediaRails — AI media generation
- Go AI Toolkit — Demo app