Installation
Basic Installation
Section titled “Basic Installation”Install pydantic-ai-guardrails using pip:
pip install pydantic-ai-guardrailsuv add pydantic-ai-guardrailspoetry add pydantic-ai-guardrailsThis installs the core library with all built-in guardrails.
Optional Dependencies
Section titled “Optional Dependencies”Additional features are available through optional dependencies:
Telemetry (Logfire/OpenTelemetry)
Section titled “Telemetry (Logfire/OpenTelemetry)”For observability and tracing:
pip install pydantic-ai-guardrails[telemetry]This adds:
opentelemetry-apiopentelemetry-sdk
Pydantic Evals Integration
Section titled “Pydantic Evals Integration”To use pydantic_evals evaluators as guardrails:
pip install pydantic-ai-guardrails[evals]This adds:
pydantic-evals
All Features
Section titled “All Features”Install everything:
pip install pydantic-ai-guardrails[all]Third-Party Integrations
Section titled “Third-Party Integrations”For additional guardrail capabilities, you can install these complementary libraries:
llm-guard
Section titled “llm-guard”Battle-tested ML models for prompt injection, toxicity, and sensitive data detection:
pip install llm-guardSee llm-guard integration for usage.
autoevals
Section titled “autoevals”LLM-powered evaluations from Braintrust:
pip install autoevalsSee autoevals integration for usage.
Requirements
Section titled “Requirements”- Python: 3.10 or higher
- pydantic-ai: 1.39.0 or higher
Verify Installation
Section titled “Verify Installation”Check that everything is installed correctly:
import pydantic_ai_guardrails
print(pydantic_ai_guardrails.__version__)You can also verify the available guardrails:
from pydantic_ai_guardrails.guardrails.input import ( length_limit, pii_detector, prompt_injection,)from pydantic_ai_guardrails.guardrails.output import ( secret_redaction, llm_judge,)
print("Installation successful!")Next Steps
Section titled “Next Steps”Now that you have pydantic-ai-guardrails installed, head to the Quick Start guide to create your first guarded agent.