Skip to main content

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
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)

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