Skip to main content

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​

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)

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​

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)

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