RAG on sensitive data
Ground an agent in your files without feeding raw PII into the index.
sensitive file → Guardian Layer → de-identified file → agent data source → RAG chat
De-identify the file
- Python
- TypeScript
from custodian_labs import GuardianLayer
masked = GuardianLayer().deidentify_file("policy.pdf", masking_type="transform")
with open("deid_policy.pdf", "wb") as f:
f.write(masked.content)
import { writeFile } from "node:fs/promises";
import { GuardianLayer } from "@custodianlabs/sdk";
const masked = await new GuardianLayer().deidentifyFile("policy.pdf", { maskingType: "transform" });
await writeFile("deid_policy.pdf", masked.content);
Use transform to keep the text readable for search. Use redact or placeholder if
the values shouldn't survive at all.
Attach it to an agent and chat
- Python
- TypeScript
from custodian_labs import Custodian
app = Custodian(
model="gpt-6-luna",
system_prompt="Answer from the uploaded file. If it's not in the file, say so.",
).add_data_source_file("./deid_policy.pdf").deploy()
reply = app.chat("What does the policy say about account access?")
print(reply.response, reply.retrieved_contexts)
import { Custodian } from "@custodianlabs/sdk";
const app = await new Custodian({
model: "gpt-6-luna",
systemPrompt: "Answer from the uploaded file. If it's not in the file, say so.",
}).addDataSourceFile("./deid_policy.pdf").deploy();
const reply = await app.chat("What does the policy say about account access?");
console.log(reply?.response, reply?.retrievedContexts);
Keep the original safe
Store the original file in secure storage, away from the app. Only the de-identified copy should be attached to the agent.
See also
Data sources and RAG · Privacy masking · Mask PII before any LLM