Skip to main content

pydanticai-tealtiger

Deterministic governance guard for Pydantic AI agents — policy enforcement, PII detection, cost tracking, kill switch, and structured audit evidence.

No LLM in the governance path. All policy evaluation is deterministic, adding <2ms latency per call.

PyPI Python License

Installation

pip install pydanticai-tealtiger

Quick Start

from pydantic_ai import Agent
from pydanticai_tealtiger import TealTigerGuard

# Zero-config: observe, track cost, detect PII, allow all
guard = TealTigerGuard()

agent = Agent('openai:gpt-4', deps_type=TealTigerGuard)

@agent.tool
async def search(ctx, query: str) -> str:
    # Governance check before execution
    ctx.deps.evaluate(tool="search", args={"query": query})
    result = perform_search(query)
    # Record cost after execution
    ctx.deps.post_call(tool_name="search", result=result)
    return result

# Run with governance
result = await agent.run("Find AI safety papers", deps=guard)

# Inspect governance data
print(guard.cumulative_cost)
print(guard.audit_trail)
print(guard.summary)

Features

Feature Description
Zero-config mode Observe all tool calls, track cost, detect PII — no setup required
Policy mode Evaluate TealEngine policies, block on DENY in ENFORCE mode
PII detection Detect email, SSN, credit card, phone, IP in tool arguments
Cost tracking Per-tool, per-session cost accumulation
Budget limits Set max spend per session — deny when exceeded
Tool allowlist Restrict which tools can be invoked
Kill switch freeze() / unfreeze() to halt all tool execution
Audit trail Structured entries with UUID v4 correlation IDs
TEEC namespace teec.pydanticai evidence contract fields

Governance Modes

Mode Behavior
OBSERVE Allow all, log decisions, track cost (default)
MONITOR Allow all, log denials as warnings
ENFORCE Block denied actions, raise GovernanceDenyError

Usage Patterns

Policy Mode with TealEngine

from tealtiger import TealEngine
from pydanticai_tealtiger import TealTigerGuard

engine = TealEngine(policies=[
    {"type": "cost_limit", "max_per_session": 5.00},
    {"type": "pii_block", "action": "DENY"},
])

guard = TealTigerGuard(engine=engine, mode="ENFORCE")

Tool Allowlist

guard = TealTigerGuard(
    mode="ENFORCE",
    tool_allowlist=["search", "compute", "read_file"],
)

Budget Limit

guard = TealTigerGuard(
    mode="ENFORCE",
    budget_limit=1.00,  # $1.00 max per session
)

Kill Switch

guard = TealTigerGuard(mode="ENFORCE")

# Emergency stop — blocks all subsequent calls
guard.freeze()

# Resume operations
guard.unfreeze()

pre_call / post_call Pattern

@agent.tool
async def my_tool(ctx, arg: str) -> str:
    # pre_call is an alias for evaluate
    ctx.deps.pre_call(tool_name="my_tool", args={"arg": arg})

    result = do_work(arg)

    # Record actual cost
    ctx.deps.post_call(
        tool_name="my_tool",
        result=result,
        token_usage={"total_tokens": 500},
    )
    return result

API Reference

TealTigerGuard

Parameter Type Default Description
engine TealEngine | None None Policy engine for evaluation
mode str "OBSERVE" Governance mode
cost_per_1k_tokens float 0.002 Cost estimation rate
session_id str | None auto-generated Session identifier
tool_allowlist list[str] | None None Allowed tool names
budget_limit float | None None Max cost per session (USD)

Methods

Method Description
evaluate(tool, args, agent_id) Evaluate governance before tool execution
pre_call(tool_name, args) Alias for evaluate()
post_call(tool_name, result, token_usage) Record cost after tool execution
freeze() Activate kill switch
unfreeze() Deactivate kill switch

Properties

Property Type Description
audit_trail list[AuditEntry] Full governance audit trail
summary dict[str, ToolSummary] Cost/call counts per tool
cumulative_cost float Total session cost
session_id str Session identifier

Development

cd packages/pydanticai-tealtiger
pip install -e ".[dev]"
pytest

License

Apache-2.0 — see LICENSE.

Release files for pydanticai-tealtiger 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydanticai-tealtiger 0.1.0
File Size Uploaded
pydanticai_tealtiger-0.1.0.tar.gz 20.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydanticai-tealtiger 0.1.0
File Interpreter ABI Platform
pydanticai_tealtiger-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 34.4 kB

Release files / pydanticai_tealtiger-0.1.0.tar.gz

Download URL pydanticai_tealtiger-0.1.0.tar.gz
Size 20.1 kB
Tags Source
SHA-256 checksum
How to use checksums
bdf24d9912b431c2bcd98ab2d8198ca828fd09714e1607a08a4c744037b22eda
BLAKE2b-256 checksum
How to use checksums
4a8fd1aa87f0248637dff447a0ab18eca3307b6ebb02269009e1dce351a7f42f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / pydanticai_tealtiger-0.1.0-py3-none-any.whl

Download URL pydanticai_tealtiger-0.1.0-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df0f768f18e3f5a70b0a39ce3f39026eb655ed5106de2b1fd8f5d8b0a372cefb
BLAKE2b-256 checksum
How to use checksums
f547689d7e2d63930c838f950fcea2c184ebb8e85c64f4d607e9e9705c616184
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page