pydantic-ai-shields
Guardrail capabilities for Pydantic AI — cost tracking, tool permissions, input/output guards
Decision gist · record as of 2026-08-14
Yes, if you are building Pydantic AI agents and need safety, cost control, or tool permission guardrails. The library is actively maintained, has low install friction, and composes naturally into agent capabilities. MIT license has no restrictions. Start with it if you need any of its built-in shields; the modular design lets you add only what you need. No known vulnerabilities.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.10 or later.
- Pricing auto-detection for CostTracking uses genai-prices; custom pricing may be needed for models not in that database.
- Low install friction with a pure-Python wheel.
License · maintenance · safety
MIT (permissive) — MIT license permits unrestricted use, modification, and distribution with minimal obligations—suitable for commercial and open-source projects.
last release 2026-06-01 (74 days) · last repo commit 2026-08-14 · 91 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 536,314 downloads/mo, #6,127 on PyPI
Alternatives
Verify before relying
pip install pydantic-ai-shields
from pydantic_ai import Agent
from pydantic_ai_shields import CostTracking, ToolGuard, InputGuard
agent = Agent(
"openai:gpt-4.1",
capabilities=[
CostTracking(budget_usd=5.0),
ToolGuard(blocked=["execute"], require_approval=["write_file"]),
InputGuard(guard=lambda prompt: "ignore all instructions" not in prompt.lower()),
],
)
result = await agent.run("Hello!")- Whether genai-prices covers all LLM providers and models you intend to use, or if custom pricing configuration is required.
- Performance overhead of concurrent guardrails (AsyncGuardrail with timing='concurrent') under high-throughput agent workloads.
- Accuracy and false-positive rates of built-in detectors (PromptInjection, PiiDetector, SecretRedaction) on real-world prompts.
What it is and what it does
Pydantic AI Shields is a library of ready-to-use guardrail capabilities that integrate directly into Pydantic AI agents without middleware wrappers. It provides infrastructure shields (cost tracking with budget enforcement, tool access control, custom input/output validation, and concurrent guardrail execution) and content shields (prompt injection detection across 6 categories, PII detection for email/phone/SSN/credit card/IP, secret redaction for API keys and tokens, blocked keyword filtering, and LLM refusal blocking).
You compose shields by passing them to an agent's `capabilities` parameter. Each shield raises a specific exception (InputBlocked, OutputBlocked, ToolBlocked, BudgetExceededError) when its guard condition fails. CostTracking auto-detects pricing from genai-prices; PromptInjection supports three sensitivity levels; PiiDetector and SecretRedaction use regex patterns; AsyncGuardrail can cancel LLM calls if guards fail first, saving cost. The library targets Pydantic AI agents and depends on pydantic-ai-slim and pydantic.
Use it for
- Enforce per-agent or per-run spending limits and track cumulative token costs across multiple LLM calls.
- Prevent agents from calling dangerous or sensitive tools without user approval or hide them entirely from the model.
- Detect and block prompt injection attempts, jailbreaks, and role-play exploits before they reach the LLM.
- Scan user input for PII (email, phone, SSN, credit card, IP) and block or log detections without stopping execution.
- Redact API keys, tokens, and credentials from model output to prevent accidental secret leakage.
- Run safety checks concurrently with LLM inference and cancel the LLM call if a guard fails, reducing wasted API costs.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you are building Pydantic AI agents and need safety, cost control, or tool permission guardrails.
The library is actively maintained, has low install friction, and composes naturally into agent capabilities. MIT license has no restrictions. Start with it if you need any of its built-in shields; the modular design lets you add only what you need. No known vulnerabilities.
Install
pydantic-ai-shields on PyPI
Before you install
Low install friction with a pure-Python wheel. Active maintenance (last commit 2026-08-14) and recent release cycle. Depends on pydantic-ai-slim and pydantic, both standard ecosystem packages.
Requires Python 3.10 or later. Pricing auto-detection for CostTracking uses genai-prices; custom pricing may be needed for models not in that database.
License in practice
MIT license permits unrestricted use, modification, and distribution with minimal obligations—suitable for commercial and open-source projects.
Quickstart
pip install pydantic-ai-shields
from pydantic_ai import Agent
from pydantic_ai_shields import CostTracking, ToolGuard, InputGuard
agent = Agent(
"openai:gpt-4.1",
capabilities=[
CostTracking(budget_usd=5.0),
ToolGuard(blocked=["execute"], require_approval=["write_file"]),
InputGuard(guard=lambda prompt: "ignore all instructions" not in prompt.lower()),
],
)
result = await agent.run("Hello!")
Verify before relying
- Whether genai-prices covers all LLM providers and models you intend to use, or if custom pricing configuration is required.
- Performance overhead of concurrent guardrails (AsyncGuardrail with timing='concurrent') under high-throughput agent workloads.
- Accuracy and false-positive rates of built-in detectors (PromptInjection, PiiDetector, SecretRedaction) on real-world prompts.
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.10 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 3 packagesgenai-pricespydantic-ai-slimpydantic |
| Maintenance | Actively maintained 74 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 536,314 / month, #6,127 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Topic :: Software Development :: Libraries :: Python ModulesTyping :: Typed |
Evidence: pydantic_ai_shields-0.3.4-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “pydantic ai guardrails”
- pydantic-ai-shieldsPydantic AI Shields provides guardrail capabilities for Pydantic AI…
- guardrails-ai-typesProvides type definitions and data structures for the Guardrails AI…
- guardrails-aiGuardrails is a Python framework that validates and constrains LLM…
Give your agent the search over MCP, or paste the wish link into any chat.
More Python Modules packages
Converts domain names between Unicode and ASCII-compatible encoding (Punycode) according to IDNA 2008 and Unicode Technical Standard 46, with security validation and broader script coverage than the standard library.
Install it if you work with internationalized domain names, need to validate domains, or use HTTP clients that depend on it transitively.
Setuptools is a Python build backend and package management tool that handles building, distributing, and installing Python packages, including support for C/C++ extension modules.
PyYAML parses and emits YAML 1.1 data format, enabling serialization and deserialization of configuration files and Python objects to and from human-readable YAML text.
Pydantic validates Python data structures against type hints, coercing and checking input at runtime to ensure it matches a declared schema.
Provides reusable metadata objects for use with PEP-593 `typing.Annotated` to express common constraints like bounds, collection sizes, and predicates on types.
Install it if you use or build libraries that need to express type constraints in a standardized, inspectable way—or if you want to annotate your own types with…
Provides runtime tools to inspect and introspect Python type annotations, enabling programmatic examination of type hints at execution time.
See also guardrails-ai · openai-guardrails · pydantic-ai-harness · pydantic-ai-backend · subagents-pydantic-ai · pydantic-ai · summarization-pydantic-ai · toolguard · plugin-scanner · codeshield