$npx skillfedfor your agent

pydantic-ai-shields

Guardrail capabilities for Pydantic AI — cost tracking, tool permissions, input/output guards

With conditionsPyPI Python ModulesReleased Jun 2026536.3K downloads / moMITPure Python

Decision gist · record as of 2026-08-14

pure-Python wheel — pydantic_ai_shields-0.3.4-py3-none-any.whl
v0.3.4 · released 2026-06-01 · Python >=3.10 · 3 runtime deps: genai-prices, pydantic-ai-slim, pydantic

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

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.
Same gist for agents: .md · .json

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.

With conditions

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

LicenseMIT permissive
Python supportSupports the current Python release >=3.10
Install frictionLow. Pure-Python wheel
Runtime dependencies
3 packages
genai-pricespydantic-ai-slimpydantic
MaintenanceActively maintained 74 days since the last release
Last repo commit
First released
Downloads536,314 / month, #6,127 on PyPI 30-day window, as of 2026-08-14
Known vulnerabilitiesNone 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

Capabilities
pydantic ai guardrailscost tracking for llm agentsprompt injection detectionpii detection and redactiontool permission controlai safety guardrailsagent input output validation
Topics
guardrailscost-controlsafety-checks

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

idna Worth it
PyPI · Python Modules · released Jun 2026

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.

BSD-3-Clausepure Python · 3.9+
1.8Bdownloads / mo
setuptools Worth it
PyPI · Python Modules · released Aug 2026

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.

MITpure Python · 3.10+
1.6Bdownloads / mo
PyYAML Worth it
PyPI · Python Modules · released Sep 2025

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.

MITcompiled wheel · 3.8+
1.2Bdownloads / mo
pydantic Worth it
PyPI · Python Modules · released May 2026

Pydantic validates Python data structures against type hints, coercing and checking input at runtime to ensure it matches a declared schema.

MITpure Python · 3.9+
1.1Bdownloads / mo
annotated-types Worth it
PyPI · Python Modules · released Jul 2026

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…

MITpure Python · 3.10+
871.3Mdownloads / mo
typing-inspection Worth it
PyPI · Python Modules · released Aug 2026

Provides runtime tools to inspect and introspect Python type annotations, enabling programmatic examination of type hints at execution time.

MITpure Python · 3.10+
783.0Mdownloads / mo

See also guardrails-ai · openai-guardrails · pydantic-ai-harness · pydantic-ai-backend · subagents-pydantic-ai · pydantic-ai · summarization-pydantic-ai · toolguard · plugin-scanner · codeshield

Further reading