Skip to main content
TealTiger ships three built-in guardrails. This page explains exactly how each one works — what techniques they use, what they call, and what they don’t.
TealTiger guardrails are deterministic by default. The same input produces the same result, unless you opt into API-based detection (content moderation with OpenAI).

Detection Techniques at a Glance


PII Detection

Technique: Pre-compiled regular expressions. PII detection is entirely local. No data leaves your process. It scans text against a set of regex patterns for common PII types.

Detected Types

How It Works

  1. Text is extracted from the input (handles strings, prompt objects, and message arrays)
  2. Each enabled pattern runs against the text using pre-compiled regex with global matching
  3. Matches are collected with position, length, and type metadata
  4. Risk score is the maximum score across all detected PII types

Performance Optimizations

  • Patterns compiled once at construction, reused across calls
  • LRU pattern cache (up to 100 entries) for repeated text
  • Early exit for text shorter than 3 characters
  • Configurable via detectTypes, action, riskScores

What It Does NOT Do

  • No named entity recognition (NER) or ML-based detection
  • No external API calls — all processing is in-process
  • Name detection is a basic heuristic (two capitalized words) and will produce false positives
  • Does not detect PII in non-Latin scripts

Prompt Injection Detection

Technique: Multi-category regex pattern matching with confidence scoring. Prompt injection detection is entirely local. It matches input text against categorized attack patterns and assigns a confidence score per detection.

Attack Categories

How It Works

  1. Input text is scanned against all pattern categories
  2. Each match produces a detection with type, matched text, and confidence score (0.7–0.98)
  3. Sensitivity level controls the threshold:
    • High: 1 match triggers detection
    • Medium: 1 match triggers detection
    • Low: 2+ matches required
  4. Overall risk score is the maximum across all detections

What It Does NOT Do

  • No ML-based semantic analysis — it’s pattern matching only
  • No external API calls
  • Cannot detect novel injection techniques not covered by patterns
  • Encoding detection flags the presence of encoding keywords, not decoded payloads

Content Moderation

Technique: Hybrid — OpenAI Moderation API (primary) with local regex fallback. This is the only guardrail that can make external API calls. When configured with an OpenAI API key, it sends text to the OpenAI Moderation endpoint. If the API is unavailable or no key is provided, it falls back to local pattern matching.

Detection Categories

How It Works

With OpenAI API (recommended for production):
  1. Text is sent to https://api.openai.com/v1/moderations via HTTPS POST
  2. OpenAI returns per-category scores (0.0–1.0) and flagged booleans
  3. Scores are compared against configurable thresholds
  4. Categories exceeding thresholds are flagged as violations
Local fallback (no API key or API failure):
  1. Text is scanned against keyword-based regex patterns per category
  2. Matches produce a binary flagged/not-flagged result (no confidence scores)
  3. Fewer categories are covered (no threatening or graphic sub-categories)

Data Flow Considerations

When useOpenAI: true, input text is sent to OpenAI’s Moderation API. If you handle sensitive data and cannot send it to external services, set useOpenAI: false to use local-only detection.

Execution Architecture

All three guardrails run through the GuardrailEngine, which provides:
  • Parallel execution: Guardrails run concurrently by default (configurable)
  • Timeout handling: 5-second default per guardrail
  • Error isolation: One guardrail failure doesn’t block others (continueOnError: true)
  • Result aggregation: Combined pass/fail, maximum risk score, list of failed guardrails
TealGuard sits on top and adds:
  • Policy integration (optional TealEngine evaluation)
  • Result caching with LRU eviction
  • Decision mapping to reason codes (PII_DETECTED, PROMPT_INJECTION_DETECTED, HARMFUL_CONTENT_DETECTED)
  • Correlation ID propagation for audit trails

Extending with Custom Guardrails

You can register custom guardrails that follow the same interface:

Summary

  • PII and prompt injection detection are fully local, deterministic, and regex-based
  • Content moderation optionally calls OpenAI’s Moderation API for higher accuracy
  • No embedded ML models — the SDK stays lightweight and predictable
  • All guardrails are configurable, extensible, and run in parallel with timeout protection
For policy-level controls that wrap these guardrails, see Policy Overview and Conditions & Actions.