Skip to content
Ask for a Budget
EngineeringFebruary 25, 20263 min readUpdated on November 11, 2026

Sensitive data in RAG: how to prevent leaks in AI chatbots

Where leaks really happen and the controls that solve most of them: classification, permission-aware search, PII redaction, text-free logs and a checklist.

Sensitive data in RAG: how to prevent leaks in AI chatbots
Índice do artigo
faltam 3 min de leitura

The biggest risk of a RAG system is not "getting the answer wrong".
It is giving the right answer to the wrong person.

When you connect an LLM to internal documents (policies, contracts, spreadsheets, tickets, wikis), you gain productivity, and you also open the door to a classic risk: improper disclosure of information.

The good news is that you can reduce this risk a lot with engineering and process. This article summarizes a set of practices that work well in real products, without relying on prompt "magic".

Professional analyzing data on a laptop and tablet in a corporate setting

What you will find here

  • Where leaks happen in RAG solutions (even when it "looks secure")
  • The controls that deliver the most: permissions, minimization and redaction
  • How to treat embeddings and vectors as sensitive data
  • Good logging and observability practices without exposing PII
  • A final security checklist

If you do not yet have a clear picture of the RAG pipeline, read this first: RAG in practice.

Where leaks really happen

In general, leaks do not happen because "the model is evil". They happen because the system:

  1. indexes more data than it should
  2. retrieves data without respecting permissions
  3. logs or stores sensitive data in unexpected places
  4. lets the LLM "do" too much (excessive agency)

OWASP's list for LLM and generative AI applications (2025 edition) gives these risks names: sensitive information disclosure (LLM02:2025), vector and embedding weaknesses (LLM08:2025) and excessive agency (LLM06:2025). The first two matter most when RAG is involved, and the third when the assistant also calls tools.

Diagram: protections in a RAG pipeline with sensitive data


Simple principles that prevent most problems

1) Minimize: not everything needs to become an embedding

The first question is always: "does this need to be in the RAG?"

Content that normally should not go into the chatbot's knowledge base:

  • secrets (tokens, keys, passwords, certificates)
  • unnecessary personal data (CPF, the Brazilian taxpayer ID, phone number, full address)
  • information that requires strong authorization (salaries, performance reviews, medical data)
  • anything you would not want to see in a screenshot

If the information is needed for a specific task, prefer exposing it through tools (tool calling) with access control and auditing, instead of "throwing it into the embedding". (See: Tool calling: secure integration.)

2) Classify data before indexing

Even a simple classification helps:

  • Public
  • Internal
  • Confidential
  • Restricted

Use this classification as metadata and apply policies:

  • "Restricted does not go into RAG"
  • "Confidential goes in with ACL and redaction"
  • "Internal goes in, but only for authenticated users"

3) ACL at retrieval: authorization happens in the search, not in the prompt

A common mistake is trying to handle permissions in the prompt ("do not show X").
That is fragile.

The most robust pattern:

  • each indexed chunk carries permission metadata (by group, role, user, tenant)
  • at search time, you filter by ACL before building the context

That way, the LLM never sees what it should not see.

Example (conceptual) of a metadata filter:

{
  "query": "What is the refund policy?",
  "filters": {
    "language": "en",
    "tenant_id": "company-123",
    "roles_any": ["finance", "manager"]
  }
}

4) Redaction: remove PII from the content and from the logs

Redaction (or masking) means removing/anonymizing sensitive parts.

You can apply it in two places:

  1. Before indexing: remove PII from the text that will become a chunk/embedding
  2. Before answering/logging: if some sensitive data got into the context, keep it from appearing in the answer or in the logs

Practical tip: start with simple rules (regex + lists) and evolve to DLP tools when it makes sense.

5) Treat embeddings as sensitive

Embeddings do not "store text" in a trivial way, but they represent the content and can leak context (besides allowing content to be retrieved through search). In environments with compliance requirements, it is reasonable to consider:

  • encryption at rest
  • strong access control on the vector database
  • segregation by tenant/environment
  • retention and disposal policy

6) Logs and observability without leaks

You need telemetry to improve the RAG, but without capturing PII:

Good practices:

  • log IDs (document_id, chunk_id) instead of full text
  • redact/mask before saving the prompt/context
  • separate "debug logs" (short retention, restricted access) from "operational logs"
  • never log tokens/secrets

Extra attention: prompt injection through documents (indirect injection)

In RAG, the retrieved content becomes "input" for the LLM.
If a document contains malicious (or simply wrong) instructions, the model can be induced to:

  • ignore policies
  • reveal content it should not
  • call tools incorrectly

This is indirect injection, and it is one of the reasons prompt injection holds first place on the OWASP list (LLM01:2025).

Recommended follow-up: Prompt injection: how to protect chatbots and agents.


Final checklist (copy and paste)

  • RAG sources defined and reviewed (what goes in / what stays out)
  • Data classification applied before indexing
  • Chunks with metadata (tenant, roles, confidentiality level)
  • Search with ACL filtering (the LLM does not see content outside its permission)
  • PII redaction before indexing and before answering/logging
  • Vector database with restricted access + encryption at rest
  • Logs: prefer IDs, mask content, set short retention for debugging
  • An "I don't know" policy when there is no permitted evidence
  • Regression tests covering sensitive questions and permission cases

Further reading

If your internal knowledge base holds sensitive data, connect this checklist to an AI chatbot and enterprise RAG project or to a generative AI governance and security initiative.

Also read

Prompt injection: protecting chatbots and agents without breaking the productMFA/2FA for clients: a secure account that never blocks your app releaseReplit → React: a safe flow from front-end prototype to production
Previous post
RAG in practice: what decides whether the assistant is right or makes things up
Next post
Prompt injection: protecting chatbots and agents without breaking the product
Newsletter

One email a month, no noise

What we learn shipping custom software and applied AI.

Related articles

Prompt injection: protecting chatbots and agents without breaking the product3 min · Engineering
MFA/2FA for clients: a secure account that never blocks your app release6 min · Engineering
Replit → React: a safe flow from front-end prototype to production3 min · Engineering
LLMOps: metrics, logs and evaluation to run AI in production3 min · Engineering
AI coding productivity: from the peak to the complexity cliff7 min · Engineering

Accelerate your business with X-Apps

Ask for a Budget
X-Apps is an IT provider partner and advised by
Gartner
Receive our e-mails
News on software and applied AI.
Follow X-Apps