ModulesLabQuizAll courses

Adding AI Steps to Automations

Put one AI step inside a fixed workflow: it reads an e-mail, picks a label from a closed list, and hands the doubtful ones to a person. Then build, test with ten e-mails, improve and publish your own inbox triage in n8n with Gemini.

Module 6 of 14 · Day 3 · Session 6 · AI Administrator: Agentic Workflows & Automation

Module 06 ~50 min read + lab No code

What you will be able to do

Prerequisites: Module 5: Automation Basics with n8n. Your n8n Cloud trial from Session 5 (check the days left at the top of your screen), with the same Google account connected to Gmail and Google Sheets. No API key and no credit card: the AI step runs on the trial's built-in Gateway credits.

SessionWhat happened, or happens
5Triggers, actions and items; the leave request as a workflow; your request intake, tested and published
6 (this module)One AI step inside the workflow, with a fixed output and a person for the doubtful cases
7Connecting tools (MCP), so an AI step can look things up
8Building an agent

1. The four AI step types

Almost every useful AI step in an office workflow is one of four jobs. Name the job before you write the prompt: it keeps the prompt short and the output predictable.

A table of the four AI step types: classify, extract, summarise and draft, with their input, output, typical use and risk
Classify and extract give small, checkable outputs. Summarise needs a check of what was left out. Draft is the riskiest: it ends in a person's review, not a send. (Figure: AI Administrator course material.)

Draft is the riskiest because its output goes to a reader, so a draft step should end in a human review rather than an automatic send. Module 10 turns that rule into a formal control.

Chain them: an invoice workflow

Extract the supplier, number, date and amount. Classify it as within or above the approval limit. Draft the reply for a person to check. Summarise the day's invoices for finance.

Why small steps

Each one has a narrow, checkable output and can be tested on its own. A failure is easy to find in Executions. Today we build the first: classify.

Back to the leave request

The leave request from Modules 3 to 5 had one amber step we skipped: reading the free-text note. That is a classify step too (urgent or not, medical or not). Today's pattern applies directly.

2. Where the AI step goes

Take your future-state map from Module 4. An AI step replaces exactly one box, usually one you marked amber or AI-judged. Around it the workflow stays as it was: a trigger before it, a router or a data node after it.

Five boxes in a row: trigger, prepare, AI step, route or store, act or hand over; red crosses mark the AI step placed first or last
Keep the AI step in the middle: after cheap filters (you do not pay for newsletters), before consequential actions (its judgement can still stop something). In the lab the cheap filter is the Gmail search subject:"[S6 test]". (Figure: AI Administrator course material.)

Two placement mistakes are common. Putting the AI step first, before any filtering, means paying for the model on every message, newsletters and auto-replies included. Putting it last, after an action such as sending, means its judgement can no longer stop anything.

3. A step prompt with a fixed output

A step prompt is different from a chat prompt. Nobody reads the answer; the next node does. So the prompt pins down the exact shape of the output and the allowed values. This is the module's prompt, version 1:

You classify incoming customer emails for a small software company. Read the email below and reply with exactly one word from this list: billing, technical, sales, unsure Rules: - billing: invoices, payments, refunds, subscription changes - technical: errors, login problems, how-to questions about the product - sales: pricing, demos, new licences, partnerships - unsure: anything else, or if two labels fit equally well Reply with the single word only. No punctuation, no explanation. Email subject: {{ $json.subject }} Email body: {{ $json.text }}

Five parts: a one-line role; a closed list of answers; a definition of each label; "single word only"; and the input at the end. The double curly braces are how n8n inserts fields from the previous node. You drag them from the left-hand input panel; you do not type them.

Never let the model invent a label

Ask for billing, technical or sales and the model will sometimes answer "support" or "Billing.". A Switch compares text literally: no rule matches and the item silently vanishes. Three defences, all in today's lab: a catch-all label (unsure), a clean-up step (trim and lower-case), and a fallback branch on the Switch that catches even the labels nobody thought of.

Extract steps: fields, not words

In the prompt

  • Ask for fixed keys, one per line: order: ..., date: ..., amount: ...
  • Say what to write when a value is missing: none
  • Give the date and number format you want

