org.llm4s.agent.guardrails.builtin.PIIMasker
See thePIIMasker companion object
class PIIMasker(val piiTypes: Seq[PIIType]) extends InputGuardrail, OutputGuardrail
Automatically masks Personally Identifiable Information (PII) in text.
Unlike PIIDetector (which can block or warn), PIIMasker always transforms the text by replacing detected PII with redaction placeholders.
This guardrail never blocks - it always allows processing to continue with sanitized text. Use this when you want to:
- Sanitize user input before sending to LLM
- Redact sensitive information from LLM outputs
- Preserve privacy while allowing queries to proceed
Masked text uses placeholders like [REDACTED_EMAIL], [REDACTED_SSN], etc.
Example usage:
// Mask all default PII types
val masker = PIIMasker()
// Mask only specific types
val emailMasker = PIIMasker(Seq(PIIType.Email, PIIType.Phone))
// Use with agent
agent.run(
query = userInput,
tools = tools,
inputGuardrails = Seq(PIIMasker())
)
Value parameters
- piiTypes
-
The types of PII to mask (default: SSN, CreditCard, Email, Phone)
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
trait OutputGuardrailtrait InputGuardrailtrait Guardrail[String]class Objecttrait Matchableclass Any
Members list
In this article