Skip to main content

Mask PII before any LLM

Using your own LLM calls? Run each message through Guardian Layer first, and only send the de-identified version to the model.

user message → your backend → Guardian Layer → de-identified message → any LLM

De-identify the message​

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

Send the safe text to your LLM​

Here with OpenAI. It works the same way with Anthropic, Gemini or a model you host.

from openai import OpenAI

reply = OpenAI().chat.completions.create(
model="gpt-6-luna",
messages=[{"role": "user", "content": safe}],
)
print(reply.choices[0].message.content)

Pick the right mode​

masking_typeThe model seesUse it when
transformMaria Lopez, maria@example.comThe model needs natural, readable text
placeholder[NAME], [EMAIL]The model only needs to know what kind of value it was
redactJ*****The model doesn't need the values at all

Good practice​

  • Call Guardian Layer from your backend, never the browser. The API key is a secret.
  • Log the de-identified text, not the raw input.
  • Test with fictional data before real customer data.
Building with Custodian Agents?

Guardian Layer is already built in. Set privacy_enabled on the agent and every message is sanitized before the model and the reply is rehydrated, with no extra code. See the private agent template.

See also​

De-identify text · Transform · Placeholder · Use API keys securely