Skip to content
Lesson 1 of 845 min video

Build Your First AI Automation with n8n

An n8n AI Lead Assistant that scores form leads with Gemini, logs them to Google Sheets and emails you the hot ones.

Series: Road to AI Automation · Episode 1 · Level: Beginner · Time: about 45 minutes to follow along

What you will build

An AI Lead Assistant. When someone fills in a contact form:

  1. An AI reads the message and classifies the lead as hot, warm or cold.
  2. It writes a short reason and drafts a friendly reply.
  3. Every lead is logged to Google Sheets.
  4. Only hot leads send you an email alert with the drafted reply.
Form Trigger → AI (Basic LLM Chain + Gemini) → Google Sheets → If (category = hot) → Gmail

What you need

  • n8n: either n8n Cloud (free trial) or self-hosted with Docker (free)
  • A free Google Gemini API key from Google AI Studio
  • A Google account for Sheets and Gmail

Part 1: What is n8n?

n8n is a workflow automation tool. You connect apps and services on a visual canvas using blocks called nodes, and data flows from one node to the next.

Why people pick it:

  • Visual workflows: connect apps without writing glue code.
  • Hundreds of integrations: Gmail, Sheets, Slack, Telegram, databases, and any API through the HTTP Request node.
  • Self-hostable: it is fair-code, so you can run it on your own server and keep your data. No per-task fees when it runs on your own machine.
  • Built-in AI: agents, LLM chains, memory and tools, with models from OpenAI, Anthropic, Google Gemini or local models.
  • Code when you want it: the Code node runs JavaScript or Python.

Part 2: The core concepts

ConceptWhat it means
WorkflowThe whole automation, on one canvas
TriggerThe event that starts it: a form, an email, a schedule, a webhook
NodeOne step that does one job
ItemsThe data passed between nodes. Each item is a JSON object
Expressions{{ $json.email }} reads data from earlier steps
CredentialsAPI keys and logins, stored once, encrypted, reused
Key idea: if a node outputs 2 items, the next node usually runs twice, once per item. Most beginner confusion comes from this.

Example of items:

[
  { "name": "Sara Khan", "email": "sara@acme.io", "plan": "pro" },
  { "name": "Ali Raza",  "email": "ali@shop.pk",  "plan": "free" }
]

Part 3: Get n8n running

Option A: n8n Cloud. Sign up, start the free trial, build in the browser.

Option B: self-host with Docker (recommended long term):

docker volume create n8n_data

docker run -it --rm --name n8n -p 5678:5678 \
  -v n8n_data:/home/node/.n8n \
  docker.n8n.io/n8nio/n8n

Open http://localhost:5678 and create your owner account.

Tip: on a public server, always run n8n behind a reverse proxy with HTTPS.

Part 4: Build the AI Lead Assistant

Step 1: Form Trigger

  1. Click + and search for Form.
  2. Pick On form submission.
  3. Form title: Contact us.
  4. Fields: Name, Email (type: email), Message. Mark all as required.
  5. Click Test step, fill in the test form and submit.

Output (one item):

{
  "Name": "Sara Khan",
  "Email": "sara@acme.io",
  "Message": "We need an AI chatbot for our 3 clinics. Budget is approved, can we start this month?"
}

Step 2: The AI brain

  1. Add a Basic LLM Chain node after the form.
  2. Attach a Chat Model → Google Gemini.
  3. Create a free API key in Google AI Studio, and save it as a new n8n credential.
  4. Set the prompt to Define below and use this prompt:
prompt
You are a sales assistant for an AI agency.
Classify this lead as hot, warm or cold.
Hot = clear need AND budget or timeline.

Name: {{ $json.Name }}
Message: {{ $json.Message }}

Return JSON with: category, reason, reply
  1. Turn on Require specific output format and add a Structured Output Parser with this example:
{
  "category": "hot",
  "reason": "Clear need and approved budget",
  "reply": "Hi Sara, thanks for reaching out..."
}

Now every next node gets clean fields instead of a paragraph.

Step 3: Log every lead to Google Sheets

  1. Create a sheet with the headers Name, Email, Category, Reason, Reply.
  2. Add a Google Sheets node → Append row in sheet.
  3. Connect your Google account (saved as a credential).
  4. Map the columns: Name and Email from the form, Category, Reason and Reply from the AI output.

Step 4: Route hot leads to Gmail

Add an If node with this condition:

{{ $('AI: Classify').item.json.output.category }}   is equal to   hot

Reference the AI node by its name, so the condition does not depend on what the Sheets node returns. Use your own node name if it is different.

  • True branch → Gmail → Send a message to your own address. Put the lead's name in the subject, and the message plus the AI reply in the body.
  • False branch → leave it empty. Warm and cold leads are already logged.

Part 5: Test and go live

  1. Execute workflow and watch each node turn green.
  2. Click any red node to see its input and output. Most errors are an expression pointing at the wrong field.
  3. Pin data on the form trigger to re-run without filling in the form again.
  4. The Executions tab keeps a history of every real run.
  5. Activate / Publish the workflow. The test form URL only works while testing. Share the production URL.

Pro tips

  • Rename every node. "AI: Classify lead" beats "Basic LLM Chain1".
  • Keep secrets in credentials, never in prompts or Code nodes.
  • Set an Error Workflow in workflow settings so failures alert you.
  • Lower the model temperature for classification.
  • Use sticky notes to document the canvas.

Troubleshooting

ProblemFix
AI returns a paragraph, not fieldsTurn on Require specific output format and add the parser
If node always goes to falseCheck the expression path; open the AI node output and drag the field in
Form works in test but not liveUse the production URL and make sure the workflow is active
Gemini errorCheck the API key credential and your free-tier limits

Practice

  1. Add a fourth category: spam. Do not log spam to the sheet.
  2. Change the trigger from a form to Gmail (new email received).
  3. Send hot-lead alerts to Telegram instead of Gmail.

Next episode: turn this into a real AI Agent with memory and tools.

Key takeaways

  • A workflow is a chain of nodes, and the trigger decides when it runs
  • Ask the AI for JSON only, so later nodes can read each field reliably
  • Keep the AI's job small (score and draft) and let n8n nodes route and save
  • Debug from the Executions tab, and switch to the production URL once the workflow is active