PIIPatterns

org.llm4s.agent.guardrails.patterns.PIIPatterns
object PIIPatterns

Regex patterns for detecting Personally Identifiable Information (PII).

These patterns are designed for common US formats and can detect:

  • Social Security Numbers (SSN)
  • Credit Card Numbers
  • Email Addresses
  • Phone Numbers
  • IP Addresses
  • Passport Numbers
  • Driver's License Numbers
  • Bank Account Numbers
  • Medical Record Numbers

Note: These patterns favor recall over precision - they may have false positives but minimize false negatives for security-sensitive use cases.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

final case class PIIMatch(piiType: PIIType, value: String, startIndex: Int, endIndex: Int)

Represents a detected PII match with type and location.

Represents a detected PII match with type and location.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object PIIType

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
PIIType.type
sealed trait PIIType

Types of PII that can be detected.

Types of PII that can be detected.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object BankAccount
object CreditCard
object DateOfBirth
object Email
object IPAddress
object Passport
object Phone
object SSN
Show all

Value members

Concrete methods

def containsPII(text: String, types: Seq[PIIType]): Boolean

Check if text contains any PII.

Check if text contains any PII.

Value parameters

text

Text to scan

types

PII types to detect

Attributes

Returns

True if any PII found

def detect(text: String, types: Seq[PIIType]): Seq[PIIMatch]

Detect all PII matches in text using specified patterns.

Detect all PII matches in text using specified patterns.

Value parameters

text

Text to scan

types

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

Attributes

Returns

Sequence of matches with type and location

def maskAll(text: String, types: Seq[PIIType]): String

Mask all PII in text with redaction placeholders.

Mask all PII in text with redaction placeholders.

Value parameters

text

Text to scan and mask

types

PII types to mask

Attributes

Returns

Text with PII replaced by [REDACTED_*] placeholders

def summarize(text: String, types: Seq[PIIType]): Map[String, Int]

Get a summary of PII found in text.

Get a summary of PII found in text.

Value parameters

text

Text to scan

types

PII types to detect

Attributes

Returns

Map of PII type name to count