Back to blog
NewGuides · Guard

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

FieldWhat it tells you
allowedWhether the statement may proceed. True only for allow.
decision_idIdentifier for the check
codeShort verdict code
reasonHuman-readable explanation
operationInsert, update or delete
tableQualified table of the write
sqlThe statement that was checked
affected_rowsRows the statement would affect
violationsRules that deny the statement
rules_checkedNumber of rules evaluated
latency_msTime 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

CodeMeaning
allowedThe write satisfies the guards that cover it
needs_approvalNo rule denies it, and one asks a person to approve it. allowed is false
no_guardsThe connection has no active guards, so the statement is allowed
no_matching_guardActive guards exist, but none cover this operation and table
read_onlyIt is a read; guards limit writes
session_statementIt is a session or transaction setting
rule_deniedAn active rule forbids the statement
omitted_columnA rule reads a column the INSERT does not send
rule_unknownA value the rule needs is missing and the guard denies that case
unsupported_statementThe SQL form cannot be certified and the connection has active guards
parse_errorThe SQL could not be read
multiple_statementsThe request contains more than one statement
ambiguous_tableThe table name exists in more than one schema
unqualified_tableThe table is not qualified and does not belong to the connection schema
table_not_foundThe table is not on the connection
truncate_guardedTRUNCATE on a table watched by a DELETE guard
upsert_updateAn INSERT that also updates, while an UPDATE guard watches the table
replace_deletesREPLACE, while a DELETE guard watches the table
check_failedThe 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

CheckWhat it prevents
Operation typeUnwanted inserts, updates or deletes
Target tableChanges to tables outside the allowed scope
Target columnsChanges to sensitive or protected fields
Record selectionUpdates or deletes that affect too many rows
Value limitsDiscounts, quantities, amounts or statuses outside allowed ranges
State transitionsInvalid changes from one status to another
Rate limitsToo many changes in a short period
Human reviewHigh-risk actions that require approval
Audit trailMissing 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

VerdictWhat the hook should do
allowedLet the statement run
denied, including rule_deniedBlock the statement and return the reason
needs_approvalPause and send it to a person. Do not run it.
check_failedBlock the statement
parse_errorBlock the statement
multiple_statementsBlock the statement
unsupported_statementBlock 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

PracticeWhy it matters
Keep write credentials in the executorPrevents the assistant from bypassing the hook
Use a dedicated Slack channelLimits who can see proposed SQL
Validate the signed approval requestPrevents unauthorized approvals
Log every decisionCreates an audit trail
Use a test messageConfirms the channel works before production
Review approval ratesHelps you improve rules over time
Keep Denied for non-negotiable rulesPrevents 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.