n8n workflow automation with retries, logging, and review queues
PURPOSE
Designs and outputs n8n workflow JSON with robust triggers, idempotency, error handling, logging, retries, and human-in-the-loop review queues.
WHEN TO USE
- Build an n8n workflow that runs every Monday and emails the compliance summary.
- Add error handling and retries to this workflow, plus a review queue for failures.
- Create a webhook workflow that logs every run and writes a status row to a tracker.
- Make this n8n flow idempotent so it does not duplicate records when it reruns.
- Instrument this workflow with audit logs and a human approval step.
- You need code-only automation without n8n (use a scripting/CI skill).
- You need to bypass security controls or hide audit trails.
- You need to purchase or recommend prohibited items/services.
INPUTS
- Workflow intent: trigger type + schedule/timezone + success criteria.
- Targets: where to write results (email/Drive/Sheet/DB) and required fields.
- Existing n8n workflow JSON to modify.
- Sample payloads / example records.
- Definition of dedup keys (what makes a record unique).
- Cron: Monday 08:00 Europe/London; send summary email + Drive upload
- Webhook: receive JSON; route to folders
OUTPUTS
- - Default (read-only): a workflow design spec (nodes, data contracts, failure modes).
- If explicitly requested:
workflow.json (n8n importable JSON) + runbook.md (from template).
Success = workflow is idempotent, logs every run, retries safely, and routes failures to a review queue.
WORKFLOW
- 1. Clarify trigger:
- Cron/webhook/manual; schedule/timezone; concurrency expectations.
- 2. Define data contract:
- input schema, required fields, and validation rules.
- 3. Design idempotency:
- choose dedup key(s) and storage (DB/Sheet) to prevent duplicates on retries.
- 4. Add observability:
- generate
run_id, log start/end, store status row and error details.
- 5. Implement error handling:
- per-node error branches, retry with backoff, and final failure notification.
- 6. Add human-in-the-loop (HITL) review queue:
- write failed items to a queue (Sheet/DB) and require approval to reprocess.
- 7. “No silent failure” gates:
- if counts/thresholds fail, stop workflow and alert.
- 8. Output:
- If asked for JSON: produce importable n8n workflow JSON + runbook.
- 9. STOP AND ASK THE USER if:
- destination systems are unknown,
- no dedup key exists,
- credential strategy (env vars) is not specified,
- the workflow needs privileged access not yet approved.
OUTPUT FORMAT
If outputting
n8n workflow JSON, conform to:
CODEBLOCK0
Also output runbook.md using assets/runbook-template.md.
SAFETY & EDGE CASES
- - Read-only by default; only emit workflow JSON when explicitly requested.
- Do not include secrets in JSON; reference env vars/credential names only.
- Include audit logging + failure notifications; avoid workflows that can silently drop data.
- Prefer least privilege: call only required APIs and minimize scopes.
EXAMPLES
- - Input: “Cron every Monday, email compliance summary, retry failures.”
Output: Node map +
workflow.json with Cron → Fetch → Aggregate → Email, plus error branches to review queue.
- - Input: “Webhook that logs runs and writes status row.”
Output: Webhook → Validate → Process → Append status row; on error → log + notify + queue.
带重试、日志和审核队列的n8n工作流自动化
目的
设计并输出具有稳健触发器、幂等性、错误处理、日志记录、重试机制以及人工审核队列的n8n工作流JSON。
使用场景
- 构建一个每周一运行并发送合规摘要邮件的n8n工作流。
- 为此工作流添加错误处理和重试机制,以及用于处理失败的审核队列。
- 创建一个记录每次运行并将状态行写入追踪器的Webhook工作流。
- 使此n8n流程具有幂等性,避免重新运行时产生重复记录。
- 为此工作流配置审计日志和人工审批步骤。
- 需要纯代码自动化而不使用n8n(请使用脚本/CI技能)。
- 需要绕过安全控制或隐藏审计轨迹。
- 需要购买或推荐违禁物品/服务。
输入
- 工作流意图:触发器类型 + 计划/时区 + 成功标准。
- 目标:结果写入位置(邮件/Drive/表格/数据库)及必需字段。
- 待修改的现有n8n工作流JSON。
- 示例负载/示例记录。
- 去重键定义(记录唯一性的判断依据)。
- Cron:周一08:00 欧洲/伦敦;发送摘要邮件 + Drive上传
- Webhook:接收JSON;路由到文件夹
输出
- - 默认(只读):工作流设计规范(节点、数据契约、故障模式)。
- 如明确要求:workflow.json(可导入n8n的JSON)+ runbook.md(基于模板)。
成功标准 = 工作流具有幂等性、记录每次运行、安全重试、将失败路由到审核队列。
工作流程
- 1. 明确触发器:
- Cron/Webhook/手动;计划/时区;并发预期。
- 2. 定义数据契约:
- 输入模式、必需字段和验证规则。
- 3. 设计幂等性:
- 选择去重键和存储方式(数据库/表格),防止重试时产生重复。
- 4. 添加可观测性:
- 生成run_id,记录开始/结束,存储状态行和错误详情。
- 5. 实现错误处理:
- 每个节点的错误分支、带退避的重试机制,以及最终失败通知。
- 6. 添加人工审核队列:
- 将失败项写入队列(表格/数据库),需要审批才能重新处理。
- 7. 无静默失败门控:
- 如果计数/阈值失败,停止工作流并发出警报。
- 8. 输出:
- 如果要求JSON:生成可导入的n8n工作流JSON + runbook。
- 9. 遇到以下情况停止并向用户询问:
- 目标系统未知,
- 不存在去重键,
- 未指定凭证策略(环境变量),
- 工作流需要尚未批准的权限访问。
输出格式
如果输出
n8n工作流JSON,需符合以下格式:
json
{
name: <工作流名称>,
nodes: [ { name: 触发器, type: n8n-nodes-base.cron, parameters: {}, position: [0,0] } ],
connections: {},
settings: {},
active: false
}
同时使用assets/runbook-template.md输出runbook.md。
安全与边界情况
- - 默认只读;仅在明确要求时输出工作流JSON。
- JSON中不包含密钥;仅引用环境变量/凭证名称。
- 包含审计日志和失败通知;避免可能静默丢失数据的工作流。
- 优先最小权限原则:仅调用所需API并最小化作用域。
示例
- - 输入:每周一Cron,发送合规摘要邮件,重试失败项。
输出:节点映射 + 包含Cron→获取→聚合→邮件的工作流JSON,以及指向审核队列的错误分支。
输出:Webhook→验证→处理→追加状态行;出错时→记录+通知+入队。