Your assistant runs SQL on your site's database with one tool, apply_sql. It takes a list of statements, runs them in a single transaction, refuses five kinds of statement before the transaction is opened, and reads the schema back in the reply every time.
That is the whole decision. The rest of this post is why the database half of the product needed a tool at all, why a tool that runs arbitrary SQL still refuses anything, and what that refusal does not claim.
A connection string nobody in the room could use
The database half was built and working before this tool existed. A site could have a database, a restricted role for its functions, row-level security checked on every deploy, and a one-time transfer that hands the whole thing to you. All of it ran end to end through the connector.
Then the gap. Nothing in the tool list could run SQL. create_database returned an owner connection string, and there was no way to use it. The schema in the first demonstration had been created from a laptop, in a terminal.
The person this product is for has no terminal. That is close to the definition of the person who needs us. They reach juudd from a chat window, and the thing doing the work is their assistant. So the credential was one nobody present could use, and the assistant could not create a table either. A customer with a built folder could at least deploy files; a customer who wanted a database could not even start.
One list, one transaction
The tool is apply_sql(site, statements[]). Statements arrive as an array, one per entry, not as one string of semicolons. That is what the driver's transaction takes, and it lets a refusal or a failure name which statement it means, by the number the caller gave it.
All of them run in one transaction, and the reason is a state the platform already refuses. A table without a row policy cannot be deployed against, and it is exactly what an assistant leaves behind when it creates a table and then goes on to think about the next thing. In one call, the table and its policy either both exist or neither does.
When a statement fails, the reply says two facts, because they are different facts:
- The transaction rolled back, so the database is exactly as it was.
- None of the statements applied, including the ones before the one that failed.
A model that reads only the first fact re-sends the list from the failing statement, and the earlier ones are gone. So the reply says both, and ends with the instruction to fix that statement and send the whole list again. This was measured, not assumed: a check creates a real database and sends a list whose third statement is bad, and neither the table the first would have created nor the row the second would have inserted is there afterwards.
Parameters are not supported. A schema is literal SQL, and adding a second array of values whose entries have to line up with the first is a way to get them out of step.
Five statements are refused before anything runs
The obvious objection comes first, and the code answers it in as many words: the owner connection string is already in the caller's hands, so a check here is not a privilege boundary. Anyone who wants to run these statements can open their own terminal and run them. This guard is not a security claim and is never written up as one.
What it is for is a window. The deploy gate reads the schema at the moment a site is published and then does not run again. Between two deploys a live site is serving visitors and nothing is looking at the schema. Every refused statement is one whose effect inside that window is immediate and public. Turning row-level security off on a table the site is already serving does not fail a later deploy. It publishes the table now, to whoever asks next.
| Refused | Because |
|---|---|
DISABLE ROW LEVEL SECURITY | publishes a live table immediately; the deploy gate will not run again until the next deploy |
BYPASSRLS or SUPERUSER on a role | ignores every policy on every table, silently, and every query still works |
GRANT or REVOKE reaching juudd_app | grants made at the gate are what make an unprotected table unreachable rather than merely policy-less |
DROP or ALTER on the role juudd_app | its password lives only in the site's own binding and this platform keeps no copy, so the site goes down and nothing here can restore it |
ALTER DEFAULT PRIVILEGES | gives access to every future table, with row security off by default; one forgotten line publishes a table with no error anywhere |
juudd_app is the role your site's functions connect as. The grant rule is wider than its spelling: a grant to PUBLIC reaches it without naming it, so that is refused too.
Each refusal names what to do instead, the way every refusal in this codebase does, because the reader is a model. It recovers from "replace the policy, and here is the statement" in one turn, and from "that is not allowed" in several, if at all. The refusal also comes before the transaction is opened, says that nothing ran, and is written into your account's history in its own words, like every other no.
The schema is read back every time
After a successful call the reply includes the same schema inspection the deploy path runs. An assistant that has just created a table learns in that turn that it needs a policy, with the statement that fixes it, rather than at deploy time several steps later, when the connection between the mistake and the refusal has to be rebuilt.
What the guard will not claim
The check matches on text, and text is not a parser. A statement can be written to slip past it, and a determined caller will manage that on the first try. That is accepted. The rules are worded for the caller who did not realise, not for the one who did, so the guard catches mistakes, not intent, and nobody should quietly upgrade it into more than that.
One limit of the single transaction is also worth naming. Anything that cannot run inside a transaction block cannot run through this tool, a concurrent index build among them. Nobody has hit it yet.
What we turned down
A raw tool with no gate. Simplest to build and never in the way. It would also make the deploy gate the only thing between a mistake and a public table, and that gate does not run while a site is live, which is most of the time.
Separate tools for querying and for migrations, with a recorded history. More honest about two different intentions, and a replayable schema history is worth having. But it asks the model to choose the right tool every time, and it was a bigger build for a product whose database half could not yet be started. It is deferred, not refused: a migration history would be added on top of this tool rather than replace it.
The rule, once
Your assistant gets one tool to run SQL: one list, one transaction, five kinds of statement refused with the fix named, and the schema read back after every call. It is a net for mistakes made while a site is live, not a wall against intent. Every tool and what it refuses is listed in the docs.