Skip to content

createPIIRedactionGuardrail

Create a guardrail that redacts common PII before it is spoken.

function createPIIRedactionGuardrail(options?): Guardrail;

Defined in: src/guardrails/redaction.ts:269

Create a guardrail that redacts common PII before it is spoken.

Parameters

ParameterType
optionsPIIRedactionOptions

Returns

Guardrail

Remarks

Covers email addresses, phone numbers, US social security numbers, credit card numbers (Luhn-validated), and IPv4 addresses. Runs at both stages by default; the patterns are local and allocation-light, so leaving it on the 'chunk' stage costs nothing measurable.

With the default 'sentence' segmentation, patterns are not split across streaming boundaries — an email address arriving in three chunks is still matched as one string.

Redaction changes only what is spoken. The guardrail.applied event still carries the pre-redaction text in its original field, and the raw model output stays on llm.chunk and llm.complete — so the PII survives in those payloads for auditing. Do not log them verbatim, and do not attach a catch-all listener that forwards every event to a log sink.

Example

const agent = new CompositeVoice({
  providers: [...],
  guardrails: {
    filters: [
      createPIIRedactionGuardrail({
        types: ['email', 'phone', 'creditCard'],
        replacements: { creditCard: 'the card on file' },
      }),
    ],
  },
});

© 2026 CompositeVoice. All rights reserved.

Font size
Contrast
Motion
Transparency