Open-source guardrail

SQL that drops a schema or a table column

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.16Nov 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 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 SQL that drops a schema (DROP SCHEMA, with or without IF EXISTS and CASCADE; in MySQL the same statement as DROP DATABASE) or drops a column (ALTER TABLE … DROP COLUMN), matched in any case with any whitespace between the words. Held for approval rather than blocked, because the guard cannot see which database the client is connected to, and a scratch schema reset is routine. 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 migration 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 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 a DROP that starts a line with no indent (ALTER TABLE users, then DROP COLUMN email on the next line) or keywords split across lines (DROP then SCHEMA) are not caught. Not caught: a statement in a file the line does not show (psql -f drop.sql, a migration tool), a database MCP tool with another name, MySQL's ALTER TABLE … DROP name without the COLUMN keyword, a comment between the keywords (DROP/**/COLUMN), and SQL issued from inside application code. Over-matches, held anyway: a client word that appears only in text (gh pr create --body "… psql … DROP SCHEMA …"), and a read-only query whose output is searched for the words (psql -c "SELECT …" | grep -i "drop column"), 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.

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 (13)

  • psql -c "DROP SCHEMA public CASCADE;"
  • psql -c 'drop schema if exists scratch cascade'
  • mysql -e 'DROP SCHEMA app;'
  • psql -c "ALTER TABLE users DROP COLUMN email;"
  • psql -c 'alter table users drop column if exists email'
  • docker exec -it db psql -U app -c "Drop Schema reporting CASCADE;"
  • psql app <<'EOF' ALTER TABLE users DROP COLUMN legacy_id; EOF
  • PowerShellsqlcmd -S localhost -Q "ALTER TABLE dbo.Users DROP COLUMN Email"
  • psql -c "SELECT * FROM users" | grep -i "drop column"
  • MCP{"sql":"DROP SCHEMA public CASCADE;"}
  • MCP{"query":"ALTER TABLE cache DROP COLUMN payload;"}
  • MCP{"project_id":"proj","query":"ALTER TABLE users DROP COLUMN email;"}
  • MCP{"project_id":"proj","sql":"drop schema staging cascade"}

Stays quiet on (13)

  • git commit -m "docs: explain psql -c DROP SCHEMA public CASCADE;"
  • grep -rn "psql -c DROP SCHEMA public CASCADE;" docs/
  • echo "never run psql -c DROP SCHEMA public CASCADE;"
  • curl --data "we ran psql -c DROP SCHEMA public CASCADE;" https://api.example.com/comments
  • psql -c "CREATE SCHEMA reporting;"
  • psql -c "ALTER TABLE users ADD COLUMN email text;"
  • psql -c "ALTER TABLE users ALTER COLUMN email DROP DEFAULT;"
  • psql -c "ALTER TABLE users DROP CONSTRAINT users_email_key;"
  • psql -c "SELECT schema_name FROM information_schema.schemata;"
  • cat > migrations/0042_drop_email.sql <<'EOF' ALTER TABLE users DROP COLUMN email; EOF
  • gh pr create --title "Retire the legacy schema" --body "This migration runs DROP SCHEMA legacy CASCADE after the backfill."
  • MCP{"title":"Retire legacy","body":"Run DROP SCHEMA legacy CASCADE."}
  • MCP{"sql":"SELECT * FROM users;"}

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.

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.

agenttrail-guard
$agenttrail-guard guardrails show dd.sql-schema-drop# everything about it
$agenttrail-guard guardrails set-action dd.sql-schema-drop warn# block, ask or warn
$agenttrail-guard guardrails allow dd.sql-schema-drop '<pattern>'# silence one shape
$agenttrail-guard guardrails disable dd.sql-schema-drop# turn it off

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.

bash
$npm i -g @agenttrail/guard
Read the source on GitHub