In n8n

  • Basic LLM Chain, Require Specific Output Format: on
  • Attach a Structured Output Parser with a JSON example
  • The answer arrives as separate fields the next node can map
  • Or use the Information Extractor node, built for this

We do not build an extract step today; this is where it lives when you need one. For a single-word label, Require Specific Output Format stays off.

4. The 'unsure' route

A model is never certain; it is fluent, which is different. Your design has to make room for doubt. The simplest tool is a fourth label, unsure, that routes to a person.

AI step, Clean label and a Switch: billing 3 of 10, technical 3 of 10 and sales 2 of 10 get a Gmail label; unsure or anything else, 2 of 10, goes to the Triage review sheet
Three known labels get a Gmail label; anything else goes to a sheet a person reads each morning. The numbers are from our ten-e-mail test: 3, 3, 2 labelled and 2 to a person. (Figure: AI Administrator course material.)
MethodHowCostUse when
Let the model say soDefine unsure in the promptNone extraAlways; it is today's lab
Ask for a confidenceSecond line: a number 0 to 100; route below 70A few tokensYou want a threshold you can tune
Ask twiceTwo prompts or two models; route when they disagreeDoubleHigh-stakes sorting

The confidence number is a self-estimate, not a measurement, but it separates the obvious from the borderline surprisingly well.

The human queue is not a failure

It is where the interesting cases live, and it is the sample you review weekly to improve the prompt (Module 12). A healthy triage sends 5 to 15 percent of items to a person. Zero means the model is guessing.

5. Cost per run and model choice

Every AI step costs tokens: roughly words in plus words out (Module 1). We measured one classification in our test: 183 tokens in, 1 token out.

Cost table for one classification of 183 tokens in and 1 out on Gemini 2.5 Flash-Lite, Flash and Pro, per e-mail and per 1,000 e-mails
On Gemini 2.5 Flash ($0.30 in / $2.50 out per million tokens) one e-mail costs about $0.000057: about 6 US cents per 1,000 e-mails. Our whole test day (about 100 classifications) used $0.09 of the trial's $2.00 Gateway credits. (Figure: AI Administrator course material; prices from ai.google.dev/gemini-api/docs/pricing, checked 12 October 2026.)
StepModel sizeWhy
Classify with a short label listSmall (for example Gemini 2.5 Flash)Easy task, high volume, speed matters
Extract a few fields from a clean formSmallSame
Summarise a long, messy threadLargeNeeds to follow references across pages
Draft a reply a customer will readLargeTone and accuracy are visible

Two habits that keep costs sane

Trim the input: subject and body, not the whole thread with signatures. Watch the spend from day one: the Gateway credits balance in the Gemini node, or a monthly budget alert with your provider if you use your own key. Module 12 adds proper cost tracking per workflow.

6. The model: Gemini on Gateway credits

In n8n the AI step is a Basic LLM Chain node with a chat model attached underneath it. In this course everyone uses the Google Gemini Chat Model on the trial's Gateway credits: each n8n Cloud trial starts with $2.00 of credits for the AI nodes, so nobody needs an API key or a card.

The Google Gemini Chat Model node with the Credential list open, showing Gateway credits with $1.91 left, and Create new credential
Credential: Gateway credits, $1.91 left. No API key, nothing to paste. Create new credential is the fallback for your own key.
The Gemini node's model list open, with models/gemini-2.5-flash selected
Pick models/gemini-2.5-flash from the list: a small, fast model is right for a short label list. Under Options, set the Sampling Temperature to 0 for repeatable answers. Do not type a model name: the Gateway only serves the models in this list (Trap 2 in the lab).

No Gateway credits? Use a free Gemini key

Only if the Gemini node shows no Gateway credits option, or the balance is $0.00. A free key needs a Google account and no credit card. 1. Go to aistudio.google.com, sign in, Get API key, Create API key, then Copy. 2. In n8n, open Google Gemini Chat Model, Credential: Create new credential, paste the key into API Key, leave Host as it is, Save. 3. Pick models/gemini-2.5-flash (it has a free tier) from the list and execute once to check. Never paste a key in the Zoom chat, a sticky note or an e-mail; if anyone saw it, delete it in AI Studio and create a new one. The exported workflow JSON does not contain the key. If you later add billing, set a monthly budget alert in AI Studio (Spend) on day one. Step by step with screenshots: Day3_S6_Gemini_Key_Guide.pdf.

