Errors and enforcement#
When Enkrypt cannot be reached#
If a call to Enkrypt fails (a network error, an error response, an invalid key, or a rate limit that outlasts max_wait), the guard’s on_error decides:
"block"(the default)Refuse the value, as
blockwould, with the messageEnkrypt AI could not check the <edge>.The guard fails closed."allow"Let the value through unchecked. The guard fails open.
enkrypt.toxicity(on_error="allow")
Either way the failure is logged as a warning on the pydantic_ai_enkrypt logger.
on_error is set per guard, so a strict check can fail closed while a low-stakes one fails open. Rate limits are waited out before on_error applies; see Rate limits.
Observing instead of enforcing#
Enkrypt(enforce=False) turns every guard it creates into an observer:
what the guard would have done is logged, and the value is allowed;
this includes Enkrypt failures, whatever
on_errorsays;nothing is blocked, raised, retried or redacted.
enkrypt = Enkrypt(enforce=False)
WARNING pydantic_ai_enkrypt: Enkrypt AI would block the prompt (run 01a1d13a-..., not enforced): Your message was blocked because it was identified as a potential security threat. (injection_attack)
It overrides every guard’s on_violation and on_error, so one argument switches a whole agent between observing and enforcing. Use it to see what guards would do on real traffic before they act; see Observing before enforcing.
Because nothing is redacted, enkrypt.restore has nothing to restore while observing.
audit and logging#
on_violation="audit" is per guard: that guard logs and allows, while the others act. enforce=False is the same for every guard at once.
All logging goes to the pydantic_ai_enkrypt logger at WARNING: audited findings, findings not enforced, and Enkrypt failures. Each message names the edge and the run id.