Stop Cursor or Claude Code From Running Destructive SQL: Use a Pre-Execution Check
A prompt will not stop Cursor or Claude Code from running a bad write. Call /check-sql from a hook before execution, and block anything that is not allowed.
Claix · November 2026. Related guides: human approval before a write, DELETE or UPDATE without a real WHERE, and check SQL. Product: Claix Guard.
AI coding assistants are getting better at writing SQL. That is useful for developers. It is also risky when the assistant can run that SQL against a production database. A single destructive statement can delete records, truncate a table, overwrite data or break a production workflow.
The question is not “Can Cursor or Claude Code write SQL?” They can. The question is whether you can stop a destructive statement before it runs.
This guide explains how to add a pre-execution check that calls Claix Guard’s /check-sql before any write. Claix does not attach itself to Cursor or Claude Code. Your hook, executor or automation is what allows, blocks or pauses the statement.
Why destructive SQL is a real risk
AI coding assistants can generate SQL quickly. That speed is useful, but it also means a mistake can happen fast.
- A delete without a sufficiently specific condition.
- A truncate on a production table.
- An update that affects too many rows.
- A change to a sensitive column.
- A write that violates a business rule.
- A statement that is valid but wrong for the task.
- A query that runs before someone reviews it.
A valid statement is not always a safe statement. An update can be technically valid and still violate a business rule. The database accepts the value because it is valid. The business does not.
Why prompts are not enough
You can instruct Cursor or Claude Code not to run destructive SQL. But a prompt is not a permission system. Instructions can be misunderstood. They can conflict with other instructions. They can be overridden by another part of the workflow. And they cannot reliably guarantee that the assistant will follow them in every situation.
A prompt can guide behavior. It should not be the only thing standing between an assistant and a production database.
The right place to check
The right place to check is before execution. Not after. Not in a review comment. Not in a chat message. Before the statement runs. A hook can intercept a proposed statement, send it to a checker and decide whether to allow it.
How Claix Guard fits
Claix Guard is a checker for the database changes an AI agent proposes. Before an agent runs an INSERT, UPDATE or DELETE, Guard checks the proposed statement and its parameters against rules you approved.
- Allowed: the statement may proceed.
- Denied: the statement should not run.
- Needs approval: the statement is paused until a person decides. allowed is false.
Claix Guard does not execute the statement. Your own code, workflow or automation does. The assistant proposes. Guard decides. Your executor enforces.
The /check-sql endpoint
Claix Guard exposes POST /check-sql. You send the statement the agent wants to run and Claix answers whether the active guards of that connection allow it. The check is deterministic. It reads the SQL, applies the published guards and returns a verdict. The endpoint is built for server-to-server calls. The caller decides what to do with the verdict. Docs: check SQL.
What /check-sql returns
| Field | What it tells you |
|---|---|
| allowed | Whether the statement may proceed. True only for allow. |
| decision_id | Identifier for the check |
| code | Short verdict code |
| reason | Human-readable explanation |
| operation | Insert, update or delete |
| table | Qualified table of the write |
| sql | The statement that was checked |
| affected_rows | Rows the statement would affect |
| violations | Rules that deny the statement |
| rules_checked | Number of rules evaluated |
| latency_ms | Time the check took |
A 200 response covers both an allow and a denial. The decision is in allowed. A denial is still HTTP 200.
Verdict codes
| Code | Meaning |
|---|---|
| allowed | The write satisfies the guards that cover it |
| needs_approval | No rule denies it, and one asks a person to approve it. allowed is false |
| no_guards | The connection has no active guards, so the statement is allowed |
| no_matching_guard | Active guards exist, but none cover this operation and table |
| read_only | It is a read; guards limit writes |
| session_statement | It is a session or transaction setting |
| rule_denied | An active rule forbids the statement |
| omitted_column | A rule reads a column the INSERT does not send |
| rule_unknown | A value the rule needs is missing and the guard denies that case |
| unsupported_statement | The SQL form cannot be certified and the connection has active guards |
| parse_error | The SQL could not be read |
| multiple_statements | The request contains more than one statement |
| ambiguous_table | The table name exists in more than one schema |
| unqualified_table | The table is not qualified and does not belong to the connection schema |
| table_not_found | The table is not on the connection |
| truncate_guarded | TRUNCATE on a table watched by a DELETE guard |
| upsert_update | An INSERT that also updates, while an UPDATE guard watches the table |
| replace_deletes | REPLACE, while a DELETE guard watches the table |
| check_failed | The check could not finish; the statement is denied |
How to use a hook
A hook is a small script or function that runs before an action. For Cursor or Claude Code, the idea is simple:
- The assistant proposes a SQL statement.
- Your hook intercepts it.
- The hook calls /check-sql.
- If the verdict is allowed, the hook lets the statement run.
- If the verdict is denied, the hook blocks it.
- If the verdict is needs_approval, the hook pauses and sends it to a person.
The hook must be the only path to execution. If the assistant can reach the database directly with write credentials, it can bypass the hook.
What to check before execution
| Check | What it prevents |
|---|---|
| Operation type | Unwanted inserts, updates or deletes |
| Target table | Changes to tables outside the allowed scope |
| Target columns | Changes to sensitive or protected fields |
| Record selection | Updates or deletes that affect too many rows |
| Value limits | Discounts, quantities, amounts or statuses outside allowed ranges |
| State transitions | Invalid changes from one status to another |
| Rate limits | Too many changes in a short period |
| Human review | High-risk actions that require approval |
| Audit trail | Missing evidence of what was proposed and decided |
These checks are complementary. Database permissions and constraints remain important, but they do not cover every business rule.
Why a hook is not enough by itself
A hook is useful, but it is not a complete security model. You still need a dedicated database role with narrow privileges, database constraints and validation, row-level security where appropriate, audit logs, and a process for reviewing incidents.
How to structure the hook
- Receive the proposed statement.
- Send it to /check-sql.
- Read allowed and the verdict code. Do not treat HTTP 200 as success.
- Decide whether to allow, block or pause.
- Return a clear reason to the assistant.
- Log the decision.
The hook should not try to interpret the SQL itself. That is Guard’s job.
What to do with each verdict
| Verdict | What the hook should do |
|---|---|
| allowed | Let the statement run |
| denied, including rule_denied | Block the statement and return the reason |
| needs_approval | Pause and send it to a person. Do not run it. |
| check_failed | Block the statement |
| parse_error | Block the statement |
| multiple_statements | Block the statement |
| unsupported_statement | Block the statement |
How to handle needs approval
If the verdict is needs_approval, the hook should pause. The statement should not run automatically. You can send it to Slack or to your own endpoint. Claix can post the request to Slack with Approve and Reject buttons. When someone clicks Approve, Claix calls the endpoint you configured. That endpoint runs the statement. When someone clicks Reject, Claix calls your reject endpoint, which can notify the assistant that the change was declined. The full flow is in human approval with n8n and Slack.
Security practices
| Practice | Why it matters |
|---|---|
| Keep write credentials in the executor | Prevents the assistant from bypassing the hook |
| Use a dedicated Slack channel | Limits who can see proposed SQL |
| Validate the signed approval request | Prevents unauthorized approvals |
| Log every decision | Creates an audit trail |
| Use a test message | Confirms the channel works before production |
| Review approval rates | Helps you improve rules over time |
| Keep Denied for non-negotiable rules | Prevents normalizing risky actions |
Common mistakes
Giving the assistant write credentials
If the assistant can reach the database directly, it can bypass the hook.
Treating a prompt as a permission
A prompt can guide behavior, but it is not an enforcement mechanism.
Using one Slack channel for everything
Alerts include the proposed SQL. Use a channel where the right people, and only they, will see them.
Skipping audit logs
Every decision should be recorded so you can review what was proposed and why it was allowed or denied.
How to get started
- Create a policy and write your first rules in plain English.
- Review and approve the proposed exact rules.
- Test the policy in the Sandbox, including actions that should be denied.
- Call Guard before every write from your hook or executor.
- Execute only when allowed is true; return the denial reason when it is not.
Conclusion
AI coding assistants can write SQL fast. That is useful, but it also means a mistake can happen fast. The right place to stop a destructive statement is before it runs. Claix Guard gives you the pre-execution check: allowed for safe writes, needs approval for judgment calls, and denied for actions nobody should be able to do. Your hook calls /check-sql before execution. Your executor runs the statement only when it is allowed or approved. Claix never executes SQL. Your endpoint does.
You might also like…
Guides · Guard
Human Approval Before AI Agent Writes to Database: A Step-by-Step n8n and Slack Workflow
Security · Guardrails
How to Stop an AI Agent From Running DELETE or UPDATE Without a WHERE Clause
Guides · Security
AI Agent Database Permissions Checklist: 12 Controls Before You Connect an Agent
Guide · Security
Why Giving an AI Agent Direct SQL Access Is Dangerous (and What to Do Instead)