Barcelona Code School

Since 2015 / 500+ graduates

n8n Tutorial: Build Your First AI Workflow

Beginner n8n tutorial

n8n Tutorial: Build Your First AI Workflow

Build a small, testable workflow that turns a fictional customer enquiry into structured triage data and a reply draft, without sending anything outside n8n.

Published 28 September 2026 · Barcelona Code School

Build your first n8n AI workflow with seven nodes: a manual trigger, mock input, validation, one bounded AI step, output validation, a review-ready result and an error route. Keep the workflow in manual test mode, use fictional data and stop before any external action. The first success criterion is predictable structured output, not automatic email or CRM updates.

Key takeaways

  • Start with manual execution and fictional data, not a live webhook or inbox.
  • Give the AI one job: classify an enquiry and draft a reply in a fixed schema.
  • Use deterministic nodes to validate input and model output.
  • End with a review record; add external actions only after testing.
  • An error path and an execution log are part of the first workflow.

What will you build?

The workflow receives a fictional customer message, checks that the required fields exist, asks an AI model to return a category and reply draft, validates the result and produces a record for human review. It does not send an email or update a live CRM.

This is an AI workflow, not yet an autonomous AI agent. The route is chosen in advance, and the model performs one narrow language task. That boundary keeps the first project easier to understand and test. For the general agent architecture, use the BCS guide to building an AI agent.

What input and output does the workflow use?

FieldTypeRequiredRule
request_idstringYesUnique fictional test identifier
customer_messagestringYesNon-empty; no real personal data
consent_to_processbooleanYesMust be true before a model call
categoryenumOutputOnly sales, support or other
reply_draftstringOutputDraft only; no claims outside supplied facts
needs_humanbooleanOutputTrue for uncertainty, missing facts or sensitive requests

A test record can use a message such as: “I run a small design studio and want to understand which course teaches workflow automation.” Do not paste a real customer conversation into an unfinished workflow.

{
  "request_id": "test-001",
  "customer_message": "I run a small design studio and want to learn workflow automation.",
  "consent_to_process": true
}

What does the finished workflow look like?

Figure 1. Seven-node first AI workflow

The model performs one bounded language task. The surrounding workflow controls data, validation, review and failure handling.

Text equivalent: manual execution creates a fictional record. An input check blocks incomplete or unauthorised data. The AI step returns three defined fields. A second check rejects unknown labels or missing fields. Valid results become a review-ready draft. Errors are recorded and routed to a person instead of being hidden.

How do you build the workflow step by step?

  1. Create a manual test trigger.

    Open a new workflow and start with the manual trigger available in your n8n version. Manual execution prevents the unfinished workflow from accepting live events. Name the workflow clearly, such as TEST - Enquiry triage draft.

  2. Add fictional input data.

    Add a field-setting node and create the three input fields shown above. Use a new request_id for each test. Execute this node and inspect its output before connecting anything else.

  3. Validate required fields.

    Add conditional logic that continues only when customer_message is not empty and consent_to_process is true. Route the false branch to a safe result such as status: rejected_input. The model should never repair missing consent.

  4. Add one bounded AI step.

    Connect a supported model credential using the narrowest access available. Ask the model to classify the message as sales, support or other, draft a short reply using only supplied facts and set needs_human. Require structured output. Node names and options can change, so confirm them in the documentation for your installed version.

    Classify the customer message as sales, support, or other.
    Draft a reply using only facts in the input.
    Set needs_human to true if facts are missing or the request is sensitive.
    Return only: category, reply_draft, needs_human.
  5. Validate the model output.

    Add a deterministic check after the model. Confirm that all three fields exist, the category is one of the allowed labels and the draft is within your chosen length. Route every unexpected result to status: needs_review. Do not ask the same model to approve its own output.

  6. Create a review-ready output.

    Map the validated fields into a final record with the original request ID, model result and status: draft_ready. n8n supports mapping data from previous nodes through expressions or the input pane. Inspect the actual node output before choosing a field path.

  7. Add errors, tests and activation rules.

    Create an error workflow or alert route that includes the workflow name, execution ID and failure message without exposing secrets. Keep the workflow inactive until the test matrix passes. If you later add email or CRM actions, require human approval and a duplicate-safe operation ID first.

