Over the first three parts we built a private AI platform for a small organisation. In Part 1 we set up Ollama and Open WebUI on a VPS, in Part 2 we added a knowledge base with Docling, and in Part 3 we locked it down.
So far, everything happened because someone typed a question. In this last part we connect n8n to the same local model so it can do some work on its own: triaging the support inbox, and pulling key dates out of contracts as they arrive. The model still runs on our server and no email or contract is sent to an outside AI service.
This is the final post in a four-part series:
- Part 1 - The platform: hardware sizing, Ollama and Open WebUI on a Mac and on a VPS, HTTPS with Caddy.
- Part 2 - A knowledge base: letting the model answer from company documents using Docling.
- Part 3 - Locking it down: the security steps that keep the server out of the exposed-Ollama statistics.
- Part 4 (this post) - Automation: connecting n8n to the local model for real workflows.
Two rules we set first
Before building any workflow, we agreed two rules with the organisation:
- The model drafts, a person decides. Nothing the model writes is sent to a client or saved as final without someone checking it. In the support workflow the model saves a draft, and a person presses send.
- Failures go to a person. If the model’s output doesn’t pass validation, the workflow doesn’t guess. It sends the item to a person with the reason.
A 9B model running on a CPU is good at reading and drafting, but it does make mistakes. These two rules mean a mistake costs someone a minute to fix, not a wrong email to a client.
Step 1: Add n8n to the stack
n8n goes into the same ~/ai-stack/docker-compose.yml, so it can reach Ollama and Docling over the Docker network:
| |
Add the new values to .env:
| |
Some notes on this service:
- N8N_ENCRYPTION_KEY - n8n encrypts the credentials it stores (email passwords, API keys) with this key. If it is lost, the stored credentials can’t be decrypted, so we keep a copy in the organisation’s password manager. It is also in
.env, which is part of the off-box backup from Part 3.- N8N_DIAGNOSTICS_ENABLED=false - Turns off n8n’s anonymous usage telemetry. On a platform whose whole point is keeping data in-house, we didn’t want anything reporting out by default.
- Port binding - The same rule as every other service:
127.0.0.1only.
Step 2: Reach n8n through an SSH tunnel
In Part 1 I said n8n doesn’t get a DNS record. Only two admins use it, so there is no reason to put its login page on the internet. Instead, we open an SSH tunnel from the admin’s laptop:
| |
Then open http://localhost:5678 in the browser on the laptop. The traffic goes through the encrypted SSH connection, the server’s firewall stays at 22, 80 and 443, and anyone without an SSH key can’t even see that n8n exists. When the admin closes the tunnel, the access is gone.
The first time you open n8n it asks you to create the owner account. Do it straight away, like the Open WebUI admin in Part 1.
Note : n8n sets a secure cookie by default. Chrome and Firefox treat http://localhost as a secure context, so this works through the tunnel. Safari doesn’t, and n8n shows a warning about it. Use Chrome or Firefox rather than turning off N8N_SECURE_COOKIE.
Both workflows here start from an email trigger that polls the mailbox, so n8n never needs a public webhook URL.
Step 3: Calling the local model from n8n
n8n has built-in Ollama nodes, but for these workflows we called Ollama’s chat API directly with the HTTP Request node. That gave us two things we needed:
- Structured output - Ollama’s
formatfield takes a JSON schema, and the model’s reply is constrained to match it. The next node gets fields it can use, not a paragraph it has to parse.- Thinking off - Qwen 3.5 is a thinking model. For classification and extraction we set
"think": false, which made each call much faster on the CPU.
From inside the n8n container, Ollama is at http://ollama:11434, the same Docker network address Open WebUI uses. The request looks like this:
| |
temperature: 0 keeps the output consistent, so the same email gets the same classification every time. The reply is in message.content as a JSON string, and a Code node turns it into fields:
| |
Workflow A: Support inbox triage

