Best Way to Stop an AI Agent From Leaking Customer Data: Supabase and Postgres
A read-only role, row-level security and a column allowlist. The agent does not get a service role key, and a missing field stays empty.
Claix · November 2026. Related guides: prompt injection and data leaks, safe Supabase access, and the permissions checklist. Product: Claix Retrieve and Claix Guard.
When an agent answers questions about orders, payments, reservations or support tickets, customer data is in play. The question is not whether it can query the database. It is whether it can query only the data it needs, for the user making the request, without exposing the rest.
Why customer data leaks happen
A leak does not always mean someone broke in. The agent can retrieve data it should not see. A prompt will not stop that.
- The agent has access to every table.
- The agent can retrieve sensitive columns.
- The agent can access records from another tenant.
- The agent returns large result sets.
- The agent sends data to an external tool.
- The agent has write credentials it should not have.
- There is no audit trail.
The four layers of customer data protection
| Layer | What it controls | Why it matters |
|---|---|---|
| Database role | What the database user can do | Prevents broad privileges |
| Row-level security | Which rows a role can access | Helps isolate users and tenants |
| Column-level allowlist | Which columns an agent can retrieve | Prevents exposure of sensitive fields |
| Retrieval scope | Which tables an agent can use | Limits the agent’s data surface |
| Audit trail | What was requested and returned | Makes incidents investigable |
No single layer is enough. Claix does not replace the database role or row-level security. It sits on top of them.
Start with a dedicated read-only role
Do not connect the agent with a superuser, owner, administrator or Supabase service role. Create a dedicated role for retrieval. A support agent may read orders and customers. An operations agent may read inventory and shifts. A write-capable workflow needs a separate role, and that role stays in your executor, not in the agent. Retrieve connects with the read-only role and only reaches the tables and columns on the agent’s routes.
Use row-level security for tenant isolation
A role can say “this agent can read orders.” Row-level security says “only the orders that belong to this tenant.” Without the second boundary you are sharing data. Keep row-level security when different people or tenants share a table. Tenant identity should come from your application and the database session, not from the prompt.
Control columns and tables
A support agent may need order status and a contact method. It may not need payment details, internal notes or salary. A finance agent may see invoices and payments. A marketing agent may see campaigns and leads. Each of those is a route: the tables, the columns and a guide. The agent cannot freely query the rest of the database. If a question needs something outside that perimeter, the field comes back empty instead of a guess.
How Claix Retrieve limits what agents can see
Retrieve does not copy customer data into a vector store. The query runs where the data lives, inside the route. You create a route once and attach it to as many agents as you need. Each agent has its own endpoint, prompt, routes and response mode, so a support bot and an internal assistant can share Postgres or Supabase and still see different columns.
Queries are validated before they run. Traces show what was asked, which route answered and what came back. Typed answers, a boolean, a number, a list or a JSON object, let the workflow use a value without pulling a wide row into the model.
How to control writes
Guard checks a proposed INSERT, UPDATE or DELETE against rules you approved. Allowed means your code can execute it. Denied means it should not, and the agent receives the reason. Needs approval waits for a person. Claix has no write access and does not execute the statement. In n8n, call POST /check-sql before the Supabase node that writes. A denial is still HTTP 200. Read allowed.
What Guard can enforce
| Control | What it prevents |
|---|---|
| Operation type | Unwanted inserts, updates or deletes |
| Target table | Changes to tables outside the agent’s scope |
| Target columns | Changes to sensitive or protected fields |
| Record selection | Updates or deletes that affect too many records |
| Value limits | Discounts, quantities, amounts or statuses outside allowed ranges |
| State transitions | Invalid changes from one status to another |
| Rate limits | Too many changes in a short period |
| Human review | High-risk actions that require approval |
| Audit trail | Missing evidence of what was proposed and decided |
How to audit what the agent accessed
A transcript shows what the agent said. It does not show which route ran or whether a write was allowed. Retrieve traces each request. Guard records the proposed statement, the verdict and the reason. Violations name the rules that denied it. See what to record for auditors.
Common mistakes
- Giving the agent every table and column. A prompt injection then has a much larger blast radius.
- Treating a prompt as a permission. It can guide behavior. It does not enforce it.
- Letting the agent hold write credentials, including a Supabase service role key. It can bypass Guard.
- Skipping tenant boundaries on a shared table.
- Skipping the trace, so an incident has no record of the request, the route and the decision.
How to get started
Claix supports Postgres, MySQL and MariaDB, plus Supabase. Connect with a read-only role, define the customer-data routes, and call one endpoint. Guard supports PostgreSQL, MySQL and MariaDB. Keep the write role in the executor.
Conclusion
Customer data needs a system, not a prompt. The database role and row-level security decide the rows. The route decides the tables and columns. Retrieve refuses to guess outside that perimeter. Guard checks a proposed change before your code runs it. Traces make the request reviewable.
You might also like…
Security · Guardrails
Prompt Injection Database Data Leak: How to Limit the Damage From AI Agents
Guides · Supabase
How to Give an AI Agent Safe Access to Your Supabase Database with Claix
Guides · Security
AI Agent Database Permissions Checklist: 12 Controls Before You Connect an Agent
Security · Audit
Audit Log for AI Agent SQL Queries: What to Record, Retain and Show Auditors