Human Approval Before AI Agent Writes to Database: A Step-by-Step n8n and Slack Workflow
Allow routine writes, deny what nobody should do, and pause the rest for a person. Slack shows the SQL. Your n8n webhook runs it only after a signed approval.
Claix · November 2026. Related guides: Slack approvals, DELETE or UPDATE without a real WHERE, and n8n. Product: Claix Guard.
An AI agent can propose a database change in seconds. That is useful when the change is routine. It becomes risky when the change affects money, customer data, inventory, access permissions or a production system.
The question is not only “Can the agent write to the database?” The question is which writes can run automatically, which must be rejected, and which need a person to decide.
This guide explains how to add human approval before an AI agent writes to a database using Claix Guard, Slack and n8n.
Why AI agents need human approval
Not every database write should require a person. A routine status update can usually run automatically. A destructive operation should usually be denied. But some changes fall in between.
- A refund above a threshold.
- A discount above a normal limit.
- A change to a sensitive customer field.
- An update that affects more rows than expected.
- A deletion on a table that is usually protected.
- A change to an order total.
- A change to an employee record.
- A modification to a production configuration.
These actions may be legitimate. But they deserve a human decision. With only two outcomes, allow or deny, teams are forced to choose between blocking legitimate work or letting risky changes run without review.
The three verdicts you need
Claix Guard supports three verdicts:
| Verdict | When to use it | Example |
|---|---|---|
| Allowed | The change is inside your limits | A reservation changes from pending to confirmed |
| Needs approval | The change is permitted in principle, but a person should confirm this specific case | A refund above your threshold |
| Denied | Nobody should be able to do this | A destructive operation or a delete on a protected table |
A practical rule is: deny what nobody should ever do. Ask for approval on what a person can reasonably judge. Allow the rest.
If almost every approval request is accepted, the rule may be too strict. It may be better as an allowed rule with a limit. If almost every approval request is rejected, it should probably be denied. Too many approvals lead to people approving without reading.
How Claix Guard works
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: your code can execute the statement.
- Denied: your code should not execute it.
- Needs approval: the statement is paused until a person decides. allowed is false, so a client that runs only when allowed is true will not execute it.
Claix Guard does not execute the statement. Your own code, workflow or automation does. The agent proposes. Guard decides. Your executor enforces.
Why Claix does not execute SQL
Claix never executes SQL and has no write access to your database. That is intentional. Clicking Approve in Slack does not change anything by itself. The approval calls the endpoint you configured. That endpoint, your backend or your automation, runs the statement.
- The agent proposes the action.
- Guard decides whether the action follows your rules.
- Your executor performs the action only when it is allowed or approved.
The approval workflow
- The agent proposes a database change.
- Your code calls Claix Guard’s POST /check-sql.
- Guard returns allowed, denied or needs_approval.
- If the verdict is needs_approval, Claix sends the request to Slack or to your own endpoint.
- Your approve endpoint runs the statement; your reject endpoint notifies the agent or user.
Claix includes the proposed SQL in the Slack message, so a person can read it before deciding. The button itself carries only an opaque approval id. Claix resolves the approval on the server.
How Slack approval works
Claix can send each verdict to Slack or to a public HTTPS endpoint you already run. Setup: connect Slack.
| Verdict | Slack behavior | Endpoint behavior |
|---|---|---|
| Allowed | Plain message | Check result, including SQL |
| Denied | Plain message | Check result, including SQL |
| Needs approval | Message with Approve and Reject buttons | Check result, including SQL |
Only needs_approval messages include buttons. Allowed and denied alerts are sent without buttons.
When someone clicks Approve or Reject, Claix signs a POST to the endpoint you configured for that button. The X-Claix-Signature header is an HMAC-SHA256 of the body, using a per-endpoint secret shown once when you save it. The body includes approval_id, decision, statement_hash, timestamp and approver (the Slack user who clicked). The SQL is included only if you turn that option on. An expired approval is delivered as denied. A second click is told the decision was already made.
Why n8n is a good executor
n8n is useful because it can receive an HTTP request, run a database operation and notify a customer or agent. You do not need to build a custom backend to start. The same pattern is on the n8n integration page.
- A Webhook trigger that receives the approval decision.
- A step that verifies the signature before anything else.
- A Postgres node that runs the approved statement.
- A notification step that confirms the outcome.
- An error path that handles failures.
The same pattern works with Make, Zapier, a serverless function or any backend that can receive an HTTP request.
Step-by-step: approve a refund with n8n and Slack
This example shows how to approve a refund above a threshold.
Step 1: Create a Guard rule
Write a rule in plain English. For example: “Refunds above 200 euros require human approval.” Claix turns that description into a proposed exact rule. You can accept, reject or edit it before it becomes active.
Step 2: Connect Slack
Open the Guard alerts popup in your Claix dashboard. Click Add to Slack, choose the channel and accept the permissions. You do not need to create a Slack app or paste a bot token. Choose a channel carefully. Alerts include the proposed SQL, so send them where the right people, and only they, will see them.
Step 3: Set the destination for each verdict
Each verdict has one destination: a public HTTPS endpoint or Slack. You can mix them. allowed can stay on an endpoint you already use. denied can stay on the same endpoint. needs_approval can go to Slack. For needs_approval on Slack, set the endpoint that Approve calls and the endpoint that Reject calls.
Step 4: Create the n8n approve workflow
Create a workflow with a Webhook trigger. That webhook receives the approval decision from Claix. The workflow should receive the approval id and statement hash, verify the signature, run the approved statement using a Postgres node, confirm the outcome, and handle errors. The approve endpoint should do the whole job, including running the statement, so the button always leads to an outcome.
Step 5: Create the n8n reject workflow
Create a second workflow with a Webhook trigger. That webhook receives the rejection decision from Claix. It should verify the signature, notify the agent or user that the change was declined, and log the outcome. The reject endpoint should not run the statement.
A practical example
Say an agent proposes an update that issues a refund above your threshold. Your workflow sends the statement to Claix Guard and receives needs_approval. Claix posts the request in Slack. The finance lead reads the SQL and clicks Approve. Claix calls your approve endpoint, which is an n8n Webhook trigger followed by a Postgres node that runs the statement, and then confirms to the customer. If the lead clicks Reject, Claix calls your reject endpoint, which sends the agent a message that the change was declined.
What the approve endpoint receives
When someone clicks a button in Slack, Claix calls the endpoint you configured for that button. A body without the optional SQL looks like this:
{
"approval_id": "7d8e9f0a-1b2c-4d3e-8f90-a1b2c3d4e5f6",
"decision": "approved",
"statement_hash": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
"timestamp": "1763726400",
"approver": "U0123456789"
}- decision: approved or the rejection decision.
- approval_id: the id of this approval.
- statement_hash: a hash of the statement.
- timestamp: when the click was signed.
- approver: the Slack user who clicked.
Turn on the option if this call should also include the SQL. Verify X-Claix-Signature before you run anything. Docs: check SQL.
Security practices
| Practice | Why it matters |
|---|---|
| Keep write credentials in the executor | Prevents the agent from bypassing Guard |
| 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 |
Keep a dedicated role with narrow privileges, database constraints, row-level security where appropriate and logging alongside Guard.
Common mistakes
Giving the agent write credentials
If the agent can reach the database directly, it can bypass Guard. The guardrail becomes optional.
Using one Slack channel for everything
Alerts include the proposed SQL. Use a channel where the right people, and only they, will see them.
Treating approval as automatic execution
Clicking Approve does not run the statement. Your endpoint does.
Using approvals for everything
If almost every request is approved, the rule is probably too strict. Move it to an allowed rule with a limit.
Skipping audit logs
Every decision should be recorded so you can review what was proposed and why it was allowed or denied. See what to record in an audit log.
How to get started
Claix Guard works with any agent framework, MCP client or automation tool that can send an HTTP request.
- 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 executor function or agent tool.
- Execute only when the response is allowed; return the denial reason when it is not. For needs_approval, wait for the signed callback.
Conclusion
Human approval is not a replacement for guardrails. It is a way to handle the cases where a rule is not enough. Claix Guard supports three verdicts: allowed for routine changes, needs approval for judgment calls, and denied for actions nobody should be able to do. With Slack and n8n, you can pause a risky write, send it to the right person and let them approve or reject it with a button. Claix never executes SQL. Your endpoint does.
You might also like…
Product · Guard
Claix Guard Now Sends Alerts and Approval Requests to Slack
Security · Guardrails
How to Stop an AI Agent From Running DELETE or UPDATE Without a WHERE Clause
Guides · Guard
Stop Cursor or Claude Code From Running Destructive SQL: Use a Pre-Execution Check
Security · Audit
Audit Log for AI Agent SQL Queries: What to Record, Retain and Show Auditors