Skip to content

createPatternRedactionGuardrail

Create a guardrail that rewrites every match of the supplied patterns.

function createPatternRedactionGuardrail(options): Guardrail;

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

Create a guardrail that rewrites every match of the supplied patterns.

Parameters

ParameterType
optionsPatternRedactionOptions

Returns

Guardrail

Remarks

The general-purpose building block behind createPIIRedactionGuardrail. Reach for it when you need to silence identifiers the built-in PII categories do not cover.

Example

createPatternRedactionGuardrail({
  patterns: [
    {
      name: 'account',
      pattern: /\b\d{8,12}\b/g,
      replacement: (match) => `account ending ${match.slice(-4)}`,
    },
  ],
});

© 2026 CompositeVoice. All rights reserved.

Font size
Contrast
Motion
Transparency