Back to blog
Guides · Guard

Best Way to Automate Refunds With an AI Agent: Limits and Approvals

Refunds under the limit can run. Refunds over it wait for Slack. Guard checks the database write. Your n8n webhook calls the payment gateway.

Claix · November 2026. Related guides: n8n approval webhooks, support agents and order status, and safe Supabase access. Product: Claix Guard.

Refunds are one of the clearest cases where an AI agent can help. A customer asks for a refund. The agent checks the order, applies your policy and creates the refund. Refunds involve money, so the question is not only whether the agent can issue one. It is which refunds can run automatically, which must be rejected, and which need a person to decide.

This guide uses n8n, Supabase and a payment gateway, with Guard rules, limits and human approval above a threshold.

Why refunds need guardrails

A refund is a financial action. A mistake can cost money, affect customer trust or create a compliance problem. A prompt is not enough.

  • A refund issued for the wrong order.
  • A refund issued twice.
  • A refund above the allowed limit.
  • A refund issued without checking eligibility.
  • A refund issued for a closed or already refunded order.
  • A refund issued too many times in a short period.
  • A refund issued without a record of who approved it.

The three verdicts you need

VerdictWhen to use itExample
AllowedThe refund is inside your limitsA refund below your threshold
Needs approvalThe refund is permitted in principle, but a person should confirm this specific caseA refund above your threshold
DeniedNobody should be able to do thisA refund on a protected or already refunded order

Write the refunds the agent is allowed to create. Guard denies every refund that does not fit. Ask for approval only on a permitted refund a person should still confirm. If almost every approval 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

Before the workflow runs an INSERT, UPDATE or DELETE, it calls POST /check-sql with the statement and its parameters. Guard applies the active rules and returns a verdict. Allowed: the workflow can execute the statement. Denied: it should not. Needs approval: the statement waits for a person. needs_approval has allowed set to false. A denial is still HTTP 200. Read allowed and code. Claix does not execute the statement.

What Guard controls and what it does not

Guard controls the database write. It does not control the payment gateway call.

ActionWhat Guard controlsWhat your workflow controls
Create a refund recordThe proposed INSERTThe payment gateway call
Update an order statusThe proposed UPDATEThe refund execution
Mark an order as refundedThe proposed UPDATEThe customer notification
Call a payment gatewayNot a database writeYour n8n workflow or backend
Send a confirmation emailNot a database writeYour n8n workflow or backend

Guard decides whether the database change follows your rules. Your workflow decides whether to call the payment gateway. Do not call the gateway on a denied or unapproved write.

Why n8n is a good executor

n8n can receive the approval HTTP request, run the database operation and call a payment gateway. You do not need a custom backend to start. A typical workflow has a Webhook trigger, a signature check, a Supabase node for the approved statement, a payment gateway node, a notification and an error path. The same pattern works with Make, Zapier or a serverless function.

Step-by-step: automate a refund with limits and approvals

Step 1: Define your refund policy

Write the policy in plain English. Claix turns each description into a proposed exact rule. You accept, reject or edit it before it becomes active.

  • Refunds below 200 euros can be issued automatically.
  • Refunds above 200 euros require human approval.
  • Refunds cannot be issued for already refunded orders.
  • No more than five refunds per hour.
  • Agents can create refund records, but never delete them.
  • Agents can update an order status, but never its price.

Step 2: Connect Supabase

Claix supports Postgres, including Supabase. Connect Retrieve with a read-only role. Routes for this agent can include orders, customers, payments and refunds, and nothing else. The write role stays in n8n. Do not put a Supabase service role key on the agent. See safe Supabase access.

Step 3: Let the agent check eligibility

Before proposing a refund, ask Retrieve whether the order exists, whether it has already been refunded, whether the customer is eligible, what the amount is, and whether that amount is under the automatic threshold. Reasoned mode returns booleans and numbers the workflow can branch on. The mode is set on the agent, not in the request.

Step 4: Send the proposed write to Guard

When the agent wants to create a refund record or update an order status, send that statement to Guard. Allowed means the workflow can execute it and then call the gateway. Denied means it should not do either. Needs approval means both wait.

Step 5: Route the approval to Slack

Open the Guard alerts popup. Click Add to Slack, choose the channel and accept the permissions. You do not create a Slack app or paste a bot token. Alerts include the proposed SQL, so use a finance channel, not a public one. Setup: connect Slack.

Step 6: Set the destination for each verdict

Each verdict has one destination. allowed can go to the n8n webhook that writes the row and calls the gateway. denied can go to an endpoint that tells the agent why. needs_approval can go to Slack, with separate Approve and Reject webhook URLs.

Step 7: Create the n8n approve workflow

The Webhook trigger receives the decision. Verify the signature, run the approved statement with a Supabase node, call the payment gateway, confirm the outcome and handle errors. The approve endpoint should do the whole job, so the button always leads to an outcome. If the database write succeeds and the gateway call fails, your error path has to record that. Guard will not retry the gateway.

Step 8: Create the n8n reject workflow

Verify the signature, tell the agent or the customer the refund was declined, and log the outcome. Do not run the statement and do not call the payment gateway.

A practical example

An agent proposes a refund above the threshold. n8n sends the statement to Guard and receives needs_approval. Claix posts the SQL in Slack. The finance lead clicks Approve. Claix calls the approve webhook, which verifies the signature, writes the refund row in Supabase and calls the payment gateway. If the lead clicks Reject, the reject webhook tells the agent the refund was declined and stops there.

What the approve endpoint receives

{
  "approval_id": "7d8e9f0a-1b2c-4d3e-8f90-a1b2c3d4e5f6",
  "decision": "approved",
  "statement_hash": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
  "timestamp": "1763726400",
  "approver": "U0123456789"
}

The body includes decision, approval_id, statement_hash, timestamp and approver, the Slack user who clicked. X-Claix-Signature is an HMAC-SHA256 of that body. The SQL is included only if you turn the option on. Verify the signature before you write or charge anything. An expired approval is delivered as denied. A second click is told the decision was already made.

Security practices

PracticeWhy it matters
Keep write credentials in the executorPrevents the agent from bypassing Guard
Use a dedicated Slack channelLimits who can see proposed SQL
Validate the 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

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. It can then bypass Guard.
  • Treating Approve as execution. The click only calls your webhook.
  • Using one Slack channel for every alert, including the SQL.
  • Sending every refund to approval. If they are all accepted, use an allowed rule with a limit.
  • Skipping the audit log of what was proposed, decided and actually charged.

How to get started

  • Create a policy and write the refund rules in plain English.
  • Review and approve the proposed exact rules.
  • Test the policy in the Sandbox, including refunds that should be denied.
  • Call Guard before every refund write.
  • Execute the statement and call the gateway only when the response is allowed, or after a signed approval.

Conclusion

Refunds need more than a prompt. Allowed covers refunds inside your limits. Needs approval covers refunds above a threshold. Denied covers refunds nobody should be able to issue. n8n, Supabase and the payment gateway automate the safe cases and send the risky ones to a person. Claix never executes SQL and never calls the gateway. Your endpoint does.