How do you restrict what SQL an AI agent can run?

Check each statement against rules set outside the AI. Verosek lets through what the agent's key allows and refuses the rest, with the reason, before the database sees it.

Vats Shah5 min read
[ In short ]

To restrict what SQL an AI agent can run, check each statement against rules set outside the AI, before it reaches the database. With Verosek, you connect the database once and give each agent a key that carries its rules: read only or also write, which tables it may touch, how many rows it may get back. A statement inside those rules runs. Any other comes back refused, with the reason, and the database never receives it.

[ On this page ]

A statement is one instruction in SQL, the language databases speak. An agent writes its statements while it runs, so no person reads them first. A model can misread a request, or something it read can talk it round, and it then writes DELETE FROM payments as easily as SELECT status FROM orders WHERE id = 4417. Fortune reported in July 2025 that a Replit coding agent deleted a live database during a code freeze.

[ 01 ]

What can a rule on an agent's SQL say?

A rule says what one agent's key may do in one database. You set four things:

  • whether it may only read, or may also write, and which kinds of write
  • which tables it may touch, or which it must never touch
  • how many rows a read may return
  • which database functions it may call

Verosek already refuses the riskiest database functions and system tables unless a rule lists them. On a warehouse, a rule can require a filter on a column you name, such as a partition, so a query without one comes back refused. It can also pass a cap on bytes billed to a warehouse tool that honours one.

Two agents on one database get different answers, because the rule sits on the key. Take a support agent that may read and update but must never touch payments, and a reporting agent that may read everything and change nothing.

[ One database, two keys ]

May read and update. Must never touch payments.

Open a line for the exact reply
SELECT status FROM orders WHERE id = 4417Allowed
What happens
The statement runs, and the agent gets its result.
SELECT * FROM paymentsBlocked
What the agent gets back
{"error": "Access denied: Access to table(s) blocked: payments"}
UPDATE orders SET status = 'refunded' WHERE id = 4417Allowed
What happens
The statement runs, and the agent gets its result.
DELETE FROM paymentsBlocked
What the agent gets back
{"error": "Access denied: Operations not allowed: DELETE. Allowed: SELECT, UPDATE"}
Figure 1. One database, two keys, the same four statements. Switch the key and the answers change. Illustrative values.
[ 02 ]

What happens to a blocked statement?

A blocked statement stops at Verosek, so the database never receives it and you have nothing to roll back. Say this key may only read. The agent writes DELETE FROM payments and gets the reason back in words it can act on: Access denied: Operations not allowed: DELETE. Allowed: SELECT. It can write a read instead, or tell the person it is helping what it cannot do. Verosek also refuses text that holds two statements or is not valid SQL. It does not guess at what the model meant.

[ 03 ]

Why not check that a query starts with SELECT?

A statement can open like a read and still delete rows. This one opens with WITH, ends in a SELECT and empties payments: WITH d AS (DELETE FROM payments RETURNING *) SELECT * FROM d. PostgreSQL's documentation says a data-modifying statement inside WITH runs "exactly once, and always to completion", whether or not the main query reads its output. Verosek decides by everything a statement does, wherever the write sits, and refuses this one as a DELETE.

1WITH d AS (
2 DELETE FROM payments RETURNING *
3)
4SELECT * FROM d
[ By how it opens ]

It opens with WITH and ends in SELECT.

A check on the wording calls it a read.

[ By what it does ]Blocked

It deletes every row in payments.

Verosek refuses it as a DELETE.

Open for the exact words the agent receives
What the agent gets backBlocked
The reply
{"error": "Access denied: Operations not allowed: DELETE. Allowed: SELECT"}
Figure 2. The same statement, judged by how it opens and by what it does. Illustrative values.
[ 04 ]

Can a model talk its way past the rule?

A rule reads the statement and the key, so a persuaded model gets the same answer. An attacker who plants a line in a ticket can change what the model asks for. That line cannot change what the key allows. A model talked round can still do whatever its key permits, so give each key only what its job needs.

[ 05 ]

Is a read-only database role still worth having?

Yes: keep the read-only database role, because the rule reads the statement and the role covers what the database does next. A view can read a table the statement never names, and a trigger or stored function runs inside the database, out of the rule's sight. A column you want kept from the agent stays with the role too: leave it out of what the role can read.

[ The rule reads this ]
Allowed
SELECT * FROM order_summary
[ The role covers this ]
A view
Reads a table the statement never names
A trigger
Fires inside the database
A stored function
Runs inside the database
A column
Kept out by what the role can read
[ The rule reads this ]
Allowed
SELECT * FROM order_summary
[ The role covers this ]
A view
Reads a table the statement never names
A trigger
Fires inside the database
A stored function
Runs inside the database
A column
Kept out by what the role can read
Figure 3. The line between what the rule reads and what the role covers. Illustrative values.

Verosek adds what a shared role cannot give you: a different rule for each agent on one connection, and a sealed record of what each agent tried, blocked attempts included.

[ 06 ]

How do you know what the agent tried?

Every statement leaves a record, the refused ones included. For each request you can see what the agent tried, what Verosek decided and why, and whether the statement ran. Verosek scrubs secrets and personal data before it stores the record, then seals it, so you can check later that nobody changed it. A tamper-evident audit trail covers what that seal proves and who holds its key.

[ 07 ]

What does it take to set up?

You connect the database to Verosek and give the agent a key. Your app keeps its OpenAI, Anthropic or Gemini SDK, points the base URL at Verosek and uses that key. From then on, the agent's SQL goes through the rule. To see this on your own schema, book a call.

[ 08 ]

Frequently asked questions

Can an agent be limited to read-only on specific tables?

Yes. One key's rule can allow only reads and name the tables it may touch, and Verosek refuses any statement outside that before it reaches the database. Another key on the same database can carry a different rule.

How do you keep a column's values from an agent?

Use the database: leave the column out of what the agent's role can read, or refuse the table in the rule. Turn on Shield, Verosek's scanning layer, and it can also redact personal data in what a tool returns, as that key's settings say.

What if a query asks for more rows than the rule allows?

It gets no more than the rule allows.

Which databases does this cover?

The SQL databases in Verosek's connector catalogue, among them Postgres, MySQL, Snowflake and BigQuery.

Does this cover SQL run by a tool in my own code?

No. The SQL rule covers database tools Verosek runs for the agent. A tool your own code runs falls under the key's tool policy: an allow list and a check of its arguments against your schema.

Keep reading

[ Field guide ]

How do you stop an AI agent's tool call before it runs?

Put the decision outside the AI. Verosek checks what an agent tries to do against the rules you set, lets the allowed actions through, stops the rest and keeps a sealed record of every decision.

6 Nov 20265 min read
[ Field guide ]

How do you secure AI agents?

Limit what each agent can do, decide each action outside the AI model, read what it reads and keep a record you can check. Verosek does all four in one place, so security is not a second vendor.

6 Nov 20267 min read
[ Reference ]

AI gateway, LLM router, MCP gateway, AI firewall: what is the difference?

A router picks the model, an AI gateway controls who may use it, a firewall reads the words, and an MCP gateway decides each tool call before it runs. Who needs which, and how Verosek does them on one key.

6 Nov 20266 min read

Rules for every tool call Verosek runs. Decided before it executes, outside the model.

Still curious? Ask your favourite AI about Verosek.