Video, recorded live in n8n Cloud: the Google Gemini Chat Model under the AI step, the credential list with Gateway credits and its balance, picking models/gemini-2.5-flash from the list, temperature 0, and the token usage of one real classification in Executions (183 tokens in, 1 out) (1 min 16 s, narrated, with captions).

7. Demo: inbox triage

Ten e-mails, one AI step, one person for the doubtful ones. In the live session you watch on Zoom; you build it yourself after the break.

The S6 Demo Inbox triage workflow in Executions: New email, Classify email with Gemini underneath, Clean label, Route by label, three Label nodes and Add to Triage review, with item counts on the arrows
The workflow, left to right: trigger, AI step (Gemini underneath), Clean label, Switch, then three Gmail labels and the review sheet. One execution, 10 items in: 3 billing, 3 technical, 2 sales, 2 unsure.

The trigger: Gmail, Simplify off

The Gmail Trigger node: poll every minute, Simplify off, search subject [S6 test], and an output with subject and text fields
Poll every minute; Search: subject:"[S6 test]" (the cheap filter). Simplify off, so the output has subject and text. The yellow box under Simplify is n8n's own warning that the full response is larger; we need it, because only the full response has the plain-text body.

The AI step: Basic LLM Chain

The Classify email node: the prompt defined below on the left and the output on the right, one word per e-mail for ten items
Prompt (Define below) on the left; output on the right: one word per e-mail, ten items. Require Specific Output Format is off: a single word needs no parser.
The Gemini sub-node for run 10 of 10: the full prompt in, billing out, and tokenUsage with 183 prompt tokens and 1 completion token
What the model saw and what it cost. Run 10 of 10: the full prompt in, billing out. tokenUsage: 183 prompt tokens, 1 completion token. This is where the cost-per-run number comes from.

Clean, route, act, hand over

The Clean label Edit Fields node with label set to the expression json.text.trim().toLowerCase()
Clean the answer before routing. Edit Fields: label = {{ $json.text.trim().toLowerCase() }} protects the Switch from spaces and capitals. Include Other Input Fields is off, so the Label nodes reach back to the trigger for the message ID with $('New email').
The Route by label Switch node with three rules, billing, technical and sales, and a fallback output renamed unsure
Route with a Switch, and keep a fallback. Three rules (billing, technical, sales); Fallback Output: Extra Output, renamed unsure. Output tabs: 3, 3, 2, 2. The fallback is what makes an invented label harmless: it lands with a person instead of vanishing.
A Gmail Add Label node: message ID taken from the trigger and the label picked from the list
Act: Gmail, Add Label. Message ID from the trigger; label picked from the list; Retry On Fail is on. The labels must exist in Gmail first, and an imported workflow keeps the author's label IDs, so you pick your own from the list.
The Add to Triage review Google Sheets node appending date, from, subject, snippet and link
Hand over: the Triage review sheet. Append row: date, from, subject, snippet, link. Two e-mails land here: the two the model was not sure about. The link column opens the e-mail in Gmail; this is the queue a person opens each morning.

Ten test e-mails, sent by a workflow

The S6 Send ten test e-mails helper workflow: a Code node with ten items feeding a Gmail Send to myself node
A Code node makes 10 items and the Gmail node runs once per item: Module 5's items idea, put to work. Three billing, three technical, two sales and two deliberately ambiguous. You import this helper in the lab instead of typing ten e-mails.
Video, recorded live: the triage workflow left to right, the step prompt, the helper that really sends the ten test e-mails, and the run the published trigger picks up a minute later: ten items, split 3 billing, 3 technical, 2 sales and 2 unsure (1 min 51 s, narrated, with captions).

8. The prompt test that changed our prompt

We ran the same ten e-mails four times each with the same prompt at temperature 0. Nine e-mails got the expected label every time. One did not.

