Skip to main content
Workflow Automationn8nAI workflowtutorial

Build Your First AI Workflow with n8n: A Practical Guide

A step-by-step guide to building your first AI-powered automation workflow in n8n, from setup to deployment, with real business examples.

Gerard Buscombe· Founder & AI Consultant, IOTAI26 February 20266 min read

n8n is one of the most capable workflow automation platforms available, and its AI capabilities have matured significantly over the past year. If you have been wanting to build an AI-powered workflow but were not sure where to start, this guide walks through the process from setup to a working automation.

We will build a practical workflow that most businesses can use immediately: an intelligent email classifier that reads incoming messages, categorises them by type and urgency, and routes them to the right person or system.

What You Need

n8n instance. Either n8n Cloud (easiest to start) or a self-hosted installation. For this guide, n8n Cloud is fine.

An AI API key. OpenAI, Anthropic, or Google AI. Any of these work with n8n's AI nodes. We will use OpenAI in this example, but the concepts apply to any provider.

An email account. Gmail, Outlook, or any IMAP-compatible email service.

Step 1: Set Up the Trigger

Every workflow starts with a trigger. For our email classifier, we will use the Email Trigger node.

In n8n, create a new workflow and add an IMAP Email trigger node. Configure it with your email credentials and set it to check for new emails. You can filter by a specific folder or label if you do not want to process every incoming email.

The trigger will fire each time a new email arrives, passing the subject, body, sender, and metadata to the next node.

Step 2: Add the AI Classification Node

Add an AI Agent node after the trigger. This is where the intelligence happens.

Configure the node with your AI API credentials, then set up the prompt. For email classification, a prompt like this works well:

"Analyse the following email and return a JSON response with three fields: category (one of: inquiry, support, billing, partnership, spam), urgency (high, medium, low), and summary (one sentence describing the email's purpose). Base urgency on how time-sensitive the request appears."

Pass the email subject and body as input to the prompt. The AI node will return structured data that downstream nodes can act on.

Step 3: Parse the AI Response

Add a Code node to parse the AI response into usable fields. This handles cases where the AI returns slightly different formatting and ensures your downstream routing works reliably.

The code node should extract the category, urgency, and summary fields from the AI response. Add basic validation to handle edge cases, such as defaulting to medium urgency if the AI returns an unexpected value.

Step 4: Route Based on Classification

Add a Switch node that routes emails based on the category field:

  • Inquiry emails go to the sales team via Slack or email notification
  • Support requests create tickets in your support system
  • Billing questions route to the finance team
  • Partnership proposals go to a specific inbox or CRM
  • Spam gets logged and ignored

Each branch of the switch connects to the appropriate action node. For Slack notifications, use the Slack node. For ticket creation, connect to your support platform's API.

Step 5: Add the Urgency Layer

For high-urgency items, add a second routing layer. After the category switch, add an IF node that checks whether urgency equals high. High-urgency items get an additional immediate notification, such as a direct Slack message to the relevant team lead or an SMS alert.

This two-layer routing ensures that urgent support requests get immediate attention while routine enquiries follow the standard process.

Step 6: Log Everything

Add a Google Sheets or database node at the end of each branch to log every processed email. Record the original email details, the AI classification, the routing decision, and a timestamp.

This logging serves two purposes. First, it creates an audit trail showing how each email was handled. Second, it gives you data to evaluate the AI's classification accuracy over time. If the model consistently miscategorises certain email types, you can refine the prompt accordingly.

Testing Your Workflow

Before activating the workflow, test it with sample emails:

  • Send yourself test emails that represent each category
  • Use n8n's manual execution to process them
  • Verify the classification is correct and the routing goes to the right destination
  • Test edge cases like emails in multiple categories or emails with ambiguous urgency
  • Adjust the AI prompt based on what you observe. Small changes to the prompt wording often resolve classification issues.

    Taking It Further

    Once your basic classifier is working, consider these enhancements:

    Auto-drafting responses. Add an AI node after classification that drafts a response based on the email category. Support emails get a templated acknowledgement with relevant FAQ links. Enquiries get a personalised response based on the sender's history.

    CRM integration. Look up the sender in your CRM and enrich the classification with customer context. A billing question from your largest client might warrant different routing than one from a new prospect.

    Sentiment analysis. Add a sentiment check to detect frustrated or unhappy customers, routing them to senior staff regardless of the email category.

    Common Pitfalls

    Overly complex prompts. Start simple and add complexity only when needed. A clear, concise prompt usually performs better than a lengthy one trying to cover every edge case.

    No error handling. AI API calls can fail. Add error handling nodes that route to a fallback, such as forwarding the email to a general inbox when classification fails.

    Skipping the logging. Without logging, you cannot measure accuracy or debug issues. Always log AI decisions.

    What Comes Next

    If this is your first n8n workflow, the email classifier is a strong foundation. Once you are comfortable with the trigger-process-route pattern, the same approach applies to document processing, customer onboarding, invoice handling, and dozens of other business processes.

    If you want help designing more complex workflows or need guidance on which processes to automate first, our automation readiness assessment identifies the highest-impact opportunities in your operations. For hands-on implementation support, book a consultation with our team.

    The best automation starts with a single working workflow. Build it, refine it, then expand.

    Gerard Buscombe

    Founder & AI Consultant, IOTAI

    IOTAI is Australia's leading AI consultancy and Managed Intelligence Provider, specialising in Retool, n8n, and AI agent development for SMEs.

    Ready to Implement These Strategies?

    Our AI consultants can help you put these insights into action with tailored automation solutions for your business.