Fortress Shield: redact PII and secrets (free, on this Worker)
pii_redact_textWHAT: Fortress Shield (agent I/O PII protection). Return sanitized copies of texts with every local PII/secret finding replaced: placeholder [EMAIL_k7q2m9xp4a] (random id per value), mask, or hash. For placeholders the originals come back only inside meta.sealed_map, an AES-256-GCM encrypted string that this Worker opens in pii_restore_text. The originals stay out of the model context. WHEN: Right before sending user data to an LLM/third party. Keep meta.sealed_map if you need to restore originals in the LLM answer later. WHEN NOT: For a findings report only use pii_scan_text. For unlabelled names (NER) or fetching PDFs and remote documents use pii_guard_documents (paid). http(s) URLs in text you already have are redacted here for free. COST: Free; no token. RETURNS: One "redacted_document" row per text with output_text, typed_placeholders_escaped, context_lowered, context_suppressed, below_threshold, context_report, field_paths (JSON input) and, with failClosed, blocked / block_reasons (output_text null); meta.audit, meta.secret_guidance, meta.compliance, meta.would_fail_closed; meta.sealed_map (placeholder style, "fqs2.…"; null plus a SEAL_KEY_NOT_CONFIGURED note when this deployment has no seal key) and meta.seal {algorithm, entries, expires_at, restore_bound, max_restores}. Errors: INPUT_TOO_LARGE, INVALID_PATTERN, INVALID_ARGUMENT, SEALED_MAP_INVALID, SEALED_MAP_EXPIRED, SEAL_KEY_NOT_CONFIGURED, RESTORE_KEY_REQUIRED / RESTORE_KEY_MISMATCH (priorSealedMap bound to another restore key). BEHAVIOR: Placeholder ids are random on every call unless you pass priorSealedMap; "hash" is random per call unless a hash key is set. The sealed_map is bound to the restore key header of this request (X-FQ-PII-Restore-Key, set by the operator in the client connection); without one, pii_restore_text reports counts only. 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; texts are not forwarded. Milliseconds. PARAMETERS: texts: one element per document, 500,000 chars in total; the same value gets the same placeholder in every document of one call, and case/format variants share it (JANE@ACME.COM and jane@acme.com; +1 415 555 0100 and (415) 555-0100). Placeholder-shaped text already in the input (a user typing "[EMAIL_1]") is itself replaced by a [TYPED_PLACEHOLDER_] placeholder and restored verbatim, so it can never pull another value. priorSealedMap: the meta.sealed_map of an earlier call; values seen before keep their placeholder, new ones are added, and the returned sealed_map covers both (use it across turns and when paging). redactionStyle: "placeholder" is the only reversible style; "mask" keeps a few characters for human review; "hash" with hashKey (16-256 chars, your own key) gives the same output for the same value in every call (HMAC-SHA256, joinable), without hashKey the salt is random per call. sealTtlHours: how long the sealed_map opens (1-720, default 24). returnPlaceholderMap: deprecated and refused unless the request carries the restore key header; use sealed_map. maxRestores: restore cap for this sealed_map (default 3). entityTypes / allowList / allowDomains / allowPatterns / customDetectors / contextScoring / contextMode / entropyScan / defaultPhoneRegion: identical semantics to pii_scan_text. limit/offset page whole documents (one item per text, default 50 = all). EXAMPLE: {"texts":["Call +1 415 555 0100 or mail jane@acme.com"]} -> output_text "Call [PHONE_4hq8m2xk9c] or mail [EMAIL_t7c3pz2wqa]", meta.sealed_map "fqs2.…".
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_redact_text"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Optional page size: items to return, integer 1-50 (default 50). Example: 50 | |
| 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 | |
| hashKey | No | Optional, hash style only, discouraged. Your own 16-256 char key for deterministic HMAC-SHA256 hashes. As an argument it sits in the model context (HASHKEY_ARG_IN_CONTEXT note); prefer the X-FQ-PII-Hash-Key request header set in the MCP client connection, which wins when both are present. Never returned. | |
| tenantId | No | Optional, 1-128 chars [A-Za-z0-9._:-]. Binds the sealed_map to a tenant (a hash is stored inside the encrypted map); pii_restore_text then opens it only for the same tenant (TENANT_MISMATCH otherwise). The X-FQ-PII-Tenant connection header wins over this argument. | |
| allowList | No | Optional, default [] (nothing exempt). 0-500 exact values (<= 500 chars each) that are never flagged; whole-value, case-insensitive match, not substring. Example: ["support@yourco.com","192.0.2.1"] | |
| chunkSafe | No | Optional boolean, default false. true treats texts as consecutive chunks of ONE stream (e.g. streamed LLM output): detection runs over the joined stream, so a value split across a chunk boundary ("jane@ac" + "me.com") is still found; its placeholder goes in the chunk where it starts and its tail is removed from the next chunk. meta.chunk_safe {chunks, boundary_findings}. | |
| leakCheck | No | Optional boolean, default false. true re-scans every output_text after redaction for residual PII/secrets (anything not produced by this redaction) -> meta.leak_check {passed, residual_types, documents_with_residuals}; with failClosed a leaking document is withheld (LEAK_RESIDUAL). | |
| failClosed | No | Optional boolean, default false. true withholds a document (output_text null, blocked true, block_reasons) when a candidate was left in its text: a match dropped by contextMode "drop", or below minConfidence. Without it, meta.would_fail_closed counts such documents. | |
| contextMode | No | Optional, "lower" | "drop", default "lower". What happens to a match that only a negative context word argues against: "lower" still flags/redacts it with confidence "low" and context "negative:<reason>" (counted in context_lowered); "drop" (strict precision) leaves it untouched (counted in context_suppressed). | lower |
| detectNames | No | Optional. Omit to keep labelled person names (Dear, Patient, sign-off). false turns those labelled hits off. true keeps them; full person-name NER runs only in the Apify Actor (pii_guard_documents). | |
| entityTypes | No | Optional, default omitted = every free-tool detector (pii_list_detectors rows with local:true). 0-40 detector type names (<= 40 chars, case-insensitive), e.g. ["EMAIL","CREDIT_CARD","AWS_ACCESS_KEY"]. Valid values: the "type" field of those rows; unknown names match nothing (no error) | |
| entropyScan | No | Optional boolean, default false. true also flags unlabeled random-looking tokens of 20-200 chars as HIGH_ENTROPY_STRING (catches unknown key formats; may flag hashes/UUIDs). Example: true | |
| maxRestores | No | Optional integer 1-100, default 3. How many pii_restore_text calls may return original values for this sealed_map; later calls report counts only (RESTORE_LIMIT_REACHED). | |
| allowDomains | No | Optional, default []. 0-200 email domains whose addresses are never flagged; subdomains included. Example: ["yourco.com"] exempts support@yourco.com and a@eu.yourco.com | |
| sealTtlHours | No | Optional integer 1-720, default 24. Hours until meta.sealed_map stops opening. | |
| allowPatterns | No | Optional, default []. 0-50 JavaScript regular expressions (<= 200 chars; no backreferences or nested quantifiers -> INVALID_PATTERN); a finding whose value matches any of them is not flagged. Example: ["^192\.0\.2\.","@example\.(com|org)$"] | |
| minConfidence | No | Optional, "low" | "medium" | "high", default "low" (everything). Findings below this confidence are left in the text and counted per document as below_threshold (types only); combine with failClosed on pii_redact_text to withhold documents that contain them. | low |
| returnReceipt | No | Optional boolean, default false. true adds meta.receipt, an Ed25519 compact JWS (fqrc2) over operation, map id, counts, per-type counts, detector version, tenant tag, an HMAC commitment of the input texts (not an unsalted sha256), a sha256 of the redacted output when it changed, and expiry (no original values); check it with pii_verify_receipt on /pii-guard/mcp or offline with pii_list_detectors receipt_verification. Default expiry is 30 days (receiptTtlDays). | |
| surrogateSeed | No | Optional, 1-200 chars, redactionStyle "surrogate" only. WARNING: this argument is visible to the model and to transcripts. Prefer the X-FQ-PII-Surrogate-Seed request header (same 512-char cap as the hash key, never echoed). The header wins when both are set. Omit both for a per-call seed. There is no per-tenant isolation. Surrogates cannot be restored. | |
| contextScoring | No | Optional boolean, default true. true uses the words around a match: labels like "SSN:", "phone:", "my cell", "call me" raise confidence, and a label earlier on the same line wins over a negative word. "version"/"v" before an IPv4 or phone-shaped number and "invoice"/"order"/"ticket"/"ref" before a bare phone-shaped number lower it (see contextMode). Phones with +country code, parentheses or two separators, and IPv4 with a port, CIDR suffix or 3-digit octet are never lowered. false = format-only scoring. | |
| priorSealedMap | No | Optional. meta.sealed_map from an earlier pii_redact_text call (placeholder style only). Keeps the same placeholder for values seen before. Example: "fqs1.…" | |
| receiptTtlDays | No | Optional integer 1-3650, default 30. Receipt validity in days from now. | |
| redactionStyle | No | Optional, one of "placeholder" | "mask" | "hash" | "label" | "surrogate", default "placeholder". "placeholder" = [EMAIL_k7q2m9xp4a] (reversible with meta.sealed_map); "mask" = j***@a***.com, **** **** **** 1111; "hash" = [EMAIL:3f2a9c0d1b7e] (salted sha256 prefix; with hashKey an HMAC that stays the same across calls); "label" = type only, [EMAIL]; "surrogate" = a synthetic value of the same shape, prefixed with ⟦SG⟧, stable for the same text and surrogateSeed, and not reversible (other types [TYPE_SURROGATE_id]). Example: "mask" | placeholder |
| customDetectors | No | Optional, default []. 0-20 of your own detectors (regex pattern and/or terms dictionary) for account IDs, ticket formats or member numbers; findings use your type name with category "custom" and are redacted and restored like built-in types. | |
| detectAddresses | No | Optional boolean, default false. true also runs the street-address patterns on this Worker (STREET_ADDRESS: house number + street, PO Box, units, trailing city/state/ZIP or postcode; US/UK/FR/DE-style forms). Pattern-based, medium confidence; place-name NER (LOCATION) and person names stay Actor-only. Example: true | |
| restoreAudience | No | Optional, "any" | "user", default "any". "user" marks the sealed_map user-only: pii_restore_text returns originals only on requests with the X-FQ-PII-User-Present header (set by an MCP Apps / client UI action, not by the model); otherwise USER_ONLY_RESTORE, counts only. | any |
| destinationPolicy | No | Optional preset for where the text goes: "llm_public" | "llm_private" | "internal" | "logs" | "analytics". It sets minConfidence, contextMode, entropyScan, excludeEntityTypes and (pii_redact_text) failClosed / leakCheck; meta.destination_policy shows what was applied. Omit to use the individual parameters. | |
| defaultPhoneRegion | No | Optional, default "US". ISO 3166-1 alpha-2 code (2 letters, pattern ^[A-Za-z]{2}$, case-insensitive) used only for phone numbers written without a +country prefix. Examples: "US", "DE", "GB" | US |
| excludeEntityTypes | No | Optional, default []. 0-40 detector type names to switch off (case-insensitive), e.g. ["IP_ADDRESS","POSTAL_CODE"]; applied after entityTypes. customDetectors always run. | |
| returnPlaceholderMap | No | Optional boolean, default false. Deprecated: true (placeholder style only) asks for meta.placeholder_map {"[EMAIL_…]":"jane@acme.com"} with the ORIGINAL values in clear text; honoured only when the request carries the operator restore key header or sealing is unavailable (otherwise a PLAINTEXT_MAP_REFUSED note). Prefer meta.sealed_map. |
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 |