A grid of ten e-mails times four runs: with prompt v1 the e-mail Your talk at the conference came back sales in 2 of 4 runs; with prompt v2 it came back unsure in 4 of 4
With the module's prompt, "Your talk at the conference" (it asks for the slides and for student pricing) came back sales in 2 of 4 runs. One added rule: unsure in 4 of 4. (Figure: AI Administrator course material, from runs on 12 October 2026.)

The rule we added under the unsure line (prompt version 2):

- unsure: also when the email mixes a personal or unrelated request (slides, a talk, an event) with a business question

Two lessons

Test more than once: same prompt, same e-mail, temperature 0, and borderline cases can still flip. Tighten the definition, do not add a hack for one e-mail: a rule that names one subject line fixes one case and breaks the next. This is lab step 7.

9. Lab: M6 inbox triage

Video, recorded live: the new parts of the lab built from an empty workflow (Gmail Trigger with Simplify off and the subject filter, Fetch Test Event, the Basic LLM Chain with the pasted prompt, the Gemini model, one Execute step), then the finished lab: Clean label, the Switch with its fallback renamed unsure, and the Publish dialog (1 min 53 s, narrated, with captions).

Build it yourself: in the live session, 40 minutes in breakout rooms of three or four, everyone in their own workspace. A new e-mail arrives, an AI step classifies it as billing, technical, sales or unsure, a Switch routes it, the three known classes get a Gmail label, and the unsure ones are written to a sheet that a person reads. Then test with ten e-mails, improve the prompt and note the cost per run.

Words in today's n8n: Execute step runs one node, Execute workflow runs the whole workflow once, Publish makes it live (older tutorials say Activate).

Before you build (5 minutes)

Gmail: three labels

Left sidebar, Labels, +: billing, technical, sales. Exactly these names, lower case.

Sheets: the review queue

A new Google Sheet, tab renamed Triage review, row 1: date, from, subject, snippet, link. A native Google Sheet, in the same Google account as n8n.

n8n: the helper

Overview, Create, Import from file: Day3_S6_Send_Test_Emails.json. In Send to myself, connect Gmail and put your own Gmail address in To. Do not run it yet (Trap 3).

1

Trigger

A new workflow M6 Inbox triage. Add first step: Gmail, On message received (Gmail Trigger). Your Gmail credential, Poll Times Every Minute, Event Message Received, Simplify: OFF, Filters, Search: subject:"[S6 test]". Send yourself one e-mail whose subject starts with [S6 test], then Fetch Test Event. The output must show subject and text.

2

AI step

Add Basic LLM Chain (search "LLM"), Source for Prompt: Define below. Paste the prompt from Section 3 without the two placeholders, then drag subject to the end of the Email subject: line and text to the end of the Email body: line. Under the chain, Model +, Google Gemini Chat Model: Credential Gateway credits, model models/gemini-2.5-flash picked from the list, Options, Sampling Temperature 0. Execute step: the output is one word.

3

Clean

Edit Fields (Set), Manual Mapping: a String field label, value (as an Expression) {{ $json.text.trim().toLowerCase() }}. Execute step: one lower-case word.

4

Route

Switch, Mode Rules. Three rules on {{ $json.label }}, String, is equal to: billing, technical, sales. Turn on Rename Output and name each like its label. Options, Fallback Output: Extra Output, renamed unsure.

5

Label

