n8n Ollama Local AI: Verify Private Document Triage
Build an n8n Ollama local AI workflow for private document triage, with Docker networking, schema-checked JSON, visible failures, and security checks.
An n8n Ollama local AI workflow sends document text from an n8n trigger to a model that runs through Ollama. It checks the response, then routes the result. The document does not need to reach a hosted AI API. This guide covers private document triage, networking, output checks, failure handling, and privacy limits. “Local” means inference runs on infrastructure you control. It does not automatically protect n8n execution data, logs, backups, open ports, or connected services.
What you’ll build—and when it helps
You’ll build a workflow that extracts document text, prepares a prompt, calls Ollama, checks the result, and sends it to the right route. This works well for narrow tasks such as invoice, support-request, and contract-notice triage.
The workflow follows this path:
Trigger or document extractor → prompt preparation → Ollama chat or language-model node → structured-output parsing → field validation → success or review route → database, ticket, email, or queue.
The model can return fields such as category, priority, summary, needs_human_review, and reason. n8n can then route the item from checked fields instead of interpreting free-form model text later.
Use this setup when a local model can handle the task and the document should stay on a workstation, server, or private network. A smaller model can suit classification when privacy, offline operation, or local cost control matter more than maximum reasoning quality. Local inference does not equal a hosted model. Test the selected model with representative documents first.
Privacy ends at the edges of your deployment. n8n may store prompts and outputs in execution history. OCR, email, proxy, database, notification, backup, and other connected services may also see the data. A successful local response proves only that inference worked.
Protect both services. Bind or firewall Ollama so the public internet cannot reach it. Require authentication at any proxy, restrict n8n access, and choose an execution-data retention period. Keep credentials out of prompts. Send only a trimmed excerpt when that is enough.
Prerequisites: runtime, hardware, model, and n8n
Before you build, confirm that your runtime, hardware, model, document source, and n8n permissions are ready. The model must fit the task and the available memory. Your network setup also depends on whether n8n and Ollama share a host, container network, or private machine.
Check these items:
- A supported operating system for n8n and Ollama, with current installation instructions from the official project documentation.
- n8n permission to create credentials and workflows.
- Ollama installed and running, with enough disk space and memory for the selected model.
- A model whose license, context support, structured-output behavior, and hardware requirements fit the task. Check the current Ollama library and model documentation. Do not treat older model names or hardware claims as universal.
- A document source, such as a webhook, email trigger, file trigger, or document-extraction step.
- Docker and Docker Compose only if you plan to run n8n, Ollama, or both in containers.
GPU acceleration is optional. A CPU-only machine can run a small model, but inference may be slower. Plan shorter prompts, lower concurrency, and a timeout that fits the hardware. A larger model may need more memory and more time for its first response while its weights load.
| Setup | Ollama address from n8n | Main trade-off |
|---|---|---|
| n8n and Ollama on the host | http://127.0.0.1:11434 | Simplest local test |
| n8n in Docker, Ollama on the host | A correctly configured host-gateway address | Requires host access configuration |
| Both in Docker Compose | The Ollama service name and port | Shared network is predictable |
| Separate machines | The Ollama machine’s private IP or protected DNS name | Firewall and authentication matter |
A container’s localhost points to that container. Therefore, localhost inside n8n does not point to the host running Ollama. Docker Desktop may provide a host-gateway name. On Linux, Docker host-gateway configuration may be needed. The exact setting depends on the operating system and Compose setup, so check current Docker documentation.
Choose the n8n integration for the job
Choose the integration that matches the job and your installed n8n version. Node names, credential options, and Ollama support can change. Check the current official n8n and Ollama documentation before production use.
- Chat: Use an Ollama chat-model connection for a conversational prompt and response.
- One controlled prompt: Use a Basic LLM Chain for fixed document classification.
- Structured output: Use a Structured Output Parser when the selected chain supports it. Then check types, required fields, and allowed values. Parsing does not remove the need for a failure route.
- Embeddings: Use embeddings for vector search and retrieval. They cannot replace classification by themselves.
- Agents: Use an AI Agent when the model needs to choose tools or make multi-step decisions. Agents add moving parts, so check their final output before side effects.
For fixed document triage, start with a chat-model step or Basic LLM Chain. It is easier to inspect than an agent. It also makes the input, output schema, and failure path clear.
Install Ollama and connect it to n8n
Install and verify Ollama before adding document parsing. This separates service and network problems from workflow problems. First confirm the API, model, direct inference, and n8n connection. Then build the document workflow.
- Install Ollama using the current official instructions for your operating system. Confirm that its service is running.
- Check that the local API responds.
curl http://127.0.0.1:11434/api/tagsA response listing models means the API answered. A refusal may mean Ollama is stopped, listening elsewhere, blocked by a firewall, or using the wrong URL. This is not yet a model-selection problem.
- Download a model that fits available memory and supports the task. Follow the model’s current Ollama instructions.
ollama pull <model-name>
ollama listReplace <model-name> with the exact identifier you selected. Confirm that it appears in ollama list.
- Make one direct inference request.
ollama run <model-name>Enter a short test sentence and confirm that a response arrives. The first request may take longer while the model loads. That differs from a missing-model error.
- Configure n8n to use the endpoint from its actual runtime. Use http://127.0.0.1:11434 when n8n runs directly on the same host. Use the Ollama Compose service name when both services share a Docker network. If n8n runs in Docker and Ollama runs on the host, configure the host gateway required by your operating system and Docker setup.
- Create the current Ollama credential in n8n, if your version provides one. Otherwise, use an HTTP Request node with the Ollama base URL. Select the exact identifier shown by ollama list.
- Run a minimal n8n test with one short prompt. A refused connection points to reachability. An unavailable-model error points to the model name or Ollama installation. Fix that distinction before adding extraction.
The checkpoint is a successful short response from n8n, not merely a green node. Inspect the output and confirm that the request reached the intended Ollama service.
Build the document-triage workflow
Build the workflow in checkpoints. First prove that one short item can reach Ollama and return valid data. Then add document extraction, routing, long-input handling, deliberate failures, and privacy checks.
- Add a trigger and provide one test item with a text field. Keep the first document short enough to fit comfortably within the selected model’s context.
- Add a Set or Edit Fields node that creates the prompt. Tell the model to classify only the supplied text, return no Markdown, and use the exact JSON keys you expect. List allowed category and priority values. State what to do when the text lacks enough evidence.
- Add the Ollama chat-model or language-model node supported by your n8n version. Choose the exact model identifier from ollama list. Use low or zero temperature when repeatability matters. Set a timeout that fits the hardware.
- Add a Structured Output Parser if the selected chain supports it. Otherwise, parse the returned text in a Code or validation step. Require fields such as category, priority, summary, needs_human_review, and reason. Check required fields, types, and allowed values. Reject malformed JSON and extra text before any later side-effecting node.
- Add an IF or Switch node. Send valid records to a database, queue, or notification. Send parse failures, missing fields, model errors, and timeouts to a visible review branch. Record the original item, error details, and a safe status there.
- Run the workflow with ordinary text. The expected result is a parsed object with the required fields, followed by the intended route. Inspect the object and execution path. Do not treat a green node as proof of correctness.
- Run the workflow with a long document. If it approaches the context limit, trim, chunk, or summarize it before classification. Large prompts compete with context and local memory. Reducing the input may help more than changing an n8n setting.
- Test failures deliberately: stop Ollama, use a wrong model name, force a short timeout, and provide text that does not support a confident category. Each case should reach an observable error or human-review branch. Avoid blind retries around database writes, notifications, or other actions that could create duplicates.
- Inspect n8n execution data, container logs, Ollama logs, proxy access logs, outbound firewall rules, and OCR or notification nodes. Confirm that no fallback credential sends the document to a hosted model.
The workflow is complete when a normal item produces schema-checked JSON and reaches its destination. Unavailable-model, timeout, context, and malformed-output tests must reach controlled failure handling.
Troubleshoot the first failing boundary
Test one boundary at a time. Start with the Ollama API, then test the same URL from the n8n runtime, the model identifier, and the response parser. This keeps network, model, and JSON problems separate.
- A connection refusal or timeout usually points to the address, listener, firewall, container route, or service state. From Docker, localhost means the n8n container. Use the Ollama Compose service name on a shared network, or configure the correct host gateway for a host installation.
- A missing-model error means the identifier in n8n does not match an installed model. Compare it with ollama list; similar tags are not automatically interchangeable.
- A slow first request may reflect model loading. Use a realistic timeout and controlled failure or retry policy. Avoid retries around non-idempotent side effects.
- A context error may mean that the document, prompt, output allowance, or model context setting is too large. Trim, chunk, or summarize the input. Check the model’s current context support.
- JSON parsing failures can result from Markdown fences, commentary, truncated output, or invalid enum values. Tighten the prompt, use structured-output support where available, validate the raw response, and route failures for review. The exact message varies by n8n node and model.
- Slow CPU inference on a VPS may be a capacity constraint, not an n8n defect. Reduce model size and concurrency, shorten inputs, or move inference to a suitable private machine.
When privacy or offline operation matters most, choose a smaller local model for a narrow task. Choose a hosted model when your hardware cannot provide the needed capabilities and your data policy allows external processing. A hybrid n8n workflow can keep the original document under your control, classify or redact it locally, and send only approved fields to a hosted model.
Check current official n8n, Ollama, Docker, operating-system, and model documentation before changing production settings, prices, model availability, supported nodes, or security configuration.
Conclusion
Start with a direct Ollama API check. Then make n8n reach that endpoint from its actual runtime. After a short prompt works, add schema validation and a visible review route. Do this before connecting sensitive documents or irreversible actions. This order separates network, model, workflow, and privacy problems.
Frequently Asked Questions
Can I use Ollama with n8n when n8n runs in Docker?
Yes. The address depends on where Ollama runs. For two Compose services, use the Ollama service name. For Ollama on the host, configure the Docker host gateway required by your operating system. Do not use localhost casually: inside the n8n container, it points back to n8n itself.
Does a local n8n Ollama workflow guarantee privacy?
No. It can keep inference on infrastructure you control, but execution history, logs, proxies, databases, OCR tools, notifications, backups, and open ports may still reveal data. Inspect those paths. Restrict unnecessary retention and network access.
Should I use an AI Agent or a Basic LLM Chain for document triage?
Start with a Basic LLM Chain or chat-model step for fixed classification. It is easier to validate and troubleshoot. Use an AI Agent only when the workflow needs tool selection or multi-step decisions. Check the agent’s output before taking side effects.