Quick overview
This workflow applies a demo refund policy, asks an AI agent to explain the decision, and saves the case and the final decision as custom execution data so you can find the run later. It is Exercise 2 from the n8n Production AI Playbook on Audit & Trace.
How it works
- Receives a POST webhook request with an orderId, customerTier and message.
- Order Lookup returns a simulated order record.
- Policy Decision, an Edit Fields node, selects refund_approved, refund_declined or needs_human_review from the record.
- Check Tag Length, an If node, sends values over 255 characters to Reject Oversized Tag, a Stop and Error node.
- Tag Execution, an Execution Data node, saves the case details as custom data.
- Refund Support Agent explains the decision using an OpenRouter chat model.
- Record Decision saves the final decision as custom data, and Build Reply returns the response.
Setup
- Add an OpenRouter API credential to OpenRouter - Support. The template uses openai/gpt-4.1-mini, and any supported chat model works.
- Select Execute workflow and POST {"orderId":"ORD-1001","customerTier":"gold","message":"Please refund this order."} to the Webhook Test URL.
- Repeat with ORD-1002 and ORD-9999, selecting Execute workflow before each request. The decisions should be refund_approved, refund_declined and needs_human_review.
- Open each saved execution to inspect the custom data. Filtering the executions list by custom data requires n8n Cloud Pro or Enterprise.
Requirements
- n8n Cloud or a self-hosted n8n instance
- An OpenRouter API key
- n8n Cloud Pro or Enterprise to filter executions by custom data (optional)
Customization
- Replace Order Lookup with your own order API and change the Policy Decision expression to match your refund policy.
Additional info
All order records are synthetic and no payment is processed.