Where do permissions and human approval belong?

The tutorial needs a model credential but no live customer-system credential. Keep the scope small and never place a secret inside prompt text, mock data or a screenshot. Anyone who can run or edit the workflow may be able to use connected credentials depending on the n8n role and project configuration.

A future send step belongs after output validation and human review. n8n documents simple send-and-wait approval through supported communication nodes, and suggests the Wait node for more complex approval processes. Approval should show the exact recipient, subject and message that will be sent.

The first workflow finishes at “draft ready.” External action is a separate capability with its own permission, approval and test cases.

What should happen when a node fails?

Record the execution ID, failing node, error type and request ID. A malformed input should stop without calling the model. An invalid model result should enter review. A temporary API error may be retryable, but only within a set limit.

n8n execution history can show failed, running, successful and waiting runs, and failed executions can be retried. Once a workflow has external side effects, never retry blindly: first check whether the previous run already created the record or sent the message.

How do you test the workflow?

CaseInputExpected result
Valid sales enquiryComplete fictional recordAllowed category and draft_ready
Empty messageBlank textrejected_input; no model call
No consentConsent falserejected_input; no model call
Ambiguous requestInsufficient factsneeds_human: true
Unexpected categoryModel returns another labelneeds_review; no external action
Prompt injection textMessage asks to ignore workflow rulesTreated as customer data; schema unchanged
Model timeoutSimulated provider errorError route records execution and alerts owner
Duplicate request IDRepeat test-001Detected before any future external write

Criteria for success

  • Only complete, consented fictional records reach the model.
  • The AI returns exactly the three defined fields.
  • Unknown labels and missing fields enter human review.
  • The workflow creates a draft but sends nothing externally.
  • Every failure is visible with an execution and request ID.
  • No credential or personal data appears in the workflow example.
  • All eight test cases reach their expected result.

Go from one workflow to a complete automation system

This tutorial is enough for a first controlled build. Barcelona Code School’s AI Agent & Automation Bootcamp is for people who want deeper practice with n8n, business data, tool-using agents, RAG, approvals, QA, error handling, monitoring and multi-agent orchestration in one connected portfolio project.

The bootcamp is a four-week, full-time career programme; you do not need it to test one small workflow. Use the live page for current dates, format, tuition and prerequisites.

Explore the AI Agent & Automation Bootcamp

Frequently asked questions

What should a first n8n AI workflow do?

A good first workflow should complete one bounded task with a clear input and output. For example, it can turn a fictional enquiry into a category and reply draft. It should not send messages, spend money or change important records while you are still testing it.

Do I need an AI Agent node for this n8n tutorial?

No. A direct model or extraction step is enough when the workflow needs one bounded judgement. Use an AI Agent node only when the system must choose among tools or decide several steps within defined limits.

How do I pass data between n8n nodes?

n8n lets you map values from previous nodes into later node parameters with expressions or by selecting data from the input pane. Check the actual input and output of each node rather than assuming a field name.

Should the first workflow send the AI-written email?

No. End the first version with a review-ready draft. After the workflow passes its tests, add a separate approval step before any email node sends to a real recipient.

How do I know the n8n workflow is ready to activate?

Activate it only when valid inputs produce the expected output, invalid data stops safely, unexpected model output enters review, credentials have minimum access, errors alert an owner and retries cannot duplicate an external action.

Sources

  1. n8n Docs: Platform overview.
  2. n8n Docs: Referencing data in the UI.
  3. n8n Docs: All executions.
  4. n8n Docs: Gmail approval operations.
  5. n8n Docs: Security audit.
  6. Barcelona Code School: How to Build an AI Agent.
  7. Barcelona Code School: AI Agent & Automation Bootcamp.
Back to posts