
An AI agent that can query your database can answer questions no dashboard anticipated. It can also, if you are careless, delete a table. These are the six rules we are building into Brainbox, our AI operations platform, and they apply to any agent that touches real data.
1. Read-only, enforced twice
The agent connects with a database user that only has permission to read. Then the gateway checks every statement again and refuses anything that is not a query: DELETE, DROP, ALTER, UPDATE, INSERT. Two independent checks mean a mistake in one is caught by the other.
2. Parameterised queries
Values are never pasted into SQL text. They are passed as parameters, so the database treats them as data and not as instructions. This closes the door on SQL injection, including injection that arrives through text the agent has read.
SELECT id, status, created_at
FROM orders
WHERE customer_id = %(customer_id)s
ORDER BY created_at DESC
LIMIT 1003. Row limits
Every query has a maximum number of rows. An agent investigating a problem needs a sample, not an export. A limit also protects the database from a query that would otherwise scan millions of rows.
4. Tenant isolation
When several customers share a system, each request carries a tenant identifier and can only reach that tenant's data. The check lives in the gateway, not in the prompt: you cannot rely on a model to remember a rule.
5. Rate limiting
Each key has a limit on how many queries it can run in a period. An agent stuck in a loop then runs out of allowance instead of running up load.
6. An audit log
Every query is recorded: who asked, what ran, when, and how many rows came back. When something looks wrong, the log answers the question "what did the agent actually do?".
The principle underneath
All six rules follow from one idea: safety belongs in the system, not in the instructions. A prompt that says "never delete data" is a request. A database user without delete permission is a guarantee.
Related reading: Building AI assistants that act, not just chat.


