Best Way to Add Human Approval to an n8n AI Agent Before It Writes to Your Database
Allowed writes run. Denied writes stop. Needs approval posts the SQL to Slack, and the n8n webhook runs it only after a signed Approve.
Claix · November 2026. Related guides: the same approval flow in detail, Slack approvals, and n8n. Product: Claix Guard.
n8n is great for building automations. When you add an AI agent, the question changes. It is no longer only “How do I connect this app to that app?” It becomes “How do I let an AI agent write to my database without letting it make a mistake?”
This guide explains the best way to add human approval to an n8n AI agent before it writes to your database.
Why n8n 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. 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. They deserve a human decision.
The three verdicts you need
| 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 |
Write what the agent is allowed to change. Guard denies everything that does not fit. Ask for approval only on a permitted case a person should still confirm. If almost every approval request is accepted, that case can stay inside the permission. If almost every one is rejected, it does not belong in the permission. Too many approvals lead to people approving without reading.
How Claix Guard works
Claix Guard checks the database change an AI agent proposes. Before an agent runs an INSERT, UPDATE or DELETE, your n8n workflow calls POST /check-sql with the statement and its parameters. Guard applies the active rules of that connection and returns a verdict. Allowed: your workflow can execute the statement. Denied: it should not. Needs approval: the statement is paused until a person decides. needs_approval comes back with allowed set to false. A denial is still HTTP 200. Read allowed and code.
Claix Guard does not execute the statement. Your workflow does.
Why Claix does not execute SQL
Claix never executes SQL and has no write access to your database. Clicking Approve in Slack does not change anything by itself. The approval calls the endpoint you configured. That n8n webhook runs the statement. The agent proposes the action. Guard decides whether it follows your rules. Your executor performs it only when it is allowed or approved.
The approval workflow
- The agent proposes a database change.
- Your n8n workflow 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.
How Slack approval works
| 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. The X-Claix-Signature header is an HMAC-SHA256 of the body, using a per-endpoint secret shown once when you save it. The SQL is included in that POST only if you turn the option on.
Why n8n is a good executor
n8n can receive an HTTP request, run a database operation and notify a customer or agent. You do not need a custom backend to start. A typical workflow has a Webhook trigger, a step that verifies the signature, a Postgres node that runs the approved statement, a notification, and an error path. The same pattern works with Make, Zapier, a serverless function or any backend that can receive an HTTP request. See the n8n integration.
Step-by-step: approve a refund with n8n and Slack
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. Alerts include the proposed SQL, so use a channel only the right people can see. Setup: connect Slack.
Step 3: Set the destination for each verdict
Each verdict has one destination: a public HTTPS endpoint or Slack. allowed and denied can stay on an endpoint you already use. needs_approval can go to Slack. For that Slack destination, set the endpoint Approve calls and the endpoint Reject calls. Those URLs are your n8n webhooks.
Step 4: Create the n8n approve workflow
Create a workflow with a Webhook trigger. It should receive the approval id and statement hash, verify X-Claix-Signature, run the approved statement with 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. 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
An agent proposes an update that issues a refund above your threshold. The n8n 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 webhook, which verifies the signature, runs the statement in Postgres and confirms to the customer. If the lead clicks Reject, the reject webhook tells the agent the change was declined.
What the approve endpoint receives
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 the signature before you run anything. An expired approval is delivered as denied. A second click is told the decision was already made.
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 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 database 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 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 n8n webhook 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.
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 the n8n executor.
- Execute only when the response is allowed. For needs_approval, wait for the signed callback.
Conclusion
Human approval is not a replacement for guardrails. It handles the cases where a rule is not enough. Allowed covers routine changes. Needs approval covers judgment calls. Denied covers actions nobody should be able to do. Slack and n8n 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 webhook does.
You might also like…
Guides · Guard
Human Approval Before AI Agent Writes to Database: A Step-by-Step n8n and Slack Workflow
Guides · Guard
Best Way to Automate Refunds With an AI Agent: Limits and Approvals
Product · Guard
Claix Guard Now Sends Alerts and Approval Requests to Slack
Guides · Guard
Stop Cursor or Claude Code From Running Destructive SQL: Use a Pre-Execution Check