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
| Parameter | Type |
|---|---|
options | PIIRedactionOptions |
Returns
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' },
}),
],
},
});