Information Extraction in n8n
Learn how to use the Information Extractor node in n8n to parse and structure data from incoming messages using AI.
Information Extraction in n8n Tutorial
In this tutorial, you'll discover how to build a powerful workflow in n8n that automatically extracts structured information from unstructured text. Using the Information Extractor node, you can parse incoming messages, like customer emails or support tickets, and convert them into organized JSON data that can be used in downstream applications.
Workflow Overview
The workflow is designed to process incoming chat messages, extract key details, and then route the data based on its content.
- When Chat Message Received - This is the entry trigger that starts the workflow whenever a new chat message arrives.
- Information Extractor - This node, powered by an AI model, parses the message to pull out structured fields like name, email, order number, and the type of query.
- OpenAI Chat Model - The underlying model used by the Information Extractor to understand and structure the text.
- Switch - This node routes the execution to different paths based on the
customer_query_type
extracted from the message.
Information Extractor Node Configuration
The core of this workflow is the Information Extractor node. You configure it with a system prompt and a desired JSON structure.
System Prompt
The system prompt guides the AI model on its role and how to handle the extraction process.
You are an expert extraction algorithm.
Only extract relevant information from the text.
If you do not know the value of an attribute asked to extract, you may omit the attribute's value.
For customer_query_type - Only respond with - complaint| general | refund | order_tracking
Example JSON Structure
You provide an example JSON object to define the schema for the data you want to extract. The model will use this structure as a template for its output.
{
"customer_name": "John Doe",
"customer_email": "john@gmail.com",
"customer_order_no":"OR1234",
"customer_query":"I have some issues with my shoes",
"customer_query_type":"complaint|general|refund|order_tracking"
}
Example Usage
Here’s how the workflow processes an incoming message and transforms it into structured data.
Input Message
"Hello, my name is Jane Doe and my email is jane@example.com. I'm having an issue with my recent order, #OR9876. The shoes I received are the wrong size and I would like to request a refund."
Extracted Data Output
The Information Extractor node will output the following JSON data:
{
"customer_name": "Jane Doe",
"customer_email": "jane@example.com",
"customer_order_no": "OR9876",
"customer_query": "The shoes I received are the wrong size and I would like to request a refund.",
"customer_query_type": "refund"
}
This structured data can then be easily used by the Switch node to route the request to the correct department or trigger another automated workflow.
Key Benefits
- Structured Data: Convert messy, unstructured text into clean, organized JSON.
- Automation: Automate data entry and routing for customer queries, saving manual effort.
- Scalability: Handle a high volume of incoming messages efficiently.
- Accuracy: Leverage powerful AI models for reliable information extraction.
- Flexibility: Easily adapt the JSON structure and system prompt for different use cases.