Chains and ordering#
Lists on the prompt and the answer#
InputGuardrail and OutputGuardrail take a list of guards and run it from first to last:
a guard that allows the value passes it to the next;
a guard that rewrites the value, as redaction does, passes the rewritten value to the next;
the first guard to refuse ends the chain; the guards after it do not run.
So order matters in two ways: which check refuses first, and what the later checks see.
from pydantic_ai_harness import InputGuardrail
from pydantic_ai_harness.guardrails.detectors import redact_secrets
InputGuardrail(
guard=[
redact_secrets, # local: rewrite keys with a known shape
enkrypt.secrets(), # Enkrypt sees the rewritten prompt
enkrypt.injection_attack(),
enkrypt.pii(entities=["person"]),
no_advice, # sees placeholders, not names
]
)
Put cheap local guards before Enkrypt guards, and put guards that should see redacted text after the redaction.
On the answer, enkrypt.restore goes last, so no check sees the restored personal data:
OutputGuardrail(guard=[enkrypt.toxicity(), no_advice, enkrypt.restore])
Several checks on tools#
ToolGuardrail takes one guard per stage: one guard for arguments and one result_guard for results. For several tool checks, add several ToolGuardrails. The harness runs them in a fixed order:
argument guards run in the order the
ToolGuardrails are listed;result guards run in reverse: the
ToolGuardraillisted last checks a result first.
As with lists, a rewrite passes on and the first refusal ends the chain.
tools = ["lookup_account", "fetch_page"]
capabilities = [
ToolGuardrail(
guard=enkrypt.restore, # arguments: tools get real values
result_guard=user_pii, # results, second: redact personal data
tools=tools,
),
ToolGuardrail(
result_guard=enkrypt.injection_attack(), # results, first: refuse attacks
tools=tools,
),
]
Here a tool result is checked for injection before it is redacted.
A ToolGuardrail without tools= applies to every tool.
Within one response#
Order decides between guards. Within one guard’s response, as when a saved guardrail flags several detectors, the strictest action wins instead; see Actions.
Inline guards or a saved guardrail#
Each guard in a list makes its own call to Enkrypt, one after another. A guardrail saved in Enkrypt runs all its detectors in one call. Use a saved guardrail when you want:
fewer calls per run, which matters under Enkrypt’s rate limits;
a set of checks managed in Enkrypt’s dashboard rather than in code.
Use inline guards when you want different actions or orders per edge, or local guards and redaction between Enkrypt checks. The two mix: a saved guardrail is one more guard in a list. See guardrail.