AI security and compliance
How do you enforce tenant isolation beyond database rows?
Row level security answers "whose row is this?" Real products also need "which parts of this row may you see?"
Short answer
Tenant isolation beyond database rows means enforcing boundaries per field and per role, not only per tenant ID. The same customer record can be fully visible to one party and partly visible to another, so tenant isolation has to cover columns, caches, files, payments, background jobs and every API. Any later feature, including an AI agent for reporting or support, must respect those same boundaries, because it will read whatever your platform lets it read.
On this page
01Rows are only the first boundary
Most multi-tenant products start with a tenant column and a filter on every query. PostgreSQL row security policies make this stronger by enforcing the filter in the database itself, with a default deny when no policy matches. That is a good foundation. It is not the whole answer.
Real B2B platforms often have more than one kind of party looking at the same record. A wholesale company and its dealers, a franchisor and its locations, a platform and its resellers. In these products the question is rarely "may this tenant see this row?" It is "may this role, in this tenant, see this field of this row, for this purpose?"
AWS makes a related point in its SaaS architecture guidance: authentication and authorization are not isolation. A user can be signed in and authorized for a feature and still reach another tenant's data if isolation is not enforced separately, using tenant context on every access.
02Map the visibility rules before you write code
The most useful artifact is a visibility map: for each important entity, which roles see which fields. Draw it before building, and keep it in the repository.

| Data | Owning party | Central company admin | Dealer admin | Dealer staff | End customer |
|---|---|---|---|---|---|
| Customer profile | Dealer | Shipping details only | Full | Full | Own profile |
| Product catalog | Central company | Full | Visibility, pricing and descriptions only | Read | Published items |
| Order | Dealer, then central for fulfillment | Order and shipping | Full | Full | Own orders |
| Payment | Dealer's own account | No access to funds | Settings and refunds | Per role | Own payments |
| Design files | Customer and dealer | For production | Full | Full | Own files |
A map like this exposes decisions early: who owns the customer, who can change price, who can refund. It also becomes the test plan.
03Enforce tenant isolation at every layer
Rows, fields and roles need enforcement in more places than the main database. The OWASP Multi Tenant Security Cheat Sheet is a good checklist. In practice we cover these layers:

