/** * PII detection guardrail for sensitive text content. * * This module implements a guardrail for detecting Personally Identifiable * Information (PII) in text using regex patterns. It defines the config * schema for entity selection, output/result structures, and the async guardrail * check_fn for runtime enforcement. * * The guardrail supports two modes of operation: * - **Masking mode** (block=false, default): Automatically masks PII with placeholder tokens without blocking * - **Blocking mode** (block=true): Triggers tripwire when PII is detected, blocking the request * - With encoded detection enabled, exceeding its decoded-size limit triggers a tripwire * in either mode because the encoded content could not be fully inspected. * * **IMPORTANT: PII masking is only supported in the pre-flight stage.** * - Use `block=false` (masking mode) in pre-flight to automatically mask PII from user input * - Use `block=true` (blocking mode) in output stage to prevent PII exposure in LLM responses * - Masking in output stage is not supported and will not work as expected * * When used in pre-flight stage with masking mode, the masked text is automatically * passed to the LLM instead of the original text containing PII. * * Classes: * PIIEntity: Enum of supported PII entity types across global regions. * PIIConfig: Configuration model specifying what entities to detect and behavior mode. * PiiDetectionResult: Internal container for mapping entity types to findings. * * Functions: * pii: Async guardrail check_fn for PII detection. * * Configuration Parameters: * `entities` (list[PIIEntity]): List of PII entity types to detect. * `block` (boolean): If true, triggers tripwire when PII is detected (blocking behavior). * If false, only masks PII without blocking (masking behavior, default). * **Note: Masking only works in pre-flight stage. Use block=true for output stage.** * * Supported entities include: * * - "US_SSN": US Social Security Numbers * - "PHONE_NUMBER": Phone numbers in various formats * - "EMAIL_ADDRESS": Email addresses * - "CREDIT_CARD": Credit card numbers * - "US_BANK_ACCOUNT": US bank account numbers * - And many more. * * Example: * ```typescript * // Masking mode (default) - USE ONLY IN PRE-FLIGHT STAGE * const maskingConfig = { entities: [PIIEntity.US_SSN, PIIEntity.EMAIL_ADDRESS], block: false }; * const result1 = await pii(null, "Contact me at john@example.com, SSN: 111-22-3333", maskingConfig); * result1.tripwireTriggered // false * result1.info.checked_text // "Contact me at , SSN: " * * // Blocking mode - USE IN OUTPUT STAGE TO PREVENT PII EXPOSURE * const blockingConfig = { entities: [PIIEntity.US_SSN, PIIEntity.EMAIL_ADDRESS], block: true }; * const result2 = await pii(null, "Contact me at john@example.com, SSN: 111-22-3333", blockingConfig); * result2.tripwireTriggered // true * ``` */ import { z } from 'zod'; import type { CheckFn } from '../types'; /** * Supported PII entity types for detection. * * Includes global and region-specific types (US, UK, Spain, Italy, etc.). * These map to regex patterns for detection. */ export declare enum PIIEntity { CREDIT_CARD = "CREDIT_CARD", CRYPTO = "CRYPTO", DATE_TIME = "DATE_TIME", EMAIL_ADDRESS = "EMAIL_ADDRESS", IBAN_CODE = "IBAN_CODE", IP_ADDRESS = "IP_ADDRESS", NRP = "NRP", LOCATION = "LOCATION", PERSON = "PERSON", PHONE_NUMBER = "PHONE_NUMBER", MEDICAL_LICENSE = "MEDICAL_LICENSE", URL = "URL", CVV = "CVV", BIC_SWIFT = "BIC_SWIFT", US_BANK_NUMBER = "US_BANK_NUMBER", US_DRIVER_LICENSE = "US_DRIVER_LICENSE", US_ITIN = "US_ITIN", US_PASSPORT = "US_PASSPORT", US_SSN = "US_SSN", UK_NHS = "UK_NHS", UK_NINO = "UK_NINO", ES_NIF = "ES_NIF", ES_NIE = "ES_NIE", IT_FISCAL_CODE = "IT_FISCAL_CODE", IT_DRIVER_LICENSE = "IT_DRIVER_LICENSE", IT_VAT_CODE = "IT_VAT_CODE", IT_PASSPORT = "IT_PASSPORT", IT_IDENTITY_CARD = "IT_IDENTITY_CARD", PL_PESEL = "PL_PESEL", SG_NRIC_FIN = "SG_NRIC_FIN", SG_UEN = "SG_UEN", AU_ABN = "AU_ABN", AU_ACN = "AU_ACN", AU_TFN = "AU_TFN", AU_MEDICARE = "AU_MEDICARE", IN_PAN = "IN_PAN", IN_AADHAAR = "IN_AADHAAR", IN_VEHICLE_REGISTRATION = "IN_VEHICLE_REGISTRATION", IN_VOTER = "IN_VOTER", IN_PASSPORT = "IN_PASSPORT", FI_PERSONAL_IDENTITY_CODE = "FI_PERSONAL_IDENTITY_CODE", KR_RRN = "KR_RRN" } export declare const PIIConfig: z.ZodObject<{ entities: z.ZodDefault>>; block: z.ZodDefault; detect_encoded_pii: z.ZodDefault; }, z.core.$strip>; export type PIIConfig = z.infer; export declare const PIIConfigRequired: z.ZodPipe>; block: z.ZodBoolean; detect_encoded_pii: z.ZodBoolean; }, z.core.$strip>, z.ZodTransform<{ entities: PIIEntity[]; block: boolean; detect_encoded_pii: boolean; }, { entities: PIIEntity[]; block: boolean; detect_encoded_pii: boolean; }>>; /** * Clear deprecation warning cache. FOR TESTING ONLY. * @internal */ export declare function _clearDeprecationWarnings(): void; /** * Async guardrail check_fn for PII entity detection in text. * * Analyzes text for any configured PII entity types and reports results. If * any entity is detected, the tripwire is triggered unless scrubbing is enabled. * * @param ctx Guardrail runtime context (unused) * @param data The input text to scan * @param config Guardrail configuration for PII detection * @returns Indicates if any PII was found, and the findings * @throws Error if input text is empty or null */ export declare const pii: CheckFn, string, PIIConfig>; //# sourceMappingURL=pii.d.ts.map