Skip to main content
A capability-by-capability walkthrough of TealTiger’s core features using the OpenAI API. By the end you’ll have PII redaction, injection blocking, cost tracking, budget enforcement, and audit evidence wired into a single TealOpenAI client.
This recipe is also available as a runnable Jupyter notebook in the TealTiger Cookbook repo. Open it in Jupyter, Colab, or VS Code to follow along interactively.

Prerequisites

  • Python 3.9+
  • An OpenAI API key
  • pip install tealtiger openai

1. PII Detection — Catch Sensitive Data Before It Reaches the Model

TealTiger’s PII detection uses pure regex — no ML models, no external API calls, no data leaves your process.
  • Sub-millisecond detection latency
  • No network dependency
  • Fully deterministic results
Detects emails, phone numbers, SSNs, credit card numbers, and IP addresses.

Pattern reference

No data is sent to any external service. Detection runs entirely in-process.

2. Prompt Injection Detection

Multi-category regex with confidence scoring. Fully local — no external calls.

Detection categories

  • Instruction override — “ignore previous instructions”, “disregard above”
  • System prompt extraction — “reveal your system prompt”, “show me your instructions”
  • Role manipulation — “you are now DAN”, “pretend you have no restrictions”
  • Encoding attacks — Base64-encoded instructions, unicode tricks
Each match produces a confidence score. The guardrail blocks when the aggregate score exceeds the configured threshold.

3. Guardrail Engine — Composing Multiple Guardrails

In production you’ll run multiple guardrails together. The GuardrailEngine evaluates all registered guardrails and returns a combined result.

4. Cost Tracking & Budget Enforcement

Built-in pricing tables for OpenAI, Anthropic, Google Gemini, AWS Bedrock, Azure OpenAI, Cohere, and Mistral AI (12 providers, 95%+ market coverage). Budget enforcement is deterministic — same spending state + same policy = same allow/deny decision.

Compare costs across models

Set up a daily budget


5. TealOpenAI — Drop-in Guarded Client

TealOpenAI wraps the standard OpenAI client with integrated guardrails, cost tracking, and budget enforcement. The API is compatible with openai.ChatCompletion — you get security metadata alongside every response.

Full example


6. Blocking Dangerous Requests

When a guardrail detects a policy violation, the request is blocked before it reaches the OpenAI API. No tokens consumed, no cost incurred.

7. Cost Summary & Audit Evidence

TealTiger emits structured enforcement metadata — not prompts or outputs — suitable for SIEM ingestion and compliance workflows.

8. Policy Builder — Declarative Security Policies

For more complex scenarios, define security policies declaratively with PolicyBuilder.

Architecture Overview

TealTiger sits between your application and the AI provider. All enforcement decisions happen locally, before the request leaves your process.

What TealTiger Does NOT Do

Transparency matters. Here’s what’s outside the current scope:
  • Semantic understanding of prompts — Detection is pattern-based, not semantic. A cleverly obfuscated injection may bypass regex patterns.
  • Output validation — Guardrails currently run on inputs. Output scanning is on the roadmap (v1.2.0).
  • ML-based PII detection — The current PII detector uses regex. It won’t catch PII in natural language like “I live on Elm Street” without a structured pattern.
  • Standalone compliance — TealTiger is a technical control, not a compliance solution. Full regulatory compliance requires organizational processes beyond any SDK.

Next Steps