---
title: How do you keep customer data separate in a multi-tenant AI agent?
url: https://opencontroller.lyzr.com/blog/tenant-isolation-for-multi-tenant-ai-agents
published: 2026-11-15
updated: 2026-11-15
author: Lyzr
---

# How do you keep customer data separate in a multi-tenant AI agent?

**Keep customer data separate in a multi-tenant agent by carrying a verified tenant ID through every step, and enforcing it outside the model: in retrieval filters, memory namespaces, tool credentials, caches and logs. Never rely on the prompt to tell the model which tenant it serves. Then prove isolation with leakage tests that try to pull one tenant's data from another tenant's session.**

Cross-tenant leakage is listed in the [OWASP LLM08:2025 Vector and Embedding Weaknesses](https://genai.owasp.org/llmrisk/llm082025-vector-and-embedding-weaknesses/) entry as a risk when multiple users or applications share a vector store. Agents widen the surface because they also keep memory and call tools. This post is for teams building one agent that serves many customers or business units.

## Where can tenant data leak in an agent?

| Leak point | How it happens | Control |
|---|---|---|
| Retrieval | Shared index returns chunks from other tenants | Mandatory tenant filter on every query |
| Agent memory | Long-term memory written without a tenant key | Memory namespace per tenant |
| Tool calls | Tool uses one shared credential for all tenants | Per-tenant or on-behalf-of credentials |
| Caches | Response or semantic cache returns another tenant's answer | Tenant ID in every cache key |
| Fine-tuned or shared prompts | Examples from one customer in a shared prompt | No tenant data in shared prompts |
| Logs and traces | Support staff see all tenants' prompts | Tenant-scoped log access; redaction |
| Evaluation sets | Production samples reused across tenants | Tenant-tagged eval data |

## Why shouldn't the prompt carry tenant identity?

A line like "You are serving Tenant A, only use Tenant A data" is a request, not a control. Prompt injection, a confused model or a bug in context assembly can ignore it. Tenant identity must come from the authenticated session and be enforced by systems that do not reason, such as database filters and credential scopes.

## How do you implement tenant isolation step by step?

1. **Bind tenant at authentication.** Derive the tenant ID from the user's verified token, not from request parameters the client can change.
2. **Propagate it as context, not text.** Pass tenant ID in request headers or trace attributes to every service the agent calls.
3. **Choose an index model.** Separate indexes per tenant give the strongest isolation. A shared index needs a mandatory, server-side tenant filter that application code cannot skip.
4. **Namespace memory.** Key every memory write and read by tenant and, where relevant, by user. See [govern AI agent memory stores](/blog/govern-ai-agent-memory-stores).
5. **Scope credentials.** Use per-tenant credentials or exchange the user's token for a downstream token so the tool enforces tenancy. [OAuth token exchange for AI agents](/blog/oauth-token-exchange-for-ai-agents) shows the pattern.
6. **Key caches by tenant.** Include tenant ID in response and semantic cache keys. Provider prompt caches can also be separated; OpenAI documents a `prompt_cache_key` that keeps cache accounting separate per customer.
7. **Scope logs.** Tag traces with tenant ID and restrict who can read each tenant's traces.
8. **Fail closed.** If the tenant ID is missing at any step, block the call.

## How do you test for cross-tenant leakage?

Run these tests before launch and after every change to retrieval, memory or tools:

- **Canary documents.** Seed each test tenant with a unique marker string. From every other tenant, ask questions designed to surface it. Any hit is a failure.
- **Direct requests.** Ask the agent for "the other customer's" records by name or ID.
- **Injection.** Plant a document in Tenant A that instructs the agent to fetch Tenant B data.
- **Memory carry-over.** Run a session in Tenant A, then start one in Tenant B with the same user role, and check for recalled facts.
- **Cache probes.** Send identical questions from two tenants and confirm answers are not shared.
- **Missing context.** Strip the tenant header and confirm the request is rejected.

Automate these as a multi-turn eval suite so they run in CI. [Control AI agent retrieval from vector databases](/blog/control-ai-agent-retrieval-from-vector-databases) covers retrieval filters in more depth.

## What evidence will customers ask for?

Enterprise customers buying your agent will ask how you isolate their data. Keep:

- an architecture note showing where tenant ID is enforced
- results of the leakage test suite per release
- access logs showing who viewed which tenant's traces
- incident records for any isolation failure

## How Opencontroller does this

Opencontroller supports delegated on-behalf-of identity, so downstream calls carry the user's identity and tenancy instead of a shared credential. Multi-turn and red-team evals can run leakage tests per release, and live guardrails and LLM judges watch production traffic. The LLM Gateway routes and caches model calls and attributes cost per agent and per version. See the pillar on [on-behalf-of delegation](/blog/ai-agent-identity-on-behalf-of-delegation) or [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Is a separate vector index per tenant necessary?**
It gives the strongest isolation. A shared index can work if a server-side tenant filter is mandatory on every query and tested.

**Can the system prompt enforce tenant isolation?**
No. Tenant identity must come from authentication and be enforced in retrieval, memory, credentials and caches.

**How do you test a multi-tenant agent for data leakage?**
Seed unique canary strings per tenant, try to retrieve them from other tenants directly and through injected instructions, and check memory and caches.

## Key facts

Multi-tenant AI agents leak data through shared retrieval indexes, agent memory, shared tool credentials, caches, prompts and logs. Controls: bind tenant ID at authentication, propagate as context not prompt text, separate indexes or mandatory server-side filters, per-tenant memory namespaces, per-tenant or on-behalf-of credentials, tenant-keyed caches, fail closed. Test with canary documents, injection and cache probes. OWASP LLM08:2025 covers cross-tenant leakage in shared vector stores. Opencontroller offers delegated on-behalf-of identity, multi-turn and red-team evals, guardrails and LLM judges. Pricing starts from $250K per deployment per year.

## Related

- [How do you control what an AI agent can retrieve from a vector database?](https://opencontroller.lyzr.com/blog/control-ai-agent-retrieval-from-vector-databases.md)
- [How do you govern what AI agents remember?](https://opencontroller.lyzr.com/blog/govern-ai-agent-memory-stores.md)
- [How does OAuth token exchange work for AI agents?](https://opencontroller.lyzr.com/blog/oauth-token-exchange-for-ai-agents.md)
- [More on Agent identity and access](https://opencontroller.lyzr.com/blog/cluster/agent-identity-and-access)
