Skip to main content

protect

guard.protect checks a payload for attacks and personal data in one request and rewrites it once.
The attack check and detection run side by side on the control plane, so the call is as slow as the slower of the two, not the sum.

The result

When blocked is true the payloads are null. That is deliberate. A payload that reached this point with personal data still in it must not be something you can forward by mistake.
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.
The callback also receives safe.cloak (the report) and, when you gave a context, safe.restore.

Decorate

The request is forwarded protected, provider parameters intact. A non-streamed response is restored when 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”.