protect
guard.protect checks a payload for attacks and personal data in one request and rewrites it once.
The result
Each entry in
cloak.entities has a type, category, start, end, the strategy used, and the token for a tokenized value. Offsets index into the text you submitted. The values themselves are not in the result.
The rewrite
Attack redactions and Cloak replacements are applied in one pass. A value that sits inside an attack span is replaced by the attack’s replacement and is never tokenized or stored. Images, provider parameters, message roles, and any other non-text content pass through untouched. A value that straddles two messages is replaced in each message separately.Restoring
result.restore(value) accepts a string or any JSON-shaped value, such as a provider response, and returns the same shape with its tokens replaced.
Only tokens the vault actually holds are ever replaced. A token-shaped string in a response proves nothing, because a token is a keyed digest and cannot be written without the key.
Restoring by context, without a
protect result in hand:
Wrap
wrap protects the payload before your callback sees it. With restore: true it also restores whatever the callback returns.
safe.cloak (the report) and, when you gave a context, safe.restore.
Decorate
restore is set.
A stream is not restored. Its chunks reach you before the call ends. Restore the text you assemble with
fw.guard.cloak.restore.What is recorded
With capture on, the request body is recorded as it was forwarded, with tokens in place of values, and the response is recorded before it was restored. A request that was refused is recorded only if its personal data can be redacted out of it, and its body is dropped otherwise. Telemetry carries counts only. See Telemetry and capture.Cloak on its own
To protect personal data without the attack check:fw.guard.cloak.scan(input) finds entities without changing anything. It returns ran, and a payload the detector never answered for has ran: false. Read that as “not checked”, never as “nothing found”.