The organisation’s support mailbox gets a mix of billing questions, technical problems and everything else. Before this workflow, someone had to read each email to decide who should handle it. The flow is:
- Trigger - The Email Trigger (IMAP) node watches the
support@mailbox.- Classify - The local model reads the email and returns the topic, urgency and language as JSON.
- Route - A Switch node sends it down the billing, technical or other path.
- Draft reply - The model writes a reply using the organisation’s tone guide and the policy text for that topic.
- Save as draft - The reply is saved as a draft in the mailbox. It is not sent.
Classify
The schema for the classification step:
| |
With enum in the schema the model can only answer with one of those values, so the Switch node never gets a topic it doesn’t know about. The system prompt describes each topic in a sentence and tells the model that “high” urgency means a service outage or a payment problem, so it doesn’t mark every complaint as urgent.
Draft the reply
For each topic we keep the relevant policy text (refund rules, support hours, escalation contacts) in a Set node, along with a short tone guide. The second model call gets the original email, the policy text and the tone guide, and returns the reply. Then the Microsoft Outlook node saves it as a draft reply in the same thread (the Gmail node has the same operation).
The support team now opens a draft that is usually close to right, edits it if needed, and presses send. For the “other” path we skip the draft and just label the email, because those were too varied for a useful draft.
Note : An email is untrusted input. Someone can write “ignore your instructions and…” in a message, and the model will read it. This is another reason the model only drafts. It has no tools, it can’t send anything, and a person reads every reply before it goes out.
Workflow B: Contract intake
Signed contracts arrive at a contracts@ mailbox as PDF attachments. Someone used to read each one and type the dates into a spreadsheet, and renewals were still missed. This workflow uses Docling from Part 2 to read the PDF and the local model to extract the key terms.
Convert the PDF with Docling
The Email Trigger (IMAP) node has Download Attachments turned on, so the PDF arrives as binary data (attachment_0). An HTTP Request node sends it to Docling on the Docker network:
- Method -
POST- URL -
http://docling:5001/v1/convert/file- Body -
Form-Data, with a field namedfilesof type n8n Binary File, reading fromattachment_0
Docling returns JSON, and the Markdown version of the contract is in document.md_content. Tables and headings survive, which matters for contracts where the term and notice period are often in a schedule table at the end.
Extract the terms
The Markdown goes to the model with this schema:
| |
The system prompt tells the model to use only what is written in the contract, and to return an empty string for a date it can’t find rather than working one out.
Note : Contracts are longer than chat messages. We raised OLLAMA_CONTEXT_LENGTH to 16384 in the compose file for the whole server, instead of setting num_ctx in each request. If requests use different context sizes, Ollama reloads the model to change it, which slows down everyone using Open WebUI at the same time.
Validate before saving
A Code node checks the extracted values before anything is saved:
| |
An IF node on valid splits the flow. Valid contracts go to the next step. Anything that fails goes to a person by email, with the original PDF attached and the list of problems, so they can fill in the details by hand.
Save and remind
Valid contracts are added as a row in the organisation’s contract register, an Excel sheet in their existing Microsoft 365 (the Microsoft Excel 365 node). The contracts were already stored in Microsoft 365, so only the extracted fields go there. The model call and the PDF conversion stay on our server.
A second, small workflow runs every morning on a Schedule Trigger. It reads the register and emails the contract owner when a contract is 60 days before its renewal date, which leaves enough time to act on the notice period.
The whole platform

This is what we ended up running for the team, and which part of the series covers each piece:
- People - Staff use Open WebUI in the browser at
ai.organisationname.com. Admins use an SSH tunnel for n8n. A Mac can run the same stack locally for one person (Part 1).- Edge - One DNS record, Caddy with automatic TLS, the provider firewall and ufw, and key-only SSH with fail2ban (Parts 1 and 3).
- Apps - Open WebUI for chat, knowledge and users. n8n for workflows, reachable only through the tunnel (Parts 1 and 4).
- AI services - Ollama with
qwen3.5:9bandqwen3-embedding:0.6b, and Docling for document conversion (Parts 1 and 2).- Data - ChromaDB and SQLite inside Open WebUI, the n8n volume, snapshots before every update and encrypted off-box backups (Parts 2 and 3).
All of it runs on one 32 GB CPU-only VPS with a fixed monthly cost.
Common issues
- n8n can’t reach Ollama or Docling - Use the service names
http://ollama:11434andhttp://docling:5001.localhostinside the n8n container is the n8n container itself.- The tunnel connects but the page won’t load - Check that something else on the laptop isn’t already using port 5678. Use another local port, for example
-L 15678:127.0.0.1:5678, and openhttp://localhost:15678.- “Your n8n server is configured to use a secure cookie” - You are probably using Safari. Open the tunnel URL in Chrome or Firefox.
- The model returns invalid JSON - Check that
formatcontains the schema andstreamisfalse. With a schema informat, Ollama constrains the reply to it.- Workflows are slow when the team is chatting - Both share the same model on the same CPU. Schedule heavy jobs (like a batch of old contracts) outside office hours.
- Stored credentials stop working after a rebuild -
N8N_ENCRYPTION_KEYchanged. Restore it from.envor the password manager.
Wrapping up
When we started, the organisation wanted ChatGPT for their daily work but couldn’t send their documents to a third party. They now have a private assistant that answers from their own documents with citations, runs on a server they control, is locked down in five layers, and takes care of two jobs that used to be done by hand.
None of the pieces is new on its own. What made it work was sizing the server for the model first, getting the document conversion right before tuning anything else, and treating security as part of the build rather than a step at the end.
Sources : n8n Docker installation, n8n environment variables, n8n HTTP Request node, Ollama chat API, Ollama structured outputs, docling-serve.
