الدرس 3 · الوحدة 2: Your First Working AI Automation
Adding an AI step: classifying and summarizing incoming messages
الفيديو قريبًا
Learn it with your tutor on the live board
أهم نقاط الفيديو
Forty messages before breakfast
- A small bakery gets 40 messages a day
- Bookings, invoices, complaints, new leads
- Sorting them by hand takes an hour
- Today the workflow reads and labels them
What you will learn
- Add an AI step that classifies and summarizes
- Write a prompt that returns clean, structured data
- Route each message safely, with a fallback path
Classify and summarize, in plain words
- Messages: the unsorted pile
- Categories: booking, invoice, complaint, lead, other
- Classify = one shelf per message
- Summary = one short sentence
Where the AI step sits
- Trigger brings the message in (form or Gmail)
- AI node reads it: Basic LLM Chain or Text Classifier
- A check step makes sure the reply is valid
- Switch node sends each category down its own path
The prompt: fixed list, fixed shape
Classify this customer message.
Categories: booking, invoice, complaint,
lead, other. Use "other" if unsure.
Reply ONLY with JSON, nothing else:
{"category": "...", "summary": "..."}
The summary is one sentence, max 20 words.
Message: {{ $json.message }} Worked example: three possible replies
Allowed: booking, invoice, complaint,
lead, other
Reply 1: {"category": "booking"}
-> booking
Reply 2: {"category": "refund request"}
-> not in list -> other
Reply 3: Sure! This looks like a lead.
-> not JSON -> other, check by hand Temperature: turn the creativity down
- Temperature = how much randomness the model adds
- Low (0 to 0.2): almost the same answer every time
- High (0.8 and up): varied, creative wording
- Sorting needs low; marketing copy can go higher
Summaries into a daily digest
- Each summary is saved as a row in Google Sheets, with its date
- A Schedule trigger runs at 6 pm
- A second AI step turns today's rows into a short report
- The owner reads one email instead of forty messages
Test it before you trust it
- Collect 10 to 20 real past messages
- Write the right category next to each yourself
- Run them through the workflow and compare
- Fix the prompt where it gets things wrong
Common mistake: trusting the raw reply
- Letting the model invent its own categories
- Assuming the reply is always valid JSON
- No "other" path, so odd messages vanish
- Fix: closed list, a check step, a fallback route
Recap
- Classify = one label from a fixed list; summarize = one short sentence
- Ask for JSON, keep temperature low, validate the reply
- Every odd case lands in "other", never in silence
Your exercise
- Add an AI node to your lead capture flow
- Categories: booking, invoice, complaint, lead, other
- Add a check step and a Switch with an "other" path
- Test with 10 messages you write yourself
النص المكتوب
Forty messages before breakfast. Picture Sara, who runs a small online bakery. Every morning her inbox holds about forty new messages. Some want to book a cake tasting, some ask where their invoice is, one is angry about a late delivery, and a few come from a cafe that could become her biggest client. She has to read every one before she knows which ones matter. That's an hour a day spent sorting instead of baking. What if a workflow read each message the moment it arrived, put a label on it, and wrote a one-line summary? That's what we'll build today, and it's the first time our automation actually thinks.
What you will learn. Here's the plan for this lesson. First, you'll add an AI step to the lead capture flow you built last time, so every incoming message gets a category and a short summary. Second, you'll write a prompt, the instruction you give the AI, that makes it answer in a fixed, machine-readable shape instead of chatty prose. Third, you'll route each category to its own path, and you'll make sure anything strange lands in a safe fallback instead of breaking the workflow. By the end, Sara's inbox sorts itself.
Classify and summarize, in plain words. Think of an old post room. On the left sits a pile of messages, unopened and mixed together. In the middle are the categories, a set of shelves with fixed names: booking, invoice, complaint, lead, and other. Classifying simply means putting each message on exactly one shelf. On the right is the summary, a sticky note that says what the message wants in one short sentence. The worker doing the sorting is a language model, a program trained on huge amounts of text that predicts sensible next words, like phone autocomplete grown very large. It reads like a person, but it needs clear instructions.
Where the AI step sits. In n8n, the AI step is just another node in the chain. Your trigger, the web form or a Gmail trigger, brings the message in. Next comes an AI node. You can use the Basic LLM Chain, where you write the prompt yourself, or the Text Classifier node, which takes a list of categories for you. LLM means large language model, the kind of program we just met. Either node needs a chat model attached underneath it. After that, a small check step confirms the reply makes sense. Finally comes a Switch node, which picks a path based on a value. It looks at the category and sends bookings to the bookings sheet and complaints to an urgent alert. Anything marked other goes to the owner, who reviews it by hand.
The prompt: fixed list, fixed shape. Let's slow down here, because the prompt is where most of the quality comes from. Notice three things. The categories are a closed list, and we tell the model to choose other when it isn't sure. We ask for JSON, which is a simple text format of names and values in curly braces, so the next node can read the category like a spreadsheet column. And we limit the summary to one sentence. The double curly braces at the bottom are n8n's way of dropping the actual message text into the prompt.
Worked example: three possible replies. Here's what the check step does with three replies a model might give. Start at the top: the allowed list, our five shelves. The first reply is perfect, a booking, so it goes straight to booking. The second invents a category we never asked for, refund request. It's not in the list, so the check moves it to other. The third isn't JSON at all, because the model just chatted. Since it's not JSON, it also goes to other, with a note to check it by hand. Three replies, zero crashes. In n8n you can build this check without code: an If node that asks whether the category is one of the five, and the Switch node's fallback output for everything else. If you are comfortable with code, a Code node can do the same job.
Temperature: turn the creativity down. Every chat model node in n8n has a setting called temperature. In plain words, it's how much randomness the model mixes into its choice of words. Think of a knob. Turned low, near zero, the model picks the most likely answer, so the same message gets almost the same label today and tomorrow. Turned high, it gets playful and varied, which is lovely for writing a fresh social media post but terrible for sorting. A classifier that gives a different label each time you run it is worse than no classifier, so keep it low.
Summaries into a daily digest. Summaries become really useful once you collect them. In your lead capture flow, add three new columns to the Google Sheet: the date, the category and the summary. Then build a tiny second workflow. A Schedule trigger fires at six every evening. A Sheets node reads the rows and keeps only the ones with today's date. Another AI step writes a digest: three bookings, one complaint about a late delivery, two promising wholesale leads. An email node sends it to Sara. Forty messages become one short email she can read in a minute, and it takes only a few simple nodes.
Test it before you trust it. Before you switch this on for a client, test it like a professional. Gather ten to twenty real messages from the past, with names removed. Write the correct category next to each one yourself, on a checklist. Then run them through the workflow with n8n's test button and compare. If it scores eighteen out of twenty, look closely at the two misses. Usually the fix is in the prompt: a clearer description of what counts as a lead, or one short example message per category. This small habit is what makes clients trust your automations.
Common mistake: trusting the raw reply. Here's the mistake almost everyone makes on their first AI workflow: they send the model's reply straight into the Switch node. It works in testing. Then one day the model answers refund request, or adds a friendly sentence before the JSON, and the Switch node finds no matching branch. The message simply falls into the gap, and nobody ever sees it. That might be your client's angriest customer. The fix is the trio you saw today: a closed list of categories in the prompt, a check step that validates the reply, and an other path that a human always reviews. In the Switch node, turn on the fallback output and connect it to your other path.
Recap. Let's wrap up. Classifying means picking exactly one label from a fixed list, and summarizing means shrinking a message to one useful sentence. To make the AI reliable, ask for JSON in a fixed shape, keep the temperature low, and always check the reply before you act on it. And whatever goes wrong, the message ends up in the other category where a person sees it, never lost in silence. With that, your workflow doesn't just move data any more, it understands what it's moving.
Your exercise. Now it's your turn. Open the lead capture flow from the last lesson and add an AI node after the trigger, using the prompt pattern from this lesson with the five categories. Add a check step, then a Switch node with one branch per category. Turn on its fallback output so other has its own path, even if it only sends you an email. Write ten test messages as if you were a bakery's customers, including one that's confusing on purpose, and see where each lands. Bring your score to the next lesson, where we'll cut the running costs of this step.
ملخص الدرس
- مشاهدة الفيديو
- Classify = one label from a fixed list; summarize = one short sentence
- Ask for JSON, keep temperature low, validate the reply
- Every odd case lands in "other", never in silence