- 01
Request context.
Set the tenant on the server for every request, and treat any tenant ID sent by the client as a selector to verify, not a fact.
- 02
Database.
Use row security for tenant scoping, and column level grants or separate views for field level rules.
- 03
API responses.
Shape responses per role, so a field the role may not see is never serialized, not just hidden in the UI.
- 04
Caches and search indexes.
Include the tenant in every cache key and index filter.
- 05
Files.
Partition storage by tenant and authorize before issuing signed URLs.
- 06
Payments.
Where each tenant uses its own payment account, keep the platform out of the money flow and store no card data.
- 07
Background jobs.
Carry verified tenant context into queued messages and check it again in the worker.
- 08
Logs and exports.
Include tenant context in audit events and restrict who can read them.
Test cross-tenant denial explicitly. For each role, write tests that try to read another tenant's data and another role's fields, and run them on every release.
04Plan for AI before you add it
AI features are a new path to the same data. A reporting agent, a support assistant or a search tool will read through whatever interface you give it. If that interface was written for internal admins, the agent will see what admins see.
Before adding AI to a multi-tenant product:
- Give the agent its own access path that applies the same tenant, role and field rules as the user it acts for.
- Scope retrieval to the current tenant before anything reaches the model.
- Keep embeddings and indexes per tenant, or filter them by tenant on every query.
- Log every agent read and write with tenant and user context.
- Add the agent to your cross-tenant denial tests.
We go deeper on this pattern in how to add AI agents to existing SaaS without rebuilding.
05Common isolation mistakes
When we review multi-tenant products, these are the gaps we find most often:
- Field rules enforced only in the UI, while the API returns the full record.
- Admin endpoints that skip tenant filters because they were written for internal staff.
- Reports and exports built on direct database queries that bypass the application rules.
- Shared cache keys for data that differs by tenant.
- Background jobs that run with a superuser connection, which row security does not constrain.
- Impersonation or support tools without an audit trail.
Each one is easy to miss because the product looks correct from the screens. The fix is to test from the outside: call the API as each role in each tenant and check exactly which fields come back. Repeat those tests whenever a new endpoint, report or integration is added, and treat a failed test as a release blocker.
It also helps to name an owner for the visibility map. When the business adds a new party, such as a reseller or a partner, the map is updated first, and the code follows.
06What we see in production
For a premium custom print company with a wholesale dealer network, we replaced the dealer side of a 15 year old legacy system with a multi-tenant platform where each dealer runs a branded storefront with its own pricing, promotions and payment account, while every order flows back to the company for production and shipping.
Isolation had to work per field and per role, not just per tenant. The same customer is fully visible to the dealer and only partly visible to the central company: central admins see shipping details, not the full profile. The catalog stays central, and dealers control only visibility, pricing and descriptions. Dealers collect payment in their own accounts, so the platform holds no funds and stores no card data, which keeps it out of card data scope.
We added tenant filtering across backend and frontend, role based access for super admin, dealer admin, dealer staff and customer, and recommended snapshotting variant data into each order so later price changes never alter past orders. The platform runs on the client's own AWS account.
There was no AI in the delivered scope, but the scope document asked for an architecture ready for future agent based features such as intelligent reporting and AI customer support. Any such agent will have to respect the same field and role boundaries, which is far easier because they already exist in one place.
Frequently asked questions
Is PostgreSQL row level security enough for tenant isolation?
It is a good foundation, not the whole answer. Row security enforces the tenant filter in the database itself, with a default deny when no policy matches. It does not cover field rules, caches, files, payments or background jobs, and jobs that run with a superuser connection are not constrained by it.
How do we test tenant isolation?
Test from the outside. For each role, write tests that try to read another tenant's data and another role's fields. Call the API as each role in each tenant and check exactly which fields come back. Run those tests on every release, and treat a failed test as a release blocker.
What changes when we add an AI agent to a multi-tenant product?
The agent is a new path to the same data, and it will read through whatever interface you give it. Give it its own access path that applies the same tenant, role and field rules as the user it acts for. Scope retrieval to the current tenant, and add the agent to your cross-tenant denial tests.
How Datics helps
Datics specializes in brownfield AI: bringing production AI into the product you already operate, without forcing a rebuild.
Related work
Case studies from our projects on the same subject.
Premium print products company
Retail & E-commerce · Multi-tenant dealer storefront platform
Branded dealer storefronts where each print dealer is paid into its own account
Dealers could not sell under their own brand on a 15 year old system; we built storefronts with direct payment and a route to production.
Transcripts U.S.
Government, Legal & Defense · Legal transcript marketplace
Court reporting agencies publish transcript metadata without the file ever leaving their browser
Agencies once uploaded full transcripts to the marketplace; now title page details are read in their own browser, and they confirm what is published.
Regulated investment platform
Financial Services · Private investment marketplace
Pitch decks become drafted deals, and issuers approve each field before publishing
Issuers retyped decks and financials into long deal forms. Now AI suggests each field, and the issuer applies, edits or rejects it.
More on AI security and compliance
AI security and compliance
AI security for SaaS: protect data and pass security reviews
A practical map of AI security for established SaaS: threats, data governance, permissions, audit trails and how to answer enterprise security reviews.
AI security and compliance
How do you stop AI data leakage through search metadata?
Stop AI data leakage in search by treating metadata as sensitive: classify records, automate high stakes rules, keep people on unclear cases, and audit.
AI security and compliance
LLM security: why treat model output as untrusted input?
A core LLM security rule: treat every model response like input from an unknown user. Parse it, validate it against business rules, then let it through.
AI security and compliance
Which AI disclaimers does a product need?
An AI disclaimer works when it is designed into the feature: say it is AI, that it can be wrong, what happens to data, and where its numbers come from.
AI security and compliance
What enterprise AI security questions do buyers ask?
Enterprise AI security reviews ask where data and models run, who reaches production, what the AI may do alone and how it is logged. Here is how to prepare.
AI security and compliance
What does HIPAA AI compliance mean for software vendors?
HIPAA AI for software vendors: what the product company owns, what the engineering team builds, and how to keep patient identifiers away from models.
Your customers already expect AI from your product.
Let us make it real without rebuilding what already works.
