Skip to Content
Anuma SDKExpoInternalClassesPiiRedactor

PiiRedactor

Defined in: src/lib/pii/redactor.ts:86 

Stateful PII redactor that tracks placeholder assignments across multiple calls. Create one per conversation so “[EMAIL_1]” always refers to the same email address throughout the conversation.

Constructors

Constructor

new PiiRedactor(options: PiiRedactorOptions): PiiRedactor

Defined in: src/lib/pii/redactor.ts:127 

Parameters

ParameterType

options

PiiRedactorOptions

Returns

PiiRedactor

Accessors

size

Get Signature

get size(): number

Defined in: src/lib/pii/redactor.ts:163 

Returns the current number of unique PII values tracked.

Returns

number

Methods

clear()

clear(): void

Defined in: src/lib/pii/redactor.ts:593 

Reset all state. Useful for testing or when starting a fresh conversation.

Returns

void


deAnonymize()

deAnonymize(text: string): string

Defined in: src/lib/pii/redactor.ts:511 

Restore original PII values in text that contains placeholders. Used to de-anonymize LLM responses before displaying to the user.

Exact: matches the literal [EMAIL_1] form only. The storage paths use restoreForStorage instead, which tolerates the mangled echoes the extraction models produce.

Parameters

ParameterType

text

string

Returns

string


dispose()

dispose(): void

Defined in: src/lib/pii/redactor.ts:604 

Clear the mappings and prevent new reversible mappings.

Returns

void


getMappings()

getMappings(): ReadonlyMap<string, string>

Defined in: src/lib/pii/redactor.ts:172 

Returns a snapshot of all placeholder → original value mappings. Useful for debugging or UI display. This is a copy — mutating it (or later redactions) does not affect the returned map and vice versa.

Returns

ReadonlyMap<string, string>


maskText()

maskText(text: string): string

Defined in: src/lib/pii/redactor.ts:272 

Mask PII with unnumbered, NON-reversible tokens ([EMAIL], [SSN], …) without mutating this instance’s state. Use for one-way purposes where the value is never restored — notably embedding inputs: it keeps real PII off the embeddings endpoint while staying deterministic, so the same content always masks identically and search stays consistent across conversations.

Parameters

ParameterType

text

string

Returns

string


maskTextAsync()

maskTextAsync(text: string): Promise<string>

Defined in: src/lib/pii/redactor.ts:408 

Async counterpart to maskText: stateless [CATEGORY] masking over regex + NER matches. With no detector, identical to maskText.

Parameters

ParameterType

text

string

Returns

Promise<string>


redactMessages()

redactMessages(messages: LlmapiMessage[]): MessageRedactionResult

Defined in: src/lib/pii/redactor.ts:456 

Redact PII from an array of LlmapiMessage objects. Returns new message objects — originals are not mutated.

All roles’ text content is redacted, not just user/system: tool results can return PII fetched from external systems, and assistant history is persisted with original (de-anonymized) values, so both must be re-redacted before they go back over the wire. Placeholders the model already emitted are inert here (they don’t match any PII pattern), so re-redaction is safe.

Parameters

ParameterType

messages

LlmapiMessage[]

Returns

MessageRedactionResult


redactMessagesAsync()

redactMessagesAsync(messages: LlmapiMessage[]): Promise<MessageRedactionResult>

Defined in: src/lib/pii/redactor.ts:419 

Async counterpart to redactMessages. Text parts are redacted sequentially so placeholder numbering stays deterministic across the conversation. With no detector, identical to redactMessages.

Parameters

ParameterType

messages

LlmapiMessage[]

Returns

Promise<MessageRedactionResult>


redactText()

redactText(text: string): RedactionResult

Defined in: src/lib/pii/redactor.ts:261 

Scan and redact PII from a single text string, using numbered, reversible placeholders ([EMAIL_1], …) tracked on this instance.

Parameters

ParameterType

text

string

Returns

RedactionResult


redactTextAsync()

redactTextAsync(text: string): Promise<RedactionResult>

Defined in: src/lib/pii/redactor.ts:396 

Async counterpart to redactText: redacts structured PII (regex) AND unstructured PII (the configured NerDetector) with numbered, reversible placeholders. With no detector, identical to redactText.

Parameters

ParameterType

text

string

Returns

Promise<RedactionResult>


restoreForStorage()

restoreForStorage(text: string): object

Defined in: src/lib/pii/redactor.ts:539 

De-anonymize for PERSISTENCE (auto-extraction / consolidation), tolerant of the ways the extraction models mangle a placeholder when echoing it back: dropped brackets (EMAIL_1) and changed case (email_1 / Email_1).

Returns the restored text plus unresolved — true when a placeholder-shaped token for one of this redactor’s categories was NOT assigned during redaction (a model hallucination, or an ambiguous re-cased collision). Callers drop/degrade such facts so an opaque token never reaches the vault.

One left-to-right pass over the ORIGINAL text. Two properties matter:

  • a restored value is never re-scanned — so a real value that happens to contain a <CATEGORY>_<n> substring (e.g. the email ssn_1@example.com, or an API key containing EMAIL_1) is neither corrupted nor false-flagged;
  • unresolved is derived from the lookup miss during this pass, not from a regex re-scan of the output — so it can’t trip over a restored value.

Parameters

ParameterType

text

string

Returns

object

text

text: string

unresolved

unresolved: boolean

Last updated on