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:
- An AI reads the message and classifies the lead as hot, warm or cold.
- It writes a short reason and drafts a friendly reply.
- Every lead is logged to Google Sheets.
- 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
| Concept | What it means |
|---|---|
| Workflow | The whole automation, on one canvas |
| Trigger | The event that starts it: a form, an email, a schedule, a webhook |
| Node | One step that does one job |
| Items | The data passed between nodes. Each item is a JSON object |
| Expressions | {{ $json.email }} reads data from earlier steps |
| Credentials | API keys and logins, stored once, encrypted, reused |
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.
Part 4: Build the AI Lead Assistant
Step 1: Form Trigger
- Click + and search for Form.
- Pick On form submission.
- Form title: Contact us.
- Fields: Name, Email (type: email), Message. Mark all as required.
- 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
- Add a Basic LLM Chain node after the form.
- Attach a Chat Model → Google Gemini.
- Create a free API key in Google AI Studio, and save it as a new n8n credential.
- Set the prompt to Define below and use this 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- 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
- Create a sheet with the headers Name, Email, Category, Reason, Reply.
- Add a Google Sheets node → Append row in sheet.
- Connect your Google account (saved as a credential).
- 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 hotReference 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
- Execute workflow and watch each node turn green.
- Click any red node to see its input and output. Most errors are an expression pointing at the wrong field.
- Pin data on the form trigger to re-run without filling in the form again.
- The Executions tab keeps a history of every real run.
- 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
| Problem | Fix |
|---|---|
| AI returns a paragraph, not fields | Turn on Require specific output format and add the parser |
| If node always goes to false | Check the expression path; open the AI node output and drag the field in |
| Form works in test but not live | Use the production URL and make sure the workflow is active |
| Gemini error | Check the API key credential and your free-tier limits |
Practice
- Add a fourth category: spam. Do not log spam to the sheet.
- Change the trigger from a form to Gmail (new email received).
- 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