Fortress Shield: restore placeholders with original values (free, on this Worker)
pii_restore_textWHAT: Fortress Shield (agent I/O PII protection). Put the original values back into texts (typically an LLM answer) that contain placeholders such as [EMAIL_k7q2m9xp4a], by opening meta.sealed_map from pii_redact_text on this Worker (or a legacy clear-text placeholder map). Numeric JSON sentinels are restored only in the redacted document they came from, matched by those bytes in any order. A different document is not rewritten. Slots for a document you did not pass are reported as JSON_NUMBER_DOC_MISMATCH. schema_range_preserved is false. WHEN: After an LLM or third party answered a prompt you sanitized with pii_redact_text (redactionStyle "placeholder"), right before showing the answer to the user. WHEN NOT: To redact (pii_redact_text) or find PII (pii_scan_text). Masked and hashed values cannot be restored; only placeholder style is reversible. COST: Free; no token. RETURNS: One "restored_document" row per text with restored, output_text, replacements, fuzzy_restored, unknown_placeholders and near_miss_placeholders. meta.restore_gate is RESTORE_KEY_OK, or RESTORE_KEY_REQUIRED / RESTORE_KEY_MISMATCH / RESTORE_LIMIT_REACHED, in which case nothing is substituted: restored is false, replacements 0, output_text is the input unchanged and sealed_replacements_withheld only counts them. restored is true only when at least one placeholder was actually replaced. Every row carries map_source ("sealed" | "plaintext"), verified (true only for an authenticated sealed map) and exact (no fuzzy, unknown or near-miss placeholders); meta.verification and meta.audit (counts) summarise them. A clear-text placeholderMap alone is refused on deployments with a seal key (meta.restore_gate SEALED_MAP_REQUIRED, nothing substituted, plaintext_replacements_refused counts). Further gate codes (counts only): TENANT_MISMATCH (map bound to another tenantId), USER_ONLY_RESTORE (restoreAudience "user" without the X-FQ-PII-User-Present header), APPS_RESTORE_REQUIRED (operator requires a user-facing MCP Apps / UI restore). meta.seal_ttl {expires_at, remaining_seconds}; meta.sealed_map_extended with extendTtlHours; meta.receipt with returnReceipt. Errors: INPUT_TOO_LARGE, MAP_MISSING, SEALED_MAP_INVALID (altered or from another deployment), SEALED_MAP_EXPIRED, SEAL_KEY_NOT_CONFIGURED. BEHAVIOR: Original values come back only when the request carries the same restore key header (X-FQ-PII-Restore-Key, configured by the operator in the MCP client connection, never a tool argument) that was present when the map was sealed, and at most maxRestores times per map; otherwise counts only. Holding the sealed map alone is not enough. Runs on this Fairquery-hosted Worker (Cloudflare), not on the caller's machine; inputs leave the client. This Worker's code is designed not to store inputs, results, or an Apify token. No further network call; the map is not forwarded. Milliseconds. Max 50 texts, 200,000 chars each, 500,000 total; map up to 10,000 entries. PARAMETERS: sealedMap: pass meta.sealed_map unchanged (preferred). placeholderMap: legacy clear-text map, honoured only when this deployment has no seal key (or the operator restore policy is "open"), and then marked verified false; if both are given, sealedMap is used alone and placeholderMap is ignored (never merged; PLAINTEXT_MAP_IGNORED note). Every key is replaced wherever it occurs exactly (longest first, one pass, so a restored value is never replaced again). fuzzyRestore (default true): a placeholder the LLM rewrote but whose random id is intact ("EMAIL_k7q2m9xp4a" without brackets, lower case, a space instead of _) is restored too and listed in fuzzy_restored. unknown_placeholders lists exact [TYPE_N] shapes the map does not contain; near_miss_placeholders lists mangled shapes ("EMAIL_3", "[Email_4]") that matched no key; both stay as they are. When restored is true the output contains the ORIGINAL sensitive values: show it to the user, do not send it back to the LLM. limit/offset page whole documents (default 10 per page). EXAMPLE: {"texts":["I will email [EMAIL_t7c3pz2wqa] today."],"sealedMap":"fqs2.…"} with the restore key header -> output_text "I will email jane@acme.com today.", replacements 1; without it -> restored false, sealed_replacements_withheld 1.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"texts": "<texts>"
},
"name": "pii_restore_text"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Optional page size: items to return, integer 1-50 (default 10). Example: 10 | |
| texts | Yes | Required. 1-50 documents (prompt, chat message, log, file content), each <= 200,000 chars, total <= 500,000 chars. Example: ["Mail jane@acme.com, key AKIAIOSFODNN7EXAMPLE"] | |
| offset | No | Optional zero-based number of items to skip, integer 0-1000000 (default 0); pass nextOffset from the previous response, e.g. 100 | |
| tenantId | No | Optional. Tenant of a tenant-bound sealed_map (pii_redact_text tenantId); a different or missing tenant -> TENANT_MISMATCH, counts only. The X-FQ-PII-Tenant header wins. | |
| sealedMap | No | Optional (this or placeholderMap required). meta.sealed_map from pii_redact_text, unchanged. Example: "fqs2.…" | |
| fuzzyRestore | No | Optional boolean, default true. Also restore rewritten placeholders whose random id is intact; false = exact keys only. | |
| returnReceipt | No | Optional, default false. true adds meta.receipt, an fqrc2 Ed25519 JWS {map id, restores used, documents, replacements} with an HMAC commitment of these input texts (not an unsalted sha256), detector version, and exp. The restored text is not hashed, because it contains the original values. Default expiry is 30 days (receiptTtlDays). No values; verify with pii_verify_receipt. | |
| extendTtlHours | No | Optional integer 1-720. After an allowed restore, also return meta.sealed_map_extended: the same map (same id, restore count, bindings) re-sealed to expire this many hours from now. Refused (EXTEND_TTL_REFUSED note) when the restore gate refused. | |
| placeholderMap | No | Optional, legacy (this or sealedMap required). Object placeholder -> original value, as returned in meta.placeholder_map (deprecated) or placeholder_map by pii_guard_documents; keys 1-200 chars, values <= 10,000 chars, <= 10,000 entries. Example: {"[EMAIL_1]":"jane@acme.com"} | |
| receiptTtlDays | No | Optional integer 1-3650, default 30. Restore-receipt validity in days from now. | |
| restoreAudience | No | Optional, "any" | "user", default "any". "user" = this restore is for the user only: originals come back only with the X-FQ-PII-User-Present header (MCP Apps / client UI), else USER_ONLY_RESTORE, counts only. | any |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| meta | No | Tool-specific context (summary counts, cost notes, ...) | |
| count | Yes | Number of items in this page | |
| items | Yes | Result rows for this page | |
| total | Yes | Total items before paging | |
| offset | Yes | Offset of the first item in this page | |
| hasMore | Yes | True if more items exist after this page | |
| nextOffset | Yes | Offset to pass for the next page, or null |