Redaction and restoring#
Placeholders#
With on_violation="redact" (the default for pii()), each value Enkrypt finds is replaced with a placeholder naming its entity type and a number:
I'm John Smith, writing from 10.1.2.3.
I'm <<PERSON:1>>, writing from <<IP_ADDRESS:1>>.
Enkrypt finds the values; the replacing happens in this package, so the placeholders are under its control:
One value, one placeholder. A value keeps its placeholder for the whole conversation, however many guards and calls find it. Numbers count per entity type: the second person is
<<PERSON:2>>.One numbering per
Enkrypt. Every guard from the sameEnkryptobject shares it, including a saved guardrail that redacts. A second redactingpii()on tool results continues the numbering rather than starting again.Hidden from checks. Placeholders are removed from every text a guard sends to Enkrypt, so no check mistakes
<<PERSON:1>>for personal data.
Restoring#
enkrypt.restore is a guard that replaces placeholders with the values they stand for. It is not a check: it never refuses. Put it:
on tool arguments,
ToolGuardrail(guard=enkrypt.restore), so a tool called with<<PERSON:1>>receivesJohn Smith; strings anywhere in the arguments are restored;last on the answer,
OutputGuardrail(guard=[..., enkrypt.restore]), so the user sees real values and no check after it sees them.
agent = Agent(
FunctionModel(model),
capabilities=[
InputGuardrail(guard=[p]), # redact the prompt
ToolGuardrail(
guard=enkrypt.restore, result_guard=p
), # real names in, redacted out
OutputGuardrail(guard=[enkrypt.restore]), # the user sees real names
],
)
user types: Hi, I'm John Smith. Why is my account locked?
model saw: Hi, I'm <<PERSON:1>>. Why is my account locked?
model calls: lookup_account(name="<<PERSON:1>>")
tool got: John Smith
tool returns: Account of John Smith: locked by the admin, Jane Doe.
model saw: Account of <<PERSON:1>>: locked by the admin, <<PERSON:2>>.
model answers: <<PERSON:1>>, your account was locked by <<PERSON:2>>.
user sees: John Smith, your account was locked by Jane Doe.
Leave enkrypt.restore out where values should stay redacted, as for other people’s data in tool results.
What can be redacted#
Redaction rewrites text: a prompt, a text answer, or a text tool result (including a ToolReturn’s return value). It fails closed:
a structured answer or a tool result that is not text cannot be rewritten, so a finding there blocks;
tool arguments are not rewritten, so
redacton tool arguments blocks;if Enkrypt reports a value that is not found verbatim in the text, the guard blocks rather than letting it through.
The block message is Enkrypt AI found PII that could not be redacted.
Not with secrets#
pii() refuses the "secrets" entity type: a redacted secret could be restored and passed to a tool or the user. Use secrets(), which raises.