TinkerLab
ARTIFACT // N8N-LOCAL-INVOICE-EXTRACTOR.JSON (JSON)

n8n + 本地模型发票/合同结构化提取工作流(含金额恒等校验与异常复核分支) (n8n-local-invoice-extractor.json)

通过本地模型提取供应商、明细与税额 JSON,并内置确定性代码节点核验“小计 + 税额 === 总计”,算账不平自动转入人工复核队列。

[核心实测结论 / TL;DR]本配置包「n8n + 本地模型发票/合同结构化提取工作流(含金额恒等校验与异常复核分支)」(文件名:n8n-local-invoice-extractor.json,格式:JSON)是 Tinker AI 实测工坊配套指南《n8n-pdf-invoice-structured-extractor》的参数化生产模板。支持在本地浏览器实时定制 本地提取模型名称 (INVOICE_MODEL=qwen2.5:14b)、Ollama 接口地址 (OLLAMA_API_URL=http://host.docker.internal:11434) 等 2 项核心变量,默认遵循 127.0.0.1 回环绑定与最小权限规范。
02 // WORKFLOW无代码工作流· 验证日期:2026-10-23
查看全部 42 套配置附件 →
n8n-local-invoice-extractor.json

n8n + 本地模型发票/合同结构化提取工作流(含金额恒等校验与异常复核分支)

通过本地模型提取供应商、明细与税额 JSON,并内置确定性代码节点核验“小计 + 税额 === 总计”,算账不平自动转入人工复核队列。

查看配套实测指南 →
参数化定制变量 (Variables — 自动保存在本地浏览器)
UTF-8 编码 · 零延迟实时编译
{
  "name": "Tinker AI — Local Invoice Extractor with Deterministic Math Guard",
  "nodes": [
    {
      "parameters": {},
      "name": "Manual Test Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [200, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://host.docker.internal:11434/api/generate",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'qwen2.5:14b', format: 'json', stream: false, options: { temperature: 0, num_ctx: 8192 }, prompt: 'Extract invoice fields in strict JSON {invoiceNo, vendor, currency, subtotal, taxAmount, totalAmount}: ' + String($json.rawText || '').slice(0, 6000) }) }}",
        "options": { "timeout": 45000 }
      },
      "name": "Local LLM JSON Extractor",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "retryOnFail": true,
      "maxTries": 2,
      "continueOnFail": true,
      "position": [440, 300]
    },
    {
      "parameters": {
        "jsCode": "const parsed = JSON.parse($input.first().json.response || '{}');\nconst sub = Number(parsed.subtotal || 0);\nconst tax = Number(parsed.taxAmount || 0);\nconst total = Number(parsed.totalAmount || 0);\nconst mathValid = Math.abs((sub + tax) - total) < 0.02 && total > 0;\nreturn [{ json: { ...parsed, mathValid, auditStatus: mathValid ? 'VERIFIED' : 'NEEDS_HUMAN_REVIEW' } }];"
      },
      "name": "Deterministic Math Reconciliation",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [680, 300]
    }
  ],
  "connections": {
    "Manual Test Trigger": {
      "main": [[{ "node": "Local LLM JSON Extractor", "type": "main", "index": 0 }]]
    },
    "Local LLM JSON Extractor": {
      "main": [[{ "node": "Deterministic Math Reconciliation", "type": "main", "index": 0 }]]
    }
  }
}
PARAMETER SPECIFICATION // 参数化变量规范说明表

「n8n-local-invoice-extractor.json」可定制环境变量与默认值说明

本配置模板(JSON 格式)支持 2 项运行时参数注入,所有替换均在本地浏览器内完成。

模板占位符参数用途说明安全默认值填写示例
{{INVOICE_MODEL}}本地提取模型名称qwen2.5:14bqwen2.5:14b
{{OLLAMA_API_URL}}Ollama 接口地址http://host.docker.internal:11434http://host.docker.internal:11434
PAIRED HARDWARE MANIFEST // 配套实测环境与边界记录

配套指南《n8n + 本地模型发票与合同提取工作流:JSON 强约束与金额恒等式自动核验》验证基线

实测硬件与操作系统 (Hardware & OS)

Docker n8n 1.76+ · 本地 Ollama(推荐 Qwen2.5-14B-Instruct Q4_K_M 或 Q5_K_M)

锁定软件栈与模型版本 (Pinned Versions)
n8n 1.76.xOllama 0.5.7qwen2.5:14b-instruct
离线与安全边界 (100% 内网闭环(财务发票与合同零外传))

PDF 文本解析、大模型字段提取与金额平衡校验全流程在本地服务器内完成。

已知限制与失败边界 (Known Limits)
  • 纯图片扫描件 PDF 不含原生文字层:若 `Extract From File` 节点提取出的字符数少于 20,必须先路由至本地 OCR(如 PaddleOCR)或视觉模型分支。
  • 大模型不能替代会计恒等式校验:任何由 LLM 提取的金额字段,在写入财务库前必须经过代码节点的确定性加总核对(误差 < 0.01)。
DEPLOYMENT CHECKLIST // 配置落地核验步骤

部署 n8n-local-invoice-extractor.json 后的 3 步验收清单

  1. 已在送入模型前增加 `rawText.trim().length < 20` 判断,自动识别无文字层的纯图片扫描件。
  2. 确认入库前已通过确定性代码节点校验“不含税金额 + 税额 === 总金额”。
  3. 已锁定 `"format": "json"` 与 `"temperature": 0`,并按发票号配置数据库唯一幂等校验。