liveBook · Manning

PII detection

As explained in Machine Learning Platform Engineering

Personally identifiable information detection is the identification of information that can identify an individual in text or other content.

PII detection identifies sensitive personal information in user inputs before they reach an LLM pipeline, helping prevent token use, privacy leaks, and downstream policy violations. section 13.3.1

A production implementation can:

  • Combine PII detection with other input validators, such as competitor and policy checks. section 13.3.1
  • Target entities such as email addresses, credit-card numbers, and Social Security numbers. section 13.3.1
  • Redact detected values or raise a validation failure, depending on the configured failure action. section 13.3.1

Guardrails AI input guard

Configure a Guardrails AI guard with a PII validator, call it on each user query, and return the validated output only after validation succeeds. A redacted email can then continue through the LLM pipeline without exposing the original value. section 13.3.1

Listing 13.13 Validating input by using Guardrails AI for safety
from guardrails import Guard
from guardrails.hub import CompetitorCheck, GuardrailsPII
from guardrails.types.on_fail import OnFailAction
DATAKRYPT_COMPETITORS = [
   "AWS KMS", "Azure Key Vault", "Google Cloud KMS",
   "HashiCorp Vault", "CyberArk", "Thales", "Venafi"
]
input_guard = Guard().use_many(  #1
   CompetitorCheck(
       DATAKRYPT_COMPETITORS, 
       on_fail=OnFailAction.EXCEPTION  #2
   ),
   GuardrailsPII(
       entities=["EMAIL_ADDRESS", "CREDIT_CARD", "SSN"],
       on_fail=OnFailAction.FIX  #3
   ),
)
def validate_user_input(user_input: str) -> str:
   """Validate and sanitize user input before processing"""
   try:
       result = input_guard.validate(user_input)#4
       return result.validated_output  #5
   except Exception as e:
       logger.warning(f"Input validation failed: {e}")
       raise ValueError(   #6
           "Input contains prohibited content")   #6

Inspect the complete validator configuration and validation function, including entity selection, failure actions, exception handling, and sanitized output. section 13.3.1

How Machine Learning Platform Engineering covers it

How deep it goes
Implements entity selection, validator composition, failure actions, validation calls, and exception handling.
Examples
Uses email addresses, credit-card numbers, and Social Security numbers, including automatic email redaction.
What you can do after
Apply it via Guardrails AI to validate and sanitize user inputs before LLM processing.
How it connects
Connects input validation with safety guardrails, LLM pipelines, output guards, and policy violations.

Also explained in

Compare how 2 books explain PII detection →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning Platform Engineering. The section links point to the parts of the book it draws on.