OpenAI Governance Quick Start
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 singleTealOpenAI 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
Pattern reference
| PII Type | Pattern | Example |
|---|---|---|
[^\s@]+@[^\s@]+\.[^\s@]+ | user@example.com | |
| SSN | \d{3}-\d{2}-\d{4} | 123-45-6789 |
| Phone | (\+1)?[\s.-]?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4} | 555-123-4567 |
| Credit Card | \d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4} | 4111-1111-1111-1111 |
| IP Address | \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} | 192.168.1.1 |
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
3. Guardrail Engine — Composing Multiple Guardrails
In production you’ll run multiple guardrails together. TheGuardrailEngine 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 (7 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 withPolicyBuilder.
Architecture Overview
TealTiger sits between your application and the AI provider. All enforcement decisions happen locally, before the request leaves your process.| Decision | Rationale |
|---|---|
| PII detection via regex | Sub-millisecond, no network dependency, deterministic |
| Injection detection via regex | Local-only, no data exfiltration risk |
| Content moderation via OpenAI Moderation API | Leverages OpenAI’s classifier (free endpoint), with local regex fallback |
| In-process enforcement | No sidecar, no proxy, no infrastructure to manage |
| Metadata-only audit events | Prompts/outputs are never persisted by default |
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
- Full Documentation — API reference and guides
- GitHub Repository — Source code, issues, discussions
- PyPI Package —
pip install tealtiger - OWASP Agentic Top 10 Mapping — How TealTiger maps to OWASP ASI01-ASI10
- HIPAA Medical Bot — Apply these concepts to a healthcare compliance scenario
- Stop Budget Runaway — Deep dive into cost governance policies

