Skip to main content

Use PII Masking with LLMs

Two ways to keep PII out of the model.

Option A: let the agent do it​

Set privacy_enabled / privacyEnabled on a Custodian Agent. The platform masks every message before the LLM and restores the values in the reply — nothing extra in your code.

Custodian(model="gpt-4o", system_prompt="…", privacy_enabled=True).deploy()

Option B: mask it yourself, then call any LLM​

De-identify from your backend, send the safe text onward.

user message → your backend → Guardian Layer → de-identified message → any LLM
from custodian_labs import GuardianLayer

safe = GuardianLayer().deidentify_text_outputs(
"My name is Jane Smith, jane@example.com. Summarize my case.",
masking_type="transform",
).outputs[0].text

llm.chat(messages=[{"role": "user", "content": safe}])

transform when the model needs a readable sentence; redact when it doesn't need the values at all.

Rules​

Call Guardian Layer from the backend. Log the de-identified text, not the raw input. Test with fictional data first.

See also​

De-identify Text · Transform · Use API keys securely