Private Ollama Chat Assistant with Structured LLM Response - n8n Workflow

Learn how to deploy a self-hosted AI assistant using this n8n workflow, leveraging the Ollama n8n node and LangChain integration to ensure structured JSON output from Llama 3.2.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Users interested in leveraging self-hosted, private Large Language Models (LLMs) like Llama 3.
Automation specialists looking for advanced n8n templates for AI integration.
Developers requiring reliable, structured (JSON) output from an AI model.
Anyone needing a robust, local n8n workflow for chat applications.

Overview

This comprehensive n8n workflow demonstrates how to create a highly efficient, private AI chat assistant using the self-hosted Ollama platform. The primary challenge solved by this n8n template is ensuring that the LLM's response is consistently formatted as a parsable JSON object, crucial for downstream automation tasks.

By utilizing the LangChain n8n node in conjunction with the Ollama n8n node, this automation guarantees that every chat message received by the n8n trigger is processed by a specific model (Llama 3.2 in this case) and returned in a predetermined format. This powerful setup is ideal for businesses and individuals prioritizing data privacy and requiring predictable data structures from their AI interactions. This specific n8n workflow is a perfect starting point for building sophisticated, localized AI services.

How it Works

This powerful n8n workflow begins when the When chat message received n8n trigger initiates the process upon receiving a new chat input from a user.


  1. Trigger and Input: The workflow starts with the dedicated chat n8n trigger, capturing the user's prompt (chatInput).

  2. LLM Processing Chain: The input is passed immediately to the Basic LLM Chain n8n node. This node is configured with a strict prompt instruction, commanding the underlying AI model to format its output as a JSON object containing 'Prompt' and 'Response' fields. This ensures structured output, which is a core feature of this n8n workflow.

  3. Model Execution: The chain leverages the Ollama Model n8n node, which connects to your local Ollama instance and executes the query using the llama3.2:latest model.

  4. Data Structuring: The raw text output from the LLM Chain (expected to be a JSON string) flows into the JSON to Object n8n node. This essential n8n node converts the string into a usable JSON object, making the data easily accessible for final display.

  5. Structured Output: The Structured Response n8n node formats the final output for the user, clearly displaying both the original prompt and the AI's response, making this a transparent and useful n8n workflow.

  6. Error Handling (Fail-Safe): If the Basic LLM Chain encounters an error (e.g., model failure, connection issue), the execution branches to the Error Response n8n node, ensuring a graceful failure message is returned instead of hanging the conversation.

Installation Guide

To deploy this specialized n8n workflow, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON data and paste it directly into your n8n instance using the 'New' -> 'Import from JSON' function.

  2. Ollama Setup: Ensure you have Ollama installed and running locally, and that the specified model (llama3.2:latest) is pulled and available.

  3. Credential Configuration: Navigate to the Ollama Model n8n node. You must set up a new Ollama API credential, providing the necessary URL and access details to connect n8n to your local Ollama server.

  4. Activate the Trigger: The When chat message received n8n trigger will automatically be active once the workflow is saved. You can test the n8n workflow by sending a message to the generated webhook URL or integrating it into an existing chat application.

  5. Test Execution: Run a test execution to confirm that the Basic LLM Chain successfully interacts with the Ollama n8n node and returns a structured response.

Node Details

This n8n workflow utilizes several key n8n nodes for LLM integration and data manipulation:

When chat message received (Chat Trigger n8n Trigger):
Function: Acts as the starting point, initiating the entire n8n workflow upon receiving a chat message.
Key Configuration: Listens for incoming chat payloads, feeding the chatInput into the next stage.

Basic LLM Chain (LangChain n8n Node):
Function: Orchestrates the AI prompt processing. It uses a custom system prompt to force the LLM to output a JSON string, guaranteeing structure for this n8n workflow.
Key Configuration: Custom prompt definition requesting JSON output. onError is set to 'continueErrorOutput' for robust error handling.

Ollama Model (LangChain Ollama n8n Node):
Function: Connects the n8n workflow to the local Ollama instance, providing the computation power of the LLM.
Key Configuration: Model specified as llama3.2:latest. Requires valid Ollama API credentials.

JSON to Object (Set n8n Node):
Function: Converts the raw JSON string output from the LLM into a structured n8n data object, named response.
Key Configuration: Mapping the incoming text field to a new object field named response using expression {{ $json.text }}.

Structured Response (Set n8n Node):
Function: Formats and finalizes the human-readable output based on the parsed JSON data, completing the n8n workflow cycle.
* Key Configuration: Uses expressions like {{ $json.response.Prompt }} and {{ $json.response.Response }} to create a clean, informative reply.

Related n8n Workflows

Free

Nodes: 5 Nodes
Updated: December 26 2025
View all
Created by
Joseph LePage
Joseph LePage

As an AI Automation consultant based in Canada, I partner with forward-thinking organizations to implement AI solutions that streamline operations and drive growth.

Featured*