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.
Path 1 — govern the tools
Section titled “Path 1 — govern the tools”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 tappassfrom 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.
export OPENAI_BASE_URL=https://tappass.example.com/v1export OPENAI_API_KEY=tp_...from pydantic_ai import Agentfrom 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)Explicit base URL
Section titled “Explicit base URL”from pydantic_ai import Agentfrom 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)Anthropic
Section titled “Anthropic”from pydantic_ai.models.anthropic import AnthropicModel
model = AnthropicModel( "claude-3-5-sonnet-20241022", base_url="https://tappass.example.com", api_key="tp_...",)