secrets#

enkrypt.secrets(*, on_violation="raise", on_error="block")

Flags credentials: API keys, passwords, tokens.

Allowed actions

raise, block, audit

Default action

raise

Enkrypt detector

pii, entity type secrets

Why it raises, and never retries#

A secret in a prompt or an answer is an incident for your application to handle, not something to quietly route around, so the default is raise. Catch EnkryptInputBlocked (or the harness’s InputBlocked) to handle it.

There is no retry: retrying would send the secret back to the model to rewrite.

Secrets are also never redacted reversibly: enkrypt.pii() refuses the "secrets" entity type, because a redacted secret could be restored and passed on.

Layer it after local redaction#

pydantic-ai-harness has a local detector, redact_secrets, that rewrites credentials with a known shape (GitHub tokens, AWS keys and similar) without calling anything. Put it first, and enkrypt.secrets() after it to catch what the patterns miss:

agent = Agent(
    FunctionModel(model),
    capabilities=[InputGuardrail(guard=[redact_secrets, enkrypt.secrets()])],
)

# A GitHub token has a known shape: redact_secrets rewrites it locally.
result = agent.run_sync(
    "Why does my token ghp_abcdefghijklmnopqrstuvwxyz0123456789 fail?"
)
print(f"model saw: {result.all_messages()[0].parts[-1].content}")
print(f"output: {result.output}\n")

# This one has no known shape: only Enkrypt catches it, and the run raises
# EnkryptInputBlocked (a subclass of the harness's InputBlocked).
agent.run_sync("My config has VERY_SECRET_TOO = 'f6CGV4aMM9zedoh3OUNbSakBymo7yplB'")
model saw: Why does my token [redacted:github_token] fail?
output: (the model answered the prompt)
...
pydantic_ai_enkrypt.core.EnkryptInputBlocked: Enkrypt AI blocked the prompt (secrets).

The GitHub token has a known shape, so redact_secrets rewrote it locally and the run went on. The second secret has no known shape, so only Enkrypt caught it. Full script: Secrets.

Reference#

pydantic_ai_enkrypt.Enkrypt.secrets()