pii#
enkrypt.pii(*, entities, on_violation="redact", on_error="block")
Finds personal data of the entity types you list, and by default replaces it with placeholders.
Allowed actions |
|
Default action |
|
Enkrypt detector |
|
Entity types#
entities lists Enkrypt’s entity types to look for, for example:
enkrypt.pii(entities=["pii", "person", "ip_address"])
person finds names; pii is a catch-all for other personal identifiers; there are others such as ip_address, email, phone and url. What each catches, and how to choose, is in Choosing entity types.
"secrets" is refused with a ValueError: use secrets().
Redact, then restore#
With redact, each value found becomes a placeholder such as <<PERSON:1>>, and the value continues with placeholders. enkrypt.restore puts the real values back where you place it:
user_pii = enkrypt.pii(entities=["pii", "person"])
capabilities = [
InputGuardrail(guard=[user_pii]), # redact the prompt
ToolGuardrail(guard=enkrypt.restore, result_guard=user_pii), # real values in, redacted out
OutputGuardrail(guard=[enkrypt.restore]), # the user sees real values
]
A value keeps its placeholder throughout the conversation, across every guard from the same Enkrypt. The details are in Redaction and restoring.
Other actions#
pii() is not only for redaction. Each action fits a different purpose:
Purpose |
Edge |
Action |
|---|---|---|
keep the user’s own data from the model and logs |
prompt, tool results |
|
keep other people’s data from the model and the user |
tool results |
|
stop a tool call carrying data out |
tool arguments |
|
catch personal data in the answer |
answer |
|
See What pii() is for.
One action per entity type#
A mapping sets an action per entity type, with "pii" covering those not listed:
enkrypt.pii(
entities=["person", "ip_address", "url"],
on_violation={"person": "redact", "url": "block"}, # ip_address: the default, redact
)
If one value contains entity types with different actions, the strictest wins; here, a URL blocks the whole value.