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
- Python
- TypeScript
- curl
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
import { GuardianLayer } from "@custodianlabs/sdk";
const out = await new GuardianLayer().deidentifyTextOutputs(
"My name is Jane Smith, jane@example.com. Summarize my case.",
{ maskingType: "transform" },
);
const safe = out.outputs[0].text;
curl -X POST "https://privacy.custodianlabs.io/api/v1/deidentify/text/proprietary/outputs" \
-H "X-API-Key: $CUSTODIAN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "My name is Jane Smith, jane@example.com. Summarize my case.", "masking_type": "transform"}'
Use outputs[0].text from the response.
Send the safe text to your LLM
Here with OpenAI. It works the same way with Anthropic, Gemini or a model you host.
- Python
- TypeScript
from openai import OpenAI
reply = OpenAI().chat.completions.create(
model="gpt-6-luna",
messages=[{"role": "user", "content": safe}],
)
print(reply.choices[0].message.content)
import OpenAI from "openai";
const reply = await new OpenAI().chat.completions.create({
model: "gpt-6-luna",
messages: [{ role: "user", content: safe }],
});
console.log(reply.choices[0].message.content);
Pick the right mode
masking_type | The model sees | Use it when |
|---|---|---|
transform | Maria Lopez, maria@example.com | The model needs natural, readable text |
placeholder | [NAME], [EMAIL] | The model only needs to know what kind of value it was |
redact | J***** | 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