Registry / ai-ml / pydantic-ai-shields

pydantic-ai-shields

JSON →
library0.3.4pypypi✓ verified 82d ago

Adds guardrail capabilities to Pydantic AI agents: cost tracking, tool permissions, input/output guards. Current version 0.3.4, early-stage development with weekly releases.

pip install pydantic-ai-shields
INSTALL
IMPORT
SIG · PYDANTIC-AI-SHIELD
P
pydantic-ai-shields
ai-mlpythonv0.3.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AsyncGuardrail
from pydantic_ai_shields import AsyncGuardrail
from pydantic_ai_shields import CostGuard
CostTracking
from pydantic_ai_shields import CostTracking
InputGuard
from pydantic_ai_shields import InputGuard

Simple agent with cost and permission guards

import os from pydantic_ai import Agent from pydantic_ai_shields import CostGuard, PermissionGuard agent = Agent('openai:gpt-4o') cost_guard = CostGuard(max_cost=0.1) perm_guard = PermissionGuard(permissions={'create_file': True}) agent.shield(cost_guard).shield(perm_guard) result = agent.run_sync('Write a poem to hello.txt') print(result.data)
Debug
Known issues
gotchaGuard ordering matters: guards are applied in the order they are shielded. Add cost guard first to avoid unnecessary execution if budget exceeded.
fix
Call shield() on agent in desired order: agent.shield(cost_guard).shield(perm_guard).
affects: all
gotchaThe library is experimental (pre-1.0). APIs may break without major version bump.
fix
Pin to exact minor version (e.g., 0.3.4) and test upgrades.
affects: 0.x
deprecatedAs of 0.3.0, shield() method replaced add_guard(). Old code using add_guard will raise AttributeError.
fix
Replace agent.add_guard(guard) with agent.shield(guard).
affects: <0.3.0
Upgrade
Version history
0.3.4latest on PyPI · released Jun 1, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
8
Bingbot
1
OpenAI (training)
1
Resources
pydantic-ai-shields — pip install pydantic-ai-shields · libregistry