Multi-Tenant AI Agents: Data Isolation Across Retrieval and Tools
Design multi-tenant AI agents with trusted tenant context, scoped retrieval and tools, isolated caches, current permissions, and adversarial isolation tests.
Abhishek Raj · · 8 min read
Prepared with AI research assistance. Sources are linked throughout; worked examples are illustrative unless stated otherwise. Editorial approach.
Multi-tenant AI agents need isolation at every point where information or authority changes hands. A tenant identifier in the system prompt is useful context, but it cannot constrain a database connection, select a safe search namespace, or authorize a tool call. Those decisions need enforceable application boundaries.
This guide develops a hypothetical shared procurement assistant for two fictional customers, Cedar and Harbor. The proposed contracts, failure scenarios, and validation steps are illustrative engineering designs, not a deployed reference implementation.
Model the isolation boundary before choosing storage
Start with an inventory of tenant-owned objects: source documents, vector records, conversation history, checkpoints, tool credentials, generated files, caches, and audit events. Include intermediate artifacts. A correct final answer does not excuse sending another customer's contract to a model during retrieval.
For each object, record who owns it, which principals may access it, and which service enforces that decision. Treat derived artifacts as protected data too: a summary of a confidential document can disclose its contents without containing its original identifier.
A useful proposed boundary separates three identities. The authenticated principal identifies the person or service. The selected tenant identifies the organization in which that principal is acting. The workload identity identifies the executing agent service. None substitutes for the others. A service account's ability to query an index does not establish the user's right to read each indexed document.
Establish tenant context outside the model
OWASP's multi-tenant guidance recommends establishing tenant context early, verifying it against authenticated identity and membership, and propagating that verified context without allowing downstream replacement by untrusted input. It also emphasizes that opaque identifiers do not themselves provide authorization. OWASP Multi-Tenant Application Security.
For the procurement assistant, the application resolves the user's Cedar membership before creating a run. The resulting execution envelope might contain:
{
"run_id": "run_example_29",
"tenant_ref": "cedar",
"principal_ref": "user_example_8",
"authorization_revision": 31,
"allowed_capabilities": ["contracts.read", "orders.draft"],
"expires_at": "2026-11-10T16:00:00Z"
}
This is an illustrative envelope, not a token format. Protect its integrity and validate its issuer, intended recipient, and expiry using the chosen identity infrastructure. Do not place a reusable credential in the model context. Tool arguments may select an order, but the executor supplies the tenant binding independently.
An execution-context object also needs lifecycle discipline. Create it for one request or run rather than mutating a global variable shared by concurrent tasks. When execution ends, release its request-local resources. Reused workers must not inherit Cedar's scope while processing Harbor's next job.
Apply authorization before evidence reaches the model
Retrieval has two related questions: which tenant owns the document, and whether this principal may read it within that tenant. A tenant-level partition addresses the first question; it does not automatically answer the second. A Cedar employee may still lack permission to read Cedar's executive compensation documents.
Azure AI Search documents both application-supplied security filters and identity-aware document-permission mechanisms. Its overview distinguishes simple string-based trimming from native permission checks, and marks several native capabilities as preview. The enforcement approach and API support must be checked for the deployed configuration. Azure AI Search document-level access control.
In the proposed design, lexical retrieval, vector retrieval, reranking, document fetches, and citation expansion all operate on authorized evidence. Filtering only the final answer is too late. An unauthorized candidate might already have entered a reranker request, trace payload, or model prompt.
Return provenance with accepted chunks: tenant, source version, document identity, and the authorization decision's relevant revision. Before expanding a citation into a full document, check access again. A citation identifier is a reference, not a transferable read capability.
Choose isolation mechanisms with explicit limits
Pinecone's multitenancy guide describes using one namespace per tenant and targeting reads and writes to the intended namespace. That provides a concrete retrieval partition, but the application still has to choose the correct namespace from trusted execution context. A broad service credential does not become tenant-scoped merely because the request contains a namespace parameter. Pinecone multitenancy.
For the hypothetical assistant, a storage choice can be evaluated with this decision table:
| Mechanism | Proposed use | Boundary that still needs enforcement |
|---|---|---|
| Tenant namespace | Partition search records | Correct trusted namespace selection and document ACLs |
| Shared relational tables | Store ordinary workflow records | Row ownership and constrained execution roles |
| Separate database or project | Support stronger administrative separation | Credential, backup, and operator access isolation |
| Dedicated worker pool | Separate sensitive execution | Routing, secret delivery, and artifact access |
These are design options rather than universal security rankings. A separate database with a shared unrestricted administrator path may provide less useful separation than its diagram suggests. Decide which adversary and operational mistake each mechanism addresses, then test that boundary directly.
PostgreSQL row-level security offers policy-based control over visible and modifiable rows. Its documentation also identifies important exceptions: superusers and roles with BYPASSRLS bypass the system, and table owners normally do too unless forced under row security. A policy therefore needs appropriate request roles, not just a migration that creates it. PostgreSQL row security policies.
For an illustrative pooled-connection design, tenant context would be set within the same transaction that performs the query. A later request must not reuse session state from an earlier tenant. Verify behavior under the actual connection pool and role configuration rather than assuming a unit test with one connection proves isolation.
Carry scope through tools, queues, and artifacts
A tool executor should resolve an order using both its identifier and the verified tenant scope. Looking up an unrestricted order by ID and checking ownership only after serialization creates an unnecessary exposure path. Apply the same rule to updates and deletes, including background reconciliation jobs.
Delegation needs a narrower capability contract. If a specialist only extracts contract dates, give it access to the specific authorized input artifact rather than the parent's entire document store. The relationship between workload identity and delegated authority is developed further in least privilege for agent tools.
Queued work introduces time. A job authorized this morning might execute after the user leaves the organization. In this proposed system, the message carries a protected reference to the run and its authority snapshot; the consumer resolves current execution permission before reading sensitive data or committing an action. Define explicitly whether a workflow may continue under a separate business authorization when its initiating user loses access.
Generated files need the same treatment. Bind a review packet to its tenant and authorized recipients. A downloadable URL should not become accessible merely because somebody guessed the filename or copied an internal artifact identifier.
Walk through a cross-tenant cache failure
Suppose Cedar and Harbor both ask, “What is the termination notice period?” Cedar's answer is cached using only the normalized question. Harbor's later request matches the key and receives Cedar's contract summary without any new retrieval call. Every search query may have been correctly scoped; the cache bypassed that protection.
A proposed result-cache identity would account for tenant, relevant authorization scope, evidence versions, query, and pipeline version. Even that does not settle revocation. A permission change may require invalidating an existing entry or checking its evidence access before serving it.
The same reasoning applies to semantic caches: similar meaning does not establish identical access rights. A cache candidate can be considered only within a permitted scope, then validated against its source dependencies. LLM caching for agent systems examines the broader correctness tradeoffs.
Now add a paused run. Cedar's contract access is revoked while the assistant waits for review. On resumption, the workflow checks the evidence references and current authorization state before publishing the packet. If access has changed, it invalidates the affected draft and records an incomplete outcome rather than silently reusing protected text.
Test isolation with negative paths and interleavings
Create two synthetic tenants with deliberately overlapping document titles, order numbers, and user-visible names. Distinct secret markers inside their fixtures make unintended disclosure detectable. Keep these fixtures separate from real customer information.
Exercise boundaries directly:
- Replace an authorized object identifier with another tenant's identifier while retaining the original authenticated context.
- Omit tenant context, provide conflicting scope fields, and replay an expired execution envelope.
- Interleave Cedar and Harbor requests on the same worker and database connection pool.
- Revoke access between retrieval and document expansion, and between approval and action execution.
- Retry an old queue message after tenant offboarding or a permission revision.
- Seed a cache with one tenant's answer, then issue an equivalent query from the other tenant.
Assert intermediate behavior as well as final output. Inspect which records reached the reranker, which artifacts were fetched, and which tool requests were attempted. A refused answer after unauthorized retrieval is still a failed isolation test.
Keep administrative and recovery paths in scope. Export tools, backup restoration, debugging dashboards, and support impersonation can bypass the normal request pipeline. Record the intended exceptional authority and test its approval, expiry, and audit behavior separately from ordinary agent execution.
Frequently asked questions
Is a separate agent instance sufficient tenant isolation?
No. Separate conversations can still share unrestricted tools, caches, storage clients, or credentials. Identify the actual enforcement points and verify that each instance receives only its permitted scope.
Should the tenant identifier be hidden from the model?
It may be useful descriptive context, but secrecy is not the security boundary. The model must not be able to select or replace the executor's authoritative tenant binding through generated arguments.
Can tenant isolation rely on a vector metadata filter?
Only if trusted application code consistently constructs and enforces the filter across every relevant path. Also consider document-level permissions, fetch-by-ID operations, caches, asynchronous jobs, and administrative access. A filter protects the operations that actually apply it.
Source reference list
Related reading
- Least Privilege for AI Agents: Scoped Credentials and Capability Design
Design least-privilege AI agents with scoped credentials, resource-bound grants, controlled delegation, explicit elevation, and credential lifecycle checks.
- LLM Caching for Agent Systems: Exact, Semantic, and Prompt Caches
Design LLM caching with exact keys, semantic reuse boundaries, stable prompt prefixes, dependency invalidation, and measurable cost and correctness tradeoffs.
- RAG Freshness: Updates, Deletion, and Index Consistency
Keep RAG answers current with versioned ingestion, deletion watermarks, permission checks, and cache invalidation that survives delayed jobs and replay.