n8n + LLM Gateway
Validate Before the Business Action
n8n + LLM 网关:先验证模型输出,再执行业务动作
A workflow turns model output into actions. Protect that boundary with scoped credentials, strict output validation, idempotency and an explicit error branch.
工作流会把模型输出转成动作。使用受限凭证、严格输出验证、幂等与显式错误分支保护这一边界。
TL;DR
Send workload alias, required capabilities, trace and deadline.
Parse and check schema before any downstream action.
Choose workflow or gateway retry ownership and share a budget.
Deduplicate updates, messages and external calls.
发送工作负载别名、所需能力、调用链与截止时间。
任何下游动作前解析并检查结构定义。
选择工作流或网关重试归属并共享预算。
去重更新、消息与外部调用。
A production workflow path 生产工作流路径
The trigger prepares redacted input and trace context, calls the gateway, validates the response and only then enters the business action node.
Trigger 准备脱敏输入与调用链上下文,调用网关、验证响应,然后才进入业务动作 Node。
Failures take a named branch for retry, compensation, alert or controlled stop. Credentials remain in the platform store, not node text.
故障进入命名分支,执行重试、补偿、告警或受控停止。凭证保存在平台 Store,而不是 Node 文本中。
Workflow stages and controls 工作流阶段与控制
| Stage 阶段 | Best fit 最适合 | Verify before choosing 选择前验证 |
|---|---|---|
| Trigger and input 触发与输入 | Webhook, schedule, queue or event. Webhook、Schedule、Queue 或 Event。 | Authenticate source, redact data and assign idempotency key. 认证来源、脱敏数据并分配 Idempotency 密钥。 |
| Gateway call 网关调用 | Stable endpoint with workload alias and trace. 带工作负载别名与调用链的稳定端点。 | Set deadline, capability flags and one retry owner. 设置截止时间、能力 Flag 与单一重试负责人。 |
| Validation 验证 | Parse strict structured output. 解析严格结构化输出。 | Reject missing, extra or unsafe fields before actions. 动作前拒绝缺失、多余或不安全字段。 |
| Action or error 动作或错误 | Execute idempotent business step or named failure branch. 执行幂等业务步骤或命名故障分支。 | Log outcome, compensate partial work and alert with trace ID. 记录结果、补偿部分工作并用调用链 ID 告警。 |
Workflow hardening checklist 工作流加固检查
Use platform-managed secrets per environment and workflow.
Keep trigger, gateway and downstream deadlines consistent.
Treat model output as untrusted input.
Carry traceparent or a stable correlation ID through every node.
按环境与工作流使用平台管理上游密钥。
保持 Trigger、网关与下游截止时间一致。
把模型输出视为不可信输入。
让 traceparent 或稳定 Correlation ID 贯穿每个 Node。
Test the workflow as a state machine 把工作流当状态机测试
- Replay valid, malformed, delayed and duplicate trigger payloads.
- Inject gateway timeout, 429, partial response and invalid schema.
- Verify no failure can execute the business action twice.
- Exercise compensation, alerting and manual replay with trace evidence.
- 回放有效、异常、延迟与重复 Trigger 请求数据。
- 注入网关超时、429、部分响应与无效结构定义。
- 验证任何故障都不能让业务动作执行两次。
- 演练补偿、告警与带调用链证据的手动重放。
Put a validation gate before side effects 在副作用前设置验证 Gate
The workflow prepares a canonical request, calls the gateway and validates the returned schema. Only a verified result enters an idempotent action. Every other state routes to a controlled error branch with trace evidence.
工作流准备规范请求、调用网关并验证返回结构定义。只有已验证结果进入幂等动作;其他状态都进入带调用链证据的受控错误分支。
Production rule: model output must never directly authorize a destructive or irreversible action.
生产规则:模型输出绝不能直接授权破坏性或不可逆动作。
Use QVeris for governed workflow capabilities 用 QVeris 治理工作流能力
QVeris lets the workflow discover and call external APIs, tools, services and live data. Keep each capability scoped, validated and idempotent, and join it to the gateway request trace.
QVeris 让工作流发现并调用外部 API、工具、服务与实时数据。让每项能力受限、经过验证且幂等,并把它连接到网关请求调用链。
Build an n8n gateway call that can be replayed 构建可重放的 n8n 网关调用
Use an HTTP Request node when a gateway operation is not exposed by a built-in node. Keep the credential in an n8n credential object, not workflow JSON, and emit a compact evidence object after every call so a failed workflow can be diagnosed without exposing prompts or secrets.
当内置 Node 没有暴露网关操作时,可使用 HTTP 请求 Node。凭证应保存在 n8n Credential Object 中,而不是 Workflow JSON;每次调用后输出精简 Evidence Object,便于在不暴露提示词或上游密钥的前提下诊断失败工作流。
Method: POST
URL: {{$env.LLM_GATEWAY_BASE_URL}}/chat/completions
Authentication: Predefined credential type
Headers:
Content-Type: application/json
Body (JSON):
{
"model": "{{$json.model_alias}}",
"messages": "{{$json.messages}}",
"stream": false,
"metadata": {"workflow_id": "{{$workflow.id}}", "execution_id": "{{$execution.id}}"}
}
Output evidence:
{
"request_id": "{{$json.id}}",
"model": "{{$json.model}}",
"usage": "{{$json.usage}}"
}
- Use Continue On Fail only when a following branch classifies the error explicitly.
- Set an execution timeout and cap retries at one layer.
- Test manual execution, scheduled execution, partial input, 429, 5xx, and credential rotation.
- 只有后续分支明确分类错误时才使用 Continue On Fail。
- 设置执行超时,并只在一层控制重试。
- 测试手动、定时、部分输入、429、5xx 与凭证轮换。
Verified implementation reference: n8n HTTP Request node.
实施参考已根据官方资料核验:n8n HTTP 请求 node。
Production Acceptance Checklist for n8n LLM gateway workflown8n LLM Gateway 工作流生产验收清单
For n8n LLM Gateway, a successful hello-world call proves connectivity only. Production acceptance must prove that the framework contract, model behavior, failures, evidence, and rollback remain predictable under the application’s real workflows.
针对“n8n LLM 网关”,Hello World 调用成功只能证明连接。生产验收还必须证明,在应用真实工作流中,框架契约、模型行为、失败处理、证据和回滚都保持可预测。
Version credential isolation, node parameters, item-level inputs, expressions, binary data, retries, workflow execution identity, and replayable outputs. Keep environment-specific secrets outside code, use stable internal model aliases, and document which layer owns transformations, retries, fallbacks, and timeout policy.
版本化凭证隔离、节点参数、Item 级输入、表达式、二进制数据、重试、工作流执行身份和可重放输出。把环境专属密钥放在代码之外,使用稳定内部模型别名,并记录转换、重试、故障切换和超时策略分别由哪一层负责。
To validate n8n LLM Gateway, cover system and user messages, long context, Unicode, streaming, structured output, tools, refusals, usage, cancellation, and provider errors. Store expected event order and required fields instead of checking text equality alone.
验证“n8n LLM 网关”时,覆盖系统与用户消息、长上下文、Unicode、流式、结构化输出、工具、拒绝、用量、取消和供应商错误,保存预期事件顺序与必需字段,而不只比较文本是否相同。
To validate n8n LLM Gateway, test invalid credentials, unknown models, rate limits, slow first token, broken streams, malformed tool arguments, partial output, network loss, duplicate retries, and a provider outage. Confirm errors stay structured and side effects stay bounded.
验证“n8n LLM 网关”时,测试无效凭证、未知模型、限流、首 Token 过慢、流中断、工具参数畸形、部分输出、网络丢失、重复重试和供应商中断,确认错误保持结构化且副作用范围受控。
Before rolling out n8n LLM Gateway, start with a reversible workflow, compare completion quality, latency, cost, and trace coverage, then expand by task class. Define rollback signals, preserve the previous configuration, and assign an owner for drift and incident review.
上线“n8n LLM 网关”前,先选择可逆工作流,比较完成质量、延迟、成本和追踪覆盖,再按任务类别扩大。定义回滚信号,保留原配置,并明确负责漂移与事故复盘的人员。
FAQ
Choose one owner for model retries; use workflow retries only for explicit state transitions.
With a strict schema and a failure branch before actions.
Use stable idempotency keys and deduplication at the downstream system.
选择一层负责模型重试;工作流重试只用于显式状态转换。
在动作前使用严格结构定义与故障分支。
使用稳定 Idempotency 密钥与下游系统去重。