ARTIFACT // N8N-LOCAL-INVOICE-EXTRACTOR.JSON (JSON)
n8n Local Invoice & Contract Structured Extractor with Math Reconciliation (n8n-local-invoice-extractor.json)
Extracts vendor, date, line items, and totals into strict JSON, then runs a deterministic JavaScript math check (subtotal + tax == total) before database insert.
[KEY VERIFIED TAKEAWAY / TL;DR]This reproducible configuration artifact "n8n Local Invoice & Contract Structured Extractor with Math Reconciliation" (n8n-local-invoice-extractor.json, JSON) is paired with Tinker AI Lab's hardware-verified guide "n8n-pdf-invoice-structured-extractor". It exposes 2 customizable browser variables (INVOICE_MODEL=qwen2.5:14b, OLLAMA_API_URL=http://host.docker.internal:11434) with loopback-first security defaults.
02 // WORKFLOWNo-Code AI Workflows· Verified: 2026-10-23
Browse All 42 Artifacts →n8n-local-invoice-extractor.json
View Paired Guide →n8n Local Invoice & Contract Structured Extractor with Math Reconciliation
Extracts vendor, date, line items, and totals into strict JSON, then runs a deterministic JavaScript math check (subtotal + tax == total) before database insert.
Customizable Variables (Saved in Browser)
UTF-8 Encoded · Live Client-Side Compilation
{
"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 // 参数化变量规范说明表
Customizable Parameter Reference for n8n-local-invoice-extractor.json
This JSON artifact exposes 2 template variables compiled client-side in your browser.
| Template Token | Parameter Description | Verified Default | Example Format |
|---|---|---|---|
{{INVOICE_MODEL}} | Local Extraction Model | qwen2.5:14b | qwen2.5:14b |
{{OLLAMA_API_URL}} | Ollama Base URL | http://host.docker.internal:11434 | http://host.docker.internal:11434 |
PAIRED HARDWARE MANIFEST // 配套实测环境与边界记录
Verified Environment for "n8n + Local LLM Invoice & Contract Extractor: JSON Schema Guard & Deterministic Math Reconciliation"
Tested Hardware & OS
Docker n8n 1.76+ · Local Ollama (Qwen2.5-14B-Instruct Q4_K_M / Q5_K_M)
Pinned Stack & Model Versions
n8n 1.76.xOllama 0.5.7qwen2.5:14b-instruct
Offline Boundary (100% On-Premise Financial Document Privacy)
All PDF text extraction, LLM JSON parsing, and math reconciliation execute inside your local LAN.
Known Operational Limits & Failure Modes
- Scanned image-only PDFs contain zero selectable text layer; you must pass scanned images through OCR (e.g. PaddleOCR / Tesseract) or a Vision-Language Model (`qwen2.5-vl` / `gemma3`) first.
- LLMs occasionally misread OCR decimal points (`1,080.00` vs `108.00`); never insert LLM-extracted financial numbers into an ERP database without a deterministic math reconciliation check.
DEPLOYMENT CHECKLIST // 配置落地核验步骤
3-Step Verification Checklist After Deploying n8n-local-invoice-extractor.json
- Added pre-check for `rawText.trim().length < 20` to catch scanned image PDFs lacking a text layer.
- Verified deterministic Code node checks `subtotal + taxAmount === totalAmount` before database write.
- Locked LLM extraction options to `"format": "json"` and `"temperature": 0` with unique invoiceNo deduplication.