PIIDetector

org.llm4s.agent.guardrails.builtin.PIIDetector
See thePIIDetector companion object
class PIIDetector(val piiTypes: Seq[PIIType], val onFail: GuardrailAction) extends InputGuardrail, OutputGuardrail

Detects Personally Identifiable Information (PII) in text.

Uses regex patterns to detect common PII types including:

  • Social Security Numbers (SSN)
  • Credit Card Numbers
  • Email Addresses
  • Phone Numbers
  • IP Addresses
  • Passport Numbers
  • Dates of Birth

Can be configured to:

  • Block: Return error when PII is detected (default)
  • Fix: Automatically mask PII and continue
  • Warn: Log warning and allow processing to continue

Example usage:

// Block on PII detection
val strictDetector = PIIDetector()

// Mask PII automatically
val maskingDetector = PIIDetector(onFail = GuardrailAction.Fix)

// Detect only credit cards and SSNs
val financialDetector = PIIDetector(
 piiTypes = Seq(PIIType.CreditCard, PIIType.SSN)
)

Value parameters

onFail

Action to take when PII is detected (default: Block)

piiTypes

The types of PII to detect (default: SSN, CreditCard, Email, Phone)

Attributes

Companion
object
Graph
Supertypes
trait Guardrail[String]
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

override def transform(input: String): String

Transform applies masking when in Fix mode. For other modes, returns input unchanged.

Transform applies masking when in Fix mode. For other modes, returns input unchanged.

Attributes

Definition Classes
def validate(value: String): Result[String]

Validate a value.

Validate a value.

This is a PURE FUNCTION - no side effects allowed. Same input always produces same output.

Value parameters

value

The value to validate

Attributes

Returns

Right(value) if valid, Left(error) if invalid

Inherited methods

def andThen(other: Guardrail[String]): Guardrail[String]

Compose this guardrail with another sequentially.

Compose this guardrail with another sequentially.

The second guardrail runs only if this one passes.

Value parameters

other

The guardrail to run after this one

Attributes

Returns

A composite guardrail that runs both in sequence

Inherited from:
Guardrail

Concrete fields

override val description: Option[String]

Optional description of what this guardrail validates.

Optional description of what this guardrail validates.

Attributes

val name: String

Name of this guardrail for logging and error messages.

Name of this guardrail for logging and error messages.

Attributes

val piiTypes: Seq[PIIType]