Build a RAG for 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
- Python
- TypeScript
from custodian_labs import Custodian, GuardianLayer
# 1. de-identify the file
masked = GuardianLayer().deidentify_file("policy.pdf", masking_type="transform")
with open("deid_policy.pdf", "wb") as f:
f.write(masked.content)
# 2. attach it to an agent
app = Custodian(
model="gpt-4o",
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 { writeFile } from "node:fs/promises";
import { Custodian, GuardianLayer } from "@custodianlabs/sdk";
const masked = await new GuardianLayer().deidentifyFile("policy.pdf", { maskingType: "transform" });
await writeFile("deid_policy.pdf", masked.content);
const app = await new Custodian({
model: "gpt-4o",
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);
Use transform to keep the text readable for retrieval; redact if the values
shouldn't survive at all. Keep originals in secure storage, not the app path.
See also
Data Sources & RAG (Python) · (TypeScript) · Use PII masking with LLMs