Skip to content

Pydantic AI

TapPass has no dedicated Pydantic AI module. Governance comes from two generic paths: wrap the agent’s tools with tappass.govern(), and/or route the model through the TapPass gateway.

tappass.govern(tools, ...) wraps any list of tools (mode "audit" by default; "enforce" blocks policy-denied calls with GovernanceBlocked). Wrap the functions before registering them with the agent:

import tappass
from pydantic_ai import Agent
search, send_email = tappass.govern(
[search, send_email],
url="https://tappass.example.com",
api_key="tp_...",
mode="enforce",
)
agent = Agent("openai:gpt-4o-mini", tools=[search, send_email])

Path 2 — route the model through the gateway

Section titled “Path 2 — route the model through the gateway”

Pydantic AI’s OpenAIModel and AnthropicModel both accept a base_url — so pointing them at TapPass is one line. Every completion (including retries) flows through the governance pipeline.

Terminal window
export OPENAI_BASE_URL=https://tappass.example.com/v1
export OPENAI_API_KEY=tp_...
from pydantic_ai import Agent
from pydantic import BaseModel
class Answer(BaseModel):
content: str
confidence: float
agent = Agent("openai:gpt-4o-mini", result_type=Answer)
result = agent.run_sync("What's the capital of Belgium?")
print(result.data.content, result.data.confidence)
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIModel
model = OpenAIModel(
"gpt-4o-mini",
base_url="https://tappass.example.com/v1",
api_key="tp_...",
)
agent = Agent(model, result_type=Answer)
from pydantic_ai.models.anthropic import AnthropicModel
model = AnthropicModel(
"claude-3-5-sonnet-20241022",
base_url="https://tappass.example.com",
api_key="tp_...",
)