AI Search Across Tenants: Permissions Belong in Retrieval, Not the Prompt
A model cannot enforce account boundaries with a polite instruction. Scope documents, caches and tool calls to the authenticated user before private text enters the context.

An assistant is told, "Only answer using this customer's documents." The retrieval service searches every customer's documents, then the model chooses what to mention. The privacy boundary has already failed before the answer is written.
Private retrieval needs authorization at the data boundary. Prompts can describe policy, but they cannot safely replace the application's permission checks.
Identify the permission model
Determine whether documents belong to a tenant, team, project or individual. Some users may have access to several scopes, and document-level restrictions can differ from broad account membership.
Use the authenticated identity to compute permitted scope. Never accept a model-selected tenant ID or a browser-supplied account ID as authority. Validate the current session and enforce access on every read.
A document's embedding is derived from its content. Treat vectors and searchable metadata as potentially sensitive rather than assuming only the original file requires protection.
Filter before returning candidates
Apply the permitted scope in the retrieval operation. Where the engine supports filtered vector search, use its documented filtering semantics and test them. A post-filter after globally retrieving the top few results can both leak metadata and damage relevance by discarding most candidates.
If the engine cannot enforce the required permissions reliably, use a partition or architecture that can. Convenience is not a reason to hand unauthorised snippets to the application and hope nobody logs them.
async function retrieveForUser(query, context) {
const scope = await context.permissions.readableDocumentScope();
return context.search.search({
query,
tenantId: context.tenantId,
allowedDocumentIds: scope.documentIds,
limit: 8,
});
}This conceptual example assumes the search service actually enforces the supplied scope. It is not a complete engine integration. Keep tenant and permission values derived from trusted context, and use the correct mechanism for large permission sets rather than assuming a list filter will scale indefinitely.
Keep the index lifecycle aligned
Document deletion, changed permissions and revoked membership must affect retrieval. An index that updates content hourly but permissions weekly is a privacy bug with a schedule.
Record document revisions and access metadata with index updates. Decide how to block a document while a permission update is pending. For sensitive systems, failing closed is preferable to returning stale access.
Also verify the original document when opening a citation. A search result can be stale even if the index normally updates quickly. The download or viewer endpoint must independently enforce current authorization.
Scope caches carefully
A cache keyed only by question text can return one customer's answer to another customer asking the same question. Include the relevant tenant, permission scope, document revisions and workflow version, or avoid caching private answers until you can define a safe key.
Permissions can change without the query changing. Design invalidation around that event. A cache duration alone may leave a window that violates your access policy.
Do not place private model outputs in shared browser or CDN caches. Review response headers and application query-cache behaviour, including what happens at logout or account switching.
Limit tool access too
Retrieval is only one boundary. A follow-up tool that looks up a referenced invoice must recheck access. A document containing an invoice ID does not grant permission to read it.
Use narrow tools and return only the fields needed for the task. Keep credentials inside the service, not in model context. Sanitize error messages so a failed query does not expose another tenant's identifiers or connection information.
If an assistant can perform actions, require appropriate authorization and exact-operation approval outside the model. The same account boundary applies to writes as to reads.
Test with sentinel documents
Create test tenants with clearly distinguishable synthetic content. Ask tenant A's assistant about a fact that exists only in tenant B. Assert that B's snippet never appears in retrieval results, tool output, logs or the final answer.
Test shared documents, revoked membership, moved documents and stale index entries. Switch accounts in one browser session and verify old cached results disappear. A signed-out test is not enough to verify boundaries between signed-in accounts.
Use synthetic secrets or phrases for these checks, not actual customer data. The test should prove separation without creating another sensitive-data repository.
Observe without collecting everything
Log correlation IDs, retrieval counts, scope decisions and rejection categories. Avoid recording complete prompts and snippets by default. Debugging access failures should not itself spread private documents into a broadly readable telemetry system.
Have an operational response for suspected cross-tenant leakage: disable the affected retrieval path, preserve appropriate evidence and follow your incident process. Do not merely add a stronger sentence to the prompt.
A trustworthy private assistant receives only the evidence the user is allowed to see. That boundary must remain true even when the model is confused, a document is malicious or a cache is stale. Once retrieval enforces it, the prompt can focus on producing a useful answer instead of pretending to be a security system.
Paj Digital Labs
The engineering journal of Paj Digital Solutions — hosting, server infrastructure and web engineering, written by the people who run the servers.
Related reading

Streaming AI Responses: Partial Text Is Not a Completed Result
Streaming improves perceived speed but adds cancellation and partial-output states. Keep tool actions, structured results and saved answers behind a verified completion boundary.

Human Review Queues for AI: Confidence Is Not a Permission Slip
A model’s self-reported confidence does not establish accuracy. Route uncertain and consequential cases using tested rules, show reviewers the evidence and record their decisions without rubber-stamping.

AI Evaluation Sets: Keep the Test Data Out of the Tuning Loop
An evaluation stops being independent when every prompt revision is shaped around its answers. Separate development examples from held-out cases and measure meaningful failure categories.