Automation

    n8n Tutorial: Build Your First AI Workflow Step by Step

    A beginner-friendly n8n tutorial that walks through building an AI workflow: trigger, AI step, logic, and output, plus testing and tips for going live.

    8SolveAI Team4 min read

    n8n is a popular workflow automation tool that lets you connect apps, add logic, and use AI, with a visual editor. This n8n tutorial walks through the thinking behind a simple AI workflow, so you can build your first one with confidence.

    We will build a common example: classify incoming enquiries with AI, then route and reply. The interface changes over time, so use this as a guide to the structure rather than a click-by-click manual, and check n8n's documentation for the latest details. If you are still choosing a tool, read our comparison of n8n, Zapier, and Make.

    What you need

    • An n8n instance (n8n's cloud service or a self-hosted setup)
    • Access to the apps you want to connect, such as Gmail or Google Sheets
    • An API key for an AI provider, such as OpenAI or Anthropic
    • A clear goal for the workflow

    The goal

    Every time someone submits a contact form:

    1. Read the message
    2. Use AI to decide what it is about (sales, support, or other) and draft a short reply
    3. Save the result in a spreadsheet or CRM
    4. Notify the right person

    Step 1: Add a trigger

    Every workflow starts with a trigger, the event that starts it. Options include:

    • A Webhook node, which receives data from your website form
    • A Schedule node, which runs at set times
    • An app trigger, such as "new email in Gmail"

    For this example, use a webhook. Your form sends the name, email, and message to the webhook address. Test it by submitting a sample message so n8n can see the data structure.

    Step 2: Add the AI step

    Add a node that calls your AI model, such as an OpenAI or an AI agent node. Give it clear instructions (a prompt), for example:

    You are an assistant for a software company. Read the message below. Reply with JSON containing: category (sales, support, or other), a one-sentence summary, and a short, polite draft reply. Message: [the message from the form]

    Tips for reliable results:

    • Ask for a fixed format, such as JSON, so later steps can use the output.
    • Be specific about the categories and tone.
    • Keep the prompt short and clear. For more on writing good instructions, see our guide to chatbot prompt design.

    Step 3: Add logic

    Use an IF or Switch node to branch based on the category. For example:

    • If category is "sales", notify the sales team
    • If category is "support", create a support ticket
    • Otherwise, send to a general inbox

    Branching turns the AI's understanding into different actions.

    Step 4: Save and notify

    Add nodes for the outputs:

    • Google Sheets or your CRM to log the enquiry, category, and summary
    • Email or Slack to alert the right person with the details and the draft reply

    Keep the draft reply for a person to review at first. Sending replies automatically is a step you can add once the quality is proven.

    Step 5: Test with real examples

    Use the test feature to run the workflow with sample data. Try:

    • A clear sales enquiry
    • A support question
    • A vague or off-topic message
    • Messages in different styles or languages

    Check the AI's output each time and refine the prompt.

    Step 6: Add error handling

    Production workflows need to cope when something fails:

    • Use n8n's error workflow feature to alert you when a run fails
    • Add checks for missing data
    • Plan what happens when the AI returns something unexpected
    • Avoid storing secrets inside nodes; use n8n's credentials

    Step 7: Go live and monitor

    • Activate the workflow
    • Watch the first runs closely
    • Review executions regularly
    • Track how many were classified correctly and where it struggled

    Tips for better n8n workflows

    • Start simple. Add features one at a time.
    • Name your nodes clearly. It makes workflows easier to maintain.
    • Keep humans in the loop for anything customer-facing or high-impact.
    • Watch AI usage costs. Each model call costs money, so avoid unnecessary calls.
    • Document your workflows so others can understand and fix them.

    When to bring in help

    No-code workflows are great for many jobs. For high volume, sensitive data, complex logic, or business-critical processes, custom code or a professionally built solution is safer. See our automation examples for ideas on where to apply this.

    We can build it for you

    We design, build, and monitor n8n workflows and custom automations, with logging and alerts built in. Learn about our AI automation services, or book a free consultation.

    Have a project in mind?

    Tell us what you want to build and we will suggest the simplest path to get there.

    Keep reading

    All articles
    Automation
    3 min read

    10 AI Automation Examples for Small Businesses

    Practical examples of AI and workflow automation small businesses can use today: leads, invoices, support, reporting, scheduling, and more.

    Read article