PydanticAI¶
agent_airlock.integrations.pydantic_ai is the canonical adapter for
PydanticAI. It is the v0.7.1 promotion of
the previously example-only PydanticAI integration to adapter-shipped.
Why an adapter (not just @Airlock())¶
PydanticAI v1.88.0 (2026-04-29) added concrete Agent-level extension
hooks — output_validate, output_process, prepare_output_tools. The
adapter binds to those hooks so users don't have to remember the
@framework_decorator over @Airlock() rule themselves; one
wrap_agent(agent, policy=...) call walks every toolset and wires
the hooks.
Install¶
The extra pins pydantic-ai>=1.88.0,<2.0. v1.88.0 is the floor because
that's the release that introduced the output_validate hook the
adapter binds to (PR pydantic/pydantic-ai#4859).
Quickstart¶
from agent_airlock.integrations.pydantic_ai import PydanticAIAdapter
from agent_airlock.policy import STRICT_POLICY
from pydantic_ai import Agent
agent = Agent("openai:gpt-4o", system_prompt="You are a helpful assistant.")
@agent.tool_plain
def get_weather(city: str) -> str:
return f"Weather in {city}: 22°C"
# wrap_agent walks every toolset and Airlock-decorates each tool callable.
adapter = PydanticAIAdapter()
adapter.wrap_agent(agent, policy=STRICT_POLICY)
# Now every tool call routes through the configured policy:
# - ghost-arg stripping
# - Pydantic V2 strict validation
# - PolicyViolation on denied tools
# - sanitization on the model's structured output (output_validate)
result = agent.run_sync("What's the weather in Bangalore?")
What the adapter does¶
-
Walks
agent.toolsets(PydanticAI v1.88+ public surface) and replaces each function-tool's callable with theAirlock(policy=...)-wrapped version. Tools are re-tagged soSecurityPolicy.allowed_tools/denied_toolslists target the tool's name, not its method name. -
Attaches
output_validate(defaultattach_output_validate=True). The hook runsagent_airlock.sanitizer.sanitize_outputover the model's structured output before it leaves the boundary. -
Pins
SUPPORTED_PYDANTIC_AI_VERSIONS = ("1.88.0", "1.89.0", "1.89.1")— running a version outside this set emits aUserWarning(no hard fail). Update the tuple once a new release has been smoke-tested against the adapter.
Honest scope¶
- The adapter does not import
pydantic_aiat module load — passing a stub agent (any object with atoolsetsortoolsattribute) works without the extra installed. This is what the test suite uses. - Real PydanticAI objects (whose
__module__starts withpydantic_ai.*) do trigger the import check. If the extra is missing, the adapter raisesPydanticAIMissingErrorwith a clear install hint. - The example-only path (
examples/pydanticai_integration.py) remains documented and still works —@Airlock()over a raw@agent.tool_plainis supported.
Primary sources¶
- PydanticAI v1.89.1 release (2026-05-01)
- PydanticAI v1.89.0 release (2026-05-01)
- PydanticAI v1.88.0 release (2026-04-29) — introduces the
output_validatehook - pydantic/pydantic-ai#4859 —
prepare_output_tools/output_validatePR - Cross-link to legacy decorator-only path:
examples/pydanticai_integration.py