Actions#

When Enkrypt flags a value, the guard’s on_violation decides what happens:

enkrypt.injection_attack(on_violation="raise")

The actions#

block

Refuse the value. The run carries on where the harness allows it.

raise

Raise an exception, ending the run. Your code decides what happens next.

retry

Send the value back to the model with Enkrypt’s findings, so it tries again.

redact

Replace the personal data Enkrypt found with placeholders, and let the value through. Only for pii() and guardrail(); see Redaction and restoring.

audit

Log what Enkrypt found, and let the value through.

What each action does on each edge#

The harness gives the same action different effects depending on the edge:

Action

Prompt

Answer

Tool arguments

Tool result

block

the model is not called; the run returns the refusal as its output

raises OutputBlocked

the tool does not run; the model sees the refusal as its result

the model sees the refusal instead of the result

raise

raises EnkryptInputBlocked

raises EnkryptOutputBlocked

raises EnkryptToolBlocked

raises EnkryptToolBlocked

retry

not allowed: the harness raises UserError

the model answers again

the model makes the call again

the model makes the call again

redact

the run continues with placeholders

the run continues with placeholders

blocks: arguments cannot be redacted

the run continues with placeholders

audit

logged, allowed

logged, allowed

logged, allowed

logged, allowed

On an answer, block and raise both end the run with an exception: the harness has no way to refuse an answer and continue. The difference is the exception: raise gives you an EnkryptOutputBlocked carrying Enkrypt’s full response.

A retry counts against the agent’s retry budget for that edge: output retries for the answer, tool retries for tools. pydantic-ai allows one of each by default; raise it with Agent(..., retries={"output": 3}). When the budget runs out, the run fails with UnexpectedModelBehavior.

Allowed actions per guard#

Each guard accepts only the actions that make sense for it. A type checker flags the others.

Guard

Allowed

Default

injection_attack, toxicity, code_of_conduct

raise, block, retry, audit

block

secrets

raise, block, audit

raise

pii

redact, raise, block, retry, audit

redact

guardrail

raise, block, retry, redact, audit

per detector: see below

secrets() has no retry, which would send the secret back to the model to rewrite.

One action, or one per thing found#

pii() and guardrail() can find several things in one value: several entity types, or several detectors. Their on_violation takes either one action for all of them, or a mapping:

enkrypt.pii(
    entities=["person", "ip_address", "url"],
    on_violation={"person": "redact", "ip_address": "redact", "url": "block"},
)

enkrypt.guardrail(
    "brokerage-support",
    on_violation={"injection_attack": "raise", "pii": "redact"},
)

The keys are what Enkrypt reports:

  • detector names: injection_attack, toxicity, policy_violation, pii, and the others a saved guardrail runs;

  • for personal data, entity types: person, ip_address, secrets, url, email, and so on.

A personal data finding is looked up by its entity type first, then under "pii", so "pii" covers every entity type not listed on its own. Anything not in the mapping gets the guard’s default.

For guardrail(), a mapping is merged over DEFAULT_ACTIONS, which raises on secrets and blocks everything else. {"injection_attack": "raise"} changes only that detector.

When several things fire at once#

If one response flags several things with different actions, the strictest wins:

raise, then block, retry, redact, audit.

So a saved guardrail with on_violation={"pii": "redact"} that finds a person and a secret raises, because secrets raise by default, rather than redacting the person.

This applies within one guard’s response. Across the guards in a list, the order decides instead; see Chains and ordering.

Messages#

A refusal, a retry and an exception all carry a message built from Enkrypt’s response:

  • Enkrypt’s own block message, when it sends one, followed by what fired and Enkrypt’s explanation: Your message does not comply with our usage policies. Please revise and try again. (policy_violation: Directly requests personalized investment advice.)

  • Otherwise a message naming the edge and what fired: Enkrypt AI blocked the tool arguments (person).

For personal data, what fired is the entity type (person, secrets); for everything else, the detector. A retry adds Try again in a way that complies.

Exceptions#

raise uses this package’s exceptions. Each subclasses the harness exception for its edge, so code that catches the harness exceptions catches these too, and each carries Enkrypt’s full response:

Exception

Subclass of

Raised on

EnkryptInputBlocked

InputBlocked

the prompt

EnkryptOutputBlocked

OutputBlocked

the answer

EnkryptToolBlocked

ToolBlocked

tool arguments and results; also has .tool_name

from pydantic_ai_enkrypt import EnkryptInputBlocked

try:
    result = agent.run_sync(prompt)
except EnkryptInputBlocked as e:
    print(e)              # the message
    print(e.response)     # Enkrypt's full JSON response