On billing, technical and sales: Gmail, Add label to message. Message ID (Expression): {{ $('Gmail Trigger').item.json.id }} (use your trigger node's name). Label: pick your label from the list. Settings: Retry On Fail on.

6

Hand over

On unsure: Google Sheets, Append Row, your sheet, tab Triage review, Map Each Column Manually, dragging from the Gmail Trigger in the input panel:

ColumnValue
datedate
fromfrom, text
subjectsubject
snippettext
linkhttps://mail.google.com/mail/u/0/#all/ followed by id
7

Test with ten e-mails

Publish the triage (top right) with the version name v1. Then open the helper and Execute workflow: ten e-mails arrive. Within two minutes open Executions in the triage: one run with 10 items, expected 8 labelled and 2 rows in Triage review. An e-mail in the wrong place? Tighten the definitions; add the v2 rule from Section 8, publish again as v2, run the helper again and compare.

8

Note the cost

In Executions, open the run and click the Google Gemini Chat Model node: tokenUsage shows prompt and completion tokens per e-mail (ours: 183 in, 1 out, about 6 cents per 1,000 e-mails). Note it, and the Gateway credits balance, for your Module 12 tracker. Using your own key? Set a monthly budget alert in AI Studio (Spend).

Three traps we hit while testing (12 October 2026)

Trap 1: Simplify hides the e-mail body

With Simplify on (the default), the Gmail Trigger outputs Subject (capital S) and snippet, but no text. The prompt's {{ $json.subject }} and {{ $json.text }} arrive empty and the model guesses, often unsure for everything. Fix: turn Simplify off, Fetch Test Event again, and re-drag the fields.

The same e-mail with Simplify on: fields id, threadId, snippet, payload, To, Subject and From, but no text field
Same e-mail, Simplify on: id, threadId, snippet, payload, ... To, Subject, From. Which two fields does the prompt need, and are they here? No subject, no text.

Trap 2: type the model name, lose the Gateway

We typed models/gemini-flash-latest by hand. The run failed: "Gateway credits don't currently support this operation. Switch to using your own credential to continue." Gateway credits serve only the models in the node's list. The real fix is simpler than the message suggests: pick the model from the list.

Classify email in red; the Logs tab shows the Gemini sub-node's 400 error from the Gateway
What Trap 2 looks like: Classify email in red, and the Logs tab shows the Gemini sub-node's 400 error from the Gateway. Read errors on the sub-node: the chain node only says "Bad request".

Trap 3: old e-mails are not new

Execute workflow on a polling trigger fetches only the latest matching e-mail. A published trigger only reads e-mails that arrive after publishing. So: build and test with one e-mail, Publish, then send the ten. That is why the helper waits until step 7.

In your breakout room

  • Everyone builds in their own workspace; one person shares their screen at a time.
  • Stuck for more than three minutes? Ask for help (button at the bottom of Zoom), or Raise Hand when back in the main room.
  • Execute step after every node, and read the output panel before adding the next.
  • Most common issues: Simplify on, labels not created in Gmail, the helper run before publishing, a typed model name, the wrong Google account (403).
  • Done early? Add the confidence line (0 to 100) to the prompt and route anything below 70 to the sheet, then help someone in your room.
  • When the rooms close, bring a screenshot of your run (10 items) and your sheet back to the main room.

Deliverable

A published M6 Inbox triage with one execution of ten items (8 labelled, 2 in Triage review), a screenshot of the Triage review sheet with the two ambiguous e-mails, one line with your tokens per e-mail and your cost estimate per 1,000 e-mails, and the exported JSON. Saved as M6-inbox-triage. Handout: Day3_S6_Lab_Handout.pdf. The helper: Day3_S6_Send_Test_Emails.json. The solution, to compare after you have built your own: Day3_S6_Inbox_Triage_Solution.json (after import: connect Gmail and Sheets, choose Gateway credits, paste your sheet URL and pick each label from the list again).

10. Publish and watch in production

The n8n Publish workflow dialog: a required Version name field with a generated default, and an optional Describe changes box
Publishing now asks for a version name. Replace the generated default with something you will recognise later, such as "v2: unsure rule for mixed e-mails". Each run in Executions shows the version it ran, so you know which prompt produced a label.

Every week

  • Read the unsure queue: 5 to 15 percent is healthy
  • Spot-check five labelled e-mails
  • A pattern of mistakes? Tighten a definition, test the ten again

Every month

  • Tokens per run x runs = cost
  • The credits balance, or a budget alert with your provider (own key)
  • Too slow or too costly? Try a smaller model on the same ten

The ten test e-mails are your regression test: keep them, and run them again after every prompt change. Module 12 turns this into a tracker.

Before you close the tab

Menu, Export JSON, for every workflow you built today. If you will not use the triage until the next session, unpublish it: a polling trigger keeps checking Gmail every minute.

Knowledge check

Pick one answer per question, then check your score. These mirror the style of the final exam.

1. Which AI step type produces one label from a fixed list?

Why: Classify maps a text to exactly one of a closed set of labels, which is what a router needs.

2. Why should a step prompt end with "reply with the single word only"?

Why: A Switch compares values literally; extra words or punctuation cause a silent mismatch.

3. What is the purpose of an "unsure" label?

Why: Models are fluent even when wrong; an explicit unsure route turns doubt into human review instead of a wrong action.

4. Which task most justifies a large model rather than a small one?

Why: Tone and accuracy are visible to the reader, so the extra quality is worth the cost. Simple classification is fine on a small model.

5. Where should the AI step sit in the workflow?

Why: Filters first save cost; placing the step before actions means its judgement can still stop something.

6. In the lab, the model answers "Billing." for one e-mail. What prevents the item from vanishing at the Switch?

Why: Trim and lower-case remove spaces and capitals; anything still unmatched (such as "billing.") leaves by the fallback, so it reaches a person.

7. The Gmail Trigger has Simplify switched on. What happens to the prompt's {{ $json.text }}?

Why: Verified on 12 October 2026: the simplified output has Subject and snippet but no text field.

8. A workflow on the trial's Gateway credits fails with "Gateway credits don't currently support this operation". The most likely fix is:

Why: We hit this with a typed models/gemini-flash-latest; Gateway credits serve only the listed models.

9. A classification uses 183 input tokens and 1 output token on Gemini 2.5 Flash ($0.30 / $2.50 per million). About what do 1,000 e-mails cost?

Why: 183 x $0.30 + 1 x $2.50 per million tokens is about $0.000057 per e-mail, so about $0.06 per 1,000.

10. The triage is published, but ten e-mails that were already in the inbox were never classified. Why?

Why: Polling triggers start from the moment of publishing; send the test e-mails after you publish.

Self-check

Answer in your own words first, then open the model answer.

1. For your course task from Module 1, which of the four step types would you use, and what is the exact output format?

Any concrete answer with a closed list of labels or a fixed set of fields. A draft step must end in a review, not a send.

2. Describe two ways to detect low confidence in a classification step.

Allow an explicit unsure label; ask for a 0 to 100 confidence and route below a threshold such as 70; or run two prompts or models and route disagreements to a person.

3. A triage workflow sends zero items to the human queue. Is that good news?

No. It means the model never expresses doubt, so wrong labels are going straight into branches. Aim for 5 to 15 percent in review.

Summary

Key takeaways

  • Every AI step is classify, extract, summarise or draft. Name the job first.
  • Put it after cheap filters and before consequential actions.
  • A step prompt fixes the output: closed list, catch-all, "single word only".
  • Clean, route with a fallback, and send "unsure" to a person.
  • Test with the same ten e-mails every time; small models for simple steps; watch the cost.

Next, Module 7: connecting tools with MCP, so an AI step can look things up instead of only reading the e-mail.

Latest reading: AI steps in real workflows (2026)

References

  1. n8n documentation: Basic LLM Chain node.
  2. n8n documentation: Google Gemini Chat Model node.
  3. n8n documentation: Gmail Trigger node and the Switch node.
  4. n8n release notes 2.42 and 2.43 (October 2026): Gateway credits, publishing guardrails. docs.n8n.io/release-notes.
  5. Google (2026). Gemini API pricing, last updated 9 October 2026. ai.google.dev/gemini-api/docs/pricing.
  6. Alammar, J. and Grootendorst, M. (2024). Hands-On Large Language Models. O'Reilly. Tokens and prompting (Modules 1 and 2).
  7. Al-Banna, A. (2026). AI Administrator, Module 5: Automation Basics with n8n. Triggers, items, credentials, publishing.
  8. IEEE CS Region 8 AI Caravan (2026). AI Administrator Track Curriculum. aicaravan.org.

All n8n screens are real, from the course n8n Cloud trial workspace (n8n 2.42.7, 12 October 2026); e-mail addresses are blurred. The AI step used Google Gemini 2.5 Flash through the trial's Gateway credits, temperature 0. The ten test e-mails, their senders and the software company are fictional. Further reading: n8n for intelligent workflows · A Visual Guide to LLM Agents.