Open-source guardrail
SQL DELETE or UPDATE with no WHERE clause
AgentTrail Guard asks you about this by default: you decide before the call runs. Where an agent cannot ask, the call is refused instead.
- Default action
- Ask
- Severity
- High severity
- Library version
- 0.2.16 · Nov 26, 2026
Mapped to the OWASP Top 10s
An id names a risk this guardrail addresses where it becomes a command or a file read or write, never the whole risk.
What it does
What it catches, and what it misses
Written into the rule itself, next to what it matches, so you can judge it before you trust it.
Holds a SQL DELETE FROM <table> or UPDATE <table> … SET that has no WHERE later in the same statement, so it changes every row, matched in any case with any whitespace between the words. Each statement is judged on its own: a ; ends it, so a scoped statement before or after does not lend it a WHERE. DELETE … USING and UPDATE … FROM without a WHERE are held, and so is EXPLAIN ANALYZE, which runs the statement. Held for approval rather than blocked, because clearing a table in a local test database is routine and the guard cannot see which database the client is connected to. On a shell command (Bash, PowerShell, and the Cursor and Codex shells mapped to them) it holds only when a SQL client is on the same command, the same list block-destructive-sql reads (psql, mysql, sqlite3, sqlcmd and others, including through docker exec, kubectl exec, ssh or an env prefix), so SQL that is only text is not held: a PR body, a heredoc that writes a seed file, a note. On MCP it holds only for the database tools MCP_COMMAND_FIELDS names (the PostgreSQL reference server's query, the SQLite reference server's read_query, write_query and create_table, Supabase's execute_sql and apply_migration, Neon's run_sql), under any server name, so a ticket or a message sent through another MCP tool is not held. For those tools it currently matches the tool's whole input, serialized as JSON, not only its SQL argument; it will read only the SQL argument once tool inputs are split by field. Until then a WHERE anywhere in the input, including in another argument, counts as scoping the statement, which is a miss; a statement in another field of the tool is held too; and a line break inside the SQL arrives as the two characters \n, which count as neither a space nor a word boundary, so DELETE and FROM on separate lines, or an UPDATE whose SET starts a line with no indent, are not caught, while a scoped statement whose WHERE starts a line with no indent is held. Not caught: any WHERE in the statement counts, including one inside a comment, a string or a subquery, and a tautology such as WHERE 1=1; a second psql -c whose statement has a WHERE; MySQL's UPDATE a JOIN b … SET; T-SQL's DELETE TOP (n) and DELETE <table> without FROM; a comment between the keywords (DELETE/**/FROM); a statement in a file the line does not show (psql -f reset.sql); a database MCP tool with another name; and SQL issued from inside application code. Over-matches, held anyway: a plain EXPLAIN of such a statement, which does not run it; a WHERE more than 1000 characters into the statement; a client word that appears only in text; a read-only query whose output is searched for the words (psql -c "SELECT …" | grep -i "delete from"), because the client and the words share the line. A quoted MENTION is not a use: a search, a git commit -m message, an echo or a curl --data body that only names this command is left alone. That holds only while every shell metacharacter stays inside the quotes, so git commit -m "x" && … is still caught; and the carrier must be the first word, so sudo grep … is not exempt.
Examples
Tested on every build
The rule must match every command on the left and none on the right, or the library does not build. Catching the real thing is easy; staying quiet on the near-miss is the hard part.
Catches (23)
- psql -c "DELETE FROM sessions;"
- psql -c 'delete from sessions'
- sqlite3 app.db 'DELETE FROM cache;'
- mysql -e 'DELETE FROM audit_log'
- psql -c "DELETE FROM sessions WHERE id = 1; DELETE FROM tokens;"
- psql -c "DELETE FROM orders USING customers;"
- psql -c "WITH stale AS (SELECT id FROM jobs WHERE done) DELETE FROM jobs;"
- psql -c "UPDATE users SET plan = 'free';"
- mysql -e 'update users u set u.active = 0'
- psql -c "UPDATE ONLY users SET active = false;"
- psql -c "UPDATE users AS u SET active = false;"
- psql -c "UPDATE orders SET total = t.total FROM totals t;"
- psql -c 'UPDATE "Users" SET active = false;'
- psql app <<'EOF' UPDATE users SET plan = 'free'; EOF
- psql -c "EXPLAIN ANALYZE DELETE FROM sessions;"
- docker exec -it db psql -U app -c "DELETE FROM users;"
- PowerShellsqlcmd -S localhost -Q "DELETE FROM dbo.Sessions"
- psql -c "EXPLAIN DELETE FROM sessions;"
- psql -c "SELECT * FROM users" | grep -i "delete from"
- MCP{"sql":"DELETE FROM users;"}
- MCP{"query":"update users set plan = 'free'"}
- MCP{"project_id":"proj","query":"DELETE FROM sessions;"}
- MCP{"project_id":"proj","sql":"UPDATE accounts SET balance = 0;"}
Stays quiet on (24)
- git commit -m "docs: explain psql -c DELETE FROM sessions;"
- grep -rn "psql -c DELETE FROM sessions;" docs/
- echo "never run psql -c DELETE FROM sessions;"
- curl --data "we ran psql -c DELETE FROM sessions;" https://api.example.com/comments
- psql -c "DELETE FROM sessions WHERE expires_at < now();"
- psql -c 'delete from sessions where id = 1'
- psql -c "UPDATE users SET active = false WHERE id = 7;"
- psql app <<'EOF' DELETE FROM sessions WHERE expires_at < now(); EOF
- psql -c "UPDATE orders SET total = t.total FROM totals t WHERE orders.id = t.id;"
- psql -c "DELETE FROM orders USING customers c WHERE orders.customer_id = c.id;"
- psql -c 'UPDATE "Users" SET active = false WHERE "id" = 1;'
- psql -c "SELECT * FROM users;"
- psql -c "EXPLAIN SELECT * FROM users;"
- psql -c "INSERT INTO counts (id, n) VALUES (1, 1) ON CONFLICT (id) DO UPDATE SET n = counts.n + 1;"
- mysql -e 'INSERT INTO counts VALUES (1, 1) ON DUPLICATE KEY UPDATE n = n + 1'
- psql -c "SELECT * FROM jobs FOR UPDATE SKIP LOCKED;"
- psql -c "CREATE TRIGGER touch BEFORE UPDATE ON users FOR EACH ROW EXECUTE FUNCTION touch();"
- psql -c 'GRANT UPDATE ON users TO app;'
- apt-get update && set -e && psql -c 'SELECT 1;'
- cat > seed.sql <<'EOF' DELETE FROM sessions; EOF
- gh issue comment 42 --body "Ran UPDATE users SET plan = free to fix the import."
- MCP{"title":"Reset plans","body":"Run UPDATE users SET plan = 'free', then DELETE FROM sessions."}
- MCP{"sql":"DELETE FROM users WHERE id = 1;"}
- MCP{"query":"SELECT * FROM users;"}
In your agent
What "ask" means in each app
The guard runs as a hook in each app, and each app gives a hook different powers. Here is what this rule's default action does in each one.
- Claude Code
- You are asked before the call runs. If your settings.json already allows the tool outright, Claude Code runs it with no prompt.
- Cursor
- A terminal command that reaches the guard gets Cursor's approval card. Any other call that needs approval, such as a file edit or a read, is refused, because Cursor cannot ask there.
- Codex CLI
- Codex cannot ask, so the call is refused, and the reason says a person has to approve it.
Each app hands the guard a different set of calls: in a Cursor sandbox run mode, for one, some terminal commands run without reaching the guard at all. Read the notes for Cursor and for Codex CLI before you rely on a rule there.
Make it yours
Change what it does in one command
Turn it off, change its action, or silence it on one command shape. The narrow one is allow: the rule keeps catching everything else.
Run it locally
Put these guardrails in front of your agent.
AgentTrail Guard is free and open source. It checks every command and file change against the whole library before your agent runs it, on your machine, with no account.
npm i -g @agenttrail/guard