Installation and setup#
Install#
pip install pydantic-ai-enkrypt
The package depends on pydantic-ai-slim, pydantic-ai-harness and httpx. Install your model provider’s extra separately, for example pydantic-ai-slim[openai] or pydantic-ai-slim[bedrock].
Create an Enkrypt object#
Every guard comes from one Enkrypt object. It holds your account settings and the state its guards share.
from pydantic_ai_enkrypt import Enkrypt
enkrypt = Enkrypt(api_key="...")
For an on-prem Enkrypt installation, also pass its address:
enkrypt = Enkrypt(api_key="...", base_url="https://enkrypt.example.internal")
Both arguments are optional. Without them, Enkrypt reads the environment:
Argument |
Environment variable |
Default |
|---|---|---|
|
|
none: required |
|
|
|
enkrypt = Enkrypt() # reads ENKRYPTAI_API_KEY and ENKRYPTAI_BASE_URL
A missing key fails when Enkrypt() is created, with a ValueError, rather than at the first request.
The other arguments control rate limits, connections, enforcement and where redacted personal data is kept. They are covered in Production and Personal data; the full list is in the API reference.
Enkrypt is not a capability#
Enkrypt itself never goes in an agent’s capabilities=. The guards it creates go inside the harness guardrails, which are the capabilities:
from pydantic_ai_harness import InputGuardrail
capabilities = [InputGuardrail(guard=[enkrypt.toxicity()])] # right
capabilities = [enkrypt] # wrong
One object, many guards#
Create one Enkrypt per account and reuse it for every guard in an agent. Guards from the same object share its settings, and share redacted personal data, so that enkrypt.restore can put back what any of them redacted. See Redaction and restoring.