Contents

Guardrails: Sensitive Information Protection

Guardrails intercepts content before every LLM call and applies configurable rules to detect, redact, block, or audit sensitive information.

Quick start

 1# Generate a starter config with common patterns
 2opensre guardrails init
 3
 4# Test it against sample text
 5opensre guardrails test "my key is AKIAIOSFODNN7EXAMPLE"
 6
 7# View configured rules
 8opensre guardrails rules

How it works

  1. Rules are loaded from ~/.opensre/guardrails.yml on first LLM call
  2. Before every LLM API request, all message content is scanned against the rules
  3. Depending on the rule action:
    • redact: matched text is replaced with [REDACTED:<rule_name>]
    • block: the request is rejected with a GuardrailBlockedError
    • audit: the match is logged but text passes through unchanged
  4. All matches are written to ~/.opensre/guardrail_audit.jsonl

If no guardrails.yml exists, all content passes through unchanged with zero overhead.

Configuration

The config file lives at ~/.opensre/guardrails.yml. Each rule can use regex patterns, keyword lists, or both.

 1rules:
 2  - name: aws_access_key
 3    description: "AWS access key IDs"
 4    action: redact
 5    patterns:
 6      - "(?:AKIA|ASIA)[A-Z0-9]{16}"
 7
 8  - name: credit_card
 9    description: "Credit card numbers"
10    action: block
11    patterns:
12      - "\\b\\d{4}[- ]?\\d{4}[- ]?\\d{4}[- ]?\\d{4}\\b"
13
14  - name: internal_domains
15    description: "Internal hostnames that should not leak"
16    action: audit
17    keywords:
18      - "prod-db.internal.corp"
19      - "staging.internal.corp"
20
21  - name: pii_fields
22    description: "Common PII field names"
23    action: redact
24    keywords:
25      - "social_security"
26      - "date_of_birth"
27    replacement: "[PII_REDACTED]"

Rule fields

Field Required Description
name yes Unique identifier for the rule
action no redact, block, or audit (default: audit)
patterns no* List of regex patterns (case-insensitive)
keywords no* List of literal keywords (case-insensitive)
description no Human-readable description
replacement no Custom replacement text (default: [REDACTED:<name>])
enabled no Set to false to disable without removing (default: true)

*At least one of patterns or keywords is required.

CLI commands

opensre guardrails init

Creates a starter ~/.opensre/guardrails.yml with common patterns for AWS keys, credit cards, private keys, and API tokens. Does not overwrite an existing config.

opensre guardrails test "text"

Dry-run: scans the provided text against all rules and shows what would be matched, redacted, or blocked.

$ opensre guardrails test "key=AKIAIOSFODNN7EXAMPLE"
  [REDACT] aws_access_key: matched 'AKIAIOSFODNN7EXAMPLE'

  Redacted output: key=[REDACTED:aws_access_key]

opensre guardrails rules

Lists all configured rules with their action and status.

opensre guardrails audit

Shows recent entries from the audit log at ~/.opensre/guardrail_audit.jsonl.

Health check

opensre health shows the current guardrails status:

CLI
  environment: development
  integration store: ~/.opensre/integrations.json
  guardrails: 5 rules active (~/.opensre/guardrails.yml)

Coverage

Guardrails protect all LLM call paths:

  • Custom Anthropic client (LLMClient.invoke)
  • OpenAI-compatible client (OpenAILLMClient.invoke)
  • Structured output calls (delegated to base client)
  • Interactive shell and gateway chat calls
  • Alert extraction prompts
  • Action planning prompts

Common patterns

Here are useful patterns you can add to your config:

 1# Email addresses
 2- name: email
 3  action: redact
 4  patterns:
 5    - "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}"
 6
 7# IPv4 addresses
 8- name: ipv4
 9  action: audit
10  patterns:
11    - "\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b"
12
13# GitHub personal access tokens
14- name: github_pat
15  action: redact
16  patterns:
17    - "ghp_[a-zA-Z0-9]{36}"
18    - "github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59}"
19
20# Slack webhook URLs
21- name: slack_webhook
22  action: redact
23  patterns:
24    - "https://hooks\\.slack\\.com/services/T[A-Z0-9]+/B[A-Z0-9]+/[a-zA-Z0-9]+"
25
26# JWT tokens
27- name: jwt
28  action: redact
29  patterns:
30    - "eyJ[A-Za-z0-9_-]+\\.eyJ[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+"