Lección 6 · Módulo 2: Your First Working AI Automation
Error handling, retries and alerts so a workflow never fails silently
- Retry safely
- Route failures
- Alert a person
Why this matters
A booking workflow can fail in the middle and say nothing. The confirmation email goes out, the calendar entry never gets saved, and the customer arrives to find no appointment. This lesson shows how to make a workflow retry the steps that are safe to repeat, route each failure to a path you designed, and send a person an alert they can act on within a minute.
Key ideas
- Retries need a wait and a safe repeat. A calendar or email server often fails for a moment and then works. Retrying gives it a second chance, but only if running the step twice cannot create a duplicate. Example: the first try times out (wait 2 s), the second times out (wait 4 s), the third works. Each wait doubles, so you stop hammering a struggling service.
- Every booking gets one ID. Store a booking ID such as B-101 and check it exists before writing. A retry that finds B-101 already saved stops, so the calendar holds one booking, not two.
- A failure needs its own branch. Stop workflow ends the run at the first error. Continue hides the error and the run looks green. Error output sends the failed item to a branch you wired yourself, where an alert can fire.
- One error workflow watches everything. An Error Trigger node starts a second workflow whenever a linked workflow fails. It passes the workflow name, the broken node and the message to your alert.
- Silence is a failure too. A daily report that never arrives looks like a quiet day. A small scheduled check each morning that alerts you when the report is missing catches this.
Try it before you watch
A booking step times out after its first try, and the code waits 2 s, then 4 s, before the third try works. Why does the code wait longer each time instead of the same length?
Show answerHide answer
Doubling the wait gives a struggling service more room to recover and stops the workflow from hammering it with rapid retries. It also means a short outage costs a few seconds, not a flood of failed requests. It shows that a retry should back off, not repeat at a fixed pace.
Words to know
- retry: running a failed step again after a short wait, in case the problem was temporary.
- idempotent: safe to run twice, because the second run changes nothing that the first did not already do.
- error output: a second output on a node that carries the failed items, so you can wire them to their own branch.
- Error Trigger: a node that starts a workflow whenever another workflow in the system fails.
- heartbeat: a regular check that confirms a job ran; if the signal is missing, you get an alert.
- alert: a message sent to a person, such as a phone notification, that says something needs attention now.
What to watch for
- Watch how the retry settings are placed on the calendar node, and how the wait is set between tries.
- Notice the booking ID being checked before the write, and why the retry then stops instead of adding a second entry.
- Pay attention to the test failure in the exercise: the alert must reach your phone with the workflow name, the node and the message.
Apréndelo con tu tutor en la pizarra en vivo
Puntos clave del video
When a workflow fails in silence
- A confirmation email went out
- Nothing is saved
- It sits in a list
layout: wide
direction: LR
components:
cust: {kind: user, label: Customer}
form: {kind: client, label: Booking form}
wf: {kind: service, label: n8n workflow}
mail: {kind: email, label: Confirmation email}
cal: {kind: external, label: Calendar}
links: [cust->form, form->wf, wf->mail, wf->cal]
steps:
- at: "A customer books a haircut"
flow: ["cust>form: Tue 10:00", "form>wf: new booking"]
- at: "sends the confirmation email"
flow: ["wf>mail: sent"]
- at: "times out"
flow: ["wf>cal: create event"]
note: "Calendar: nothing saved"
- at: "marked failed"
highlight: wf
note: "Run: failed, unread"
- at: "has no record"
highlight: cust
note: "Customer: no booking"
- at: "stays quiet"
note: "The quiet failure"
- at: "how to stop that"
note: "Next: retry, route, alert" What you will learn
- Retry safely
- Route failures
- Alert a person
tree:
Never fails silently: [Retry safely, Route failures, Alert a person]
steps:
- at: "three things"
highlight: "Never fails silently"
- at: "retry safely"
show: "Retry safely"
- at: "route failures"
show: "Route failures"
- at: "alert a person"
show: "Alert a person"
- at: "one you can trust"
highlight: "Never fails silently" Why failures stay quiet
- Twelve confirmation emails
- Nine calendar bookings
- Three customers with no booking
layout: side
objects:
mail: {text: "Confirmation emails: 12", pos: top}
cal: {text: "Calendar bookings: 9", pos: center}
miss: {text: "No booking: 3", pos: bottom_right, color: red}
gap: {tex: '12 - 9 = 3', pos: bottom_left}
steps:
- at: "twelve confirmation emails"
show: mail
- at: "nine calendar bookings"
show: cal
- at: "three customers had"
show: miss
- at: "Subtract nine from twelve"
show: gap
- at: "never backed up"
highlight: miss
- at: "looked finished"
highlight: cal
- at: "Count failures on purpose"
highlight: gap Retry, with a wait between tries
- Retry On Fail, in node settings
- Max Tries, and the wait
- In code, the wait can double
attempts = []
def book(name):
attempts.append(name)
if len(attempts) < 3:
raise TimeoutError("calendar timed out")
return f"booked for {name}"
def with_retry(fn, tries=3):
for n in range(1, tries + 1):
try:
return fn()
except TimeoutError as e:
print(f"try {n} failed: {e}")
if n < tries:
print(f"waiting {2 ** n} s")
raise RuntimeError("gave up")
print(with_retry(lambda: book("Ana"))) Retry only what is safe to repeat
- Every booking gets one ID
- Check the ID before you write
- A retry cannot double-book
cells:
A1: Booking ID
B1: Customer
C1: Time
A2: B-101
B2: Ana
C2: Tue 10:00
steps:
- at: "the reply got lost"
select: A2:C2
note: "saved, but the reply was lost"
- at: "tries again"
type: {A3: "B-101", B3: "Ana", C3: "Tue 10:00"}
- at: "two identical bookings"
highlight: A3
- at: "give every booking one ID"
highlight: A2
- at: "finds the ID already there"
note: "found, so it stops"
- at: "if this runs twice"
note: "run it twice: what happens?"
- at: "Email and payments"
note: "highest risk"
- at: "worse than a missed retry"
note: "a missed retry costs less" Give failures a branch
- Stop workflow is the default
- Continue hides the failure
- Error output is a branch you own
tree:
Calendar fails:
Stop workflow: [Run ends]
Continue: [Run looks green]
Error output: [Alert the owner]
direction: down
steps:
- at: "Picture the calendar step failing"
grow: "Calendar fails"
- at: "Stop workflow is the default"
highlight: "Stop workflow"
- at: "Continue hides the failure"
highlight: "Continue"
- at: "a branch you own"
highlight: "Error output"
- at: "alerts the owner"
grow: "Error output"
- at: "Pick the setting"
highlight: "Error output" One error workflow for everything
- Error Trigger node starts it
- Set it as the error workflow
- Sends those facts to your phone
layout: wide
direction: LR
components:
wf: {kind: service, label: Booking workflow}
errwf: {kind: service, label: Error workflow}
owner: {kind: user, label: Salon owner}
links: [wf->errwf, errwf->owner]
steps:
- at: "a second workflow"
highlight: errwf
- at: "Error Trigger node"
note: "wakes on any failure"
- at: "choose this one as its error workflow"
highlight: [wf, errwf]
- at: "When a run fails"
flow: ["wf>errwf: run failed"]
note: "name, node, message"
- at: "sends those facts"
flow: ["errwf>owner: facts"]
- at: "One place to watch"
highlight: none An alert a person can act on
- The workflow and the node
- The error message
- The booking ID
- The customer's name
alert = {
"workflow": "Booking assistant",
"node": "Create calendar event",
"error": "timeout after 30 s",
"booking": "B-104",
"customer": "Ana",
}
for key, value in alert.items():
print(f"{key}: {value}")
print("Action: call Ana, book by hand") Watch for silence
- A daily report must arrive
- A missing report sends you an alert
- Silence is a failure too
kind: line
title: Daily sales report received
x: [Mon, Tue, Wed, Thu, Fri]
data: {"Reports received": [1, 1, 1, 0, 1]}
steps:
- at: "Some failures are not errors"
show: all
- at: "A daily report that goes missing"
note: "quiet week, or broken?"
- at: "The fix is a heartbeat"
note: "a second check each morning"
- at: "sends you an alert"
note: "missing report: alert"
- at: "every working day except Thursday"
note: "Thursday: no report"
- at: "That silence should wake someone up"
note: "silence needs a check"
- at: "absence of good news"
note: "no news is bad news" Do not switch the errors off
- Continue on every node
- The run list still says success
- Test failures on purpose
cells:
A1: Booking
B1: Calendar
C1: Run status
A2: B-101
B2: Saved
C2: Success
A3: B-102
C3: Success
A4: B-103
C4: Success
steps:
- at: "switch on Continue"
highlight: C1
- at: "look green"
highlight: C2
- at: "Two bookings were quietly lost"
select: B3:B4
- at: "still says success"
highlight: C3
- at: "A checkmark tells you"
note: "finished is not the same as worked"
- at: "test failures on purpose"
highlight: C4
- at: "Check the calendar"
select: B2:B4 Three takeaways
- Retry only what is safe to repeat
- Route failures to a branch you designed
- Alert a person with the facts
tree:
Never fails silently: [Safe retries, Error branches, Alerts with facts]
steps:
- at: "retry only what is safe"
show: "Safe retries"
note: "one ID per booking"
- at: "route failures to a branch"
show: "Error branches"
note: "no silent Continue"
- at: "alert a person with the facts"
show: "Alerts with facts"
note: "a person can act"
- at: "never fails silently"
highlight: "Never fails silently" Your exercise
- Retry On Fail on the calendar node
- Error workflow in the settings
- One test alert reaches your phone
tree:
Your workflow: [Calendar node, Error workflow, Test alert]
steps:
- at: "Open your booking workflow"
highlight: "Your workflow"
- at: "On the calendar node"
show: "Calendar node"
- at: "create a second workflow"
show: "Error workflow"
- at: "force a failure"
show: "Test alert"
- at: "one test alert reaches your phone"
highlight: "Test alert"
- at: "Bring a screenshot"
highlight: "Your workflow" Transcripción
When a workflow fails in silence. Picture a Tuesday morning. A customer books a haircut for ten o'clock through your booking form. Your n8n workflow runs its steps in order. First it sends the confirmation email, so the customer feels sure. Then it tries to create the calendar event. That step times out, so nothing is saved. The run is marked failed, but it sits in a list nobody opens. At ten, the customer walks in, and your salon has no record of them. This is the real danger of automation. Not the failure itself, but the failure that stays quiet. Today you learn how to stop that.
What you will learn. By the end of this lesson, you can do three things. First, retry safely, so a slow calendar gets a second chance without doubling bookings. Second, route failures to their own branch, so every error has a designed path. Third, alert a person with enough facts to act within a minute. These three habits turn a workflow you hope works into one you can trust with a real client.
Why failures stay quiet. Let's count what a quiet failure costs. Last month, twelve confirmation emails went out from the booking workflow. Only nine calendar bookings were saved. So three customers had a confirmation and no booking at all. Subtract nine from twelve and you get three. Those three people trusted a message your system never backed up. Nothing in the automation flagged it, because every step looked finished. Count failures on purpose, or you will never see them.
Retry, with a wait between tries. Now the fix for the timeout. In n8n, every node has a Retry On Fail setting in its settings tab. Turn it on, set Max Tries, and choose the wait between tries. n8n waits the same time between each try. Calendars and email servers often fail for a moment and then work, so a retry gives them a second chance. In code, the wait can double each time. Here is that idea. The first try times out, so the code plans a two second wait. The second try also times out, so it plans a four second wait. The third try works. Doubling the wait stops you hammering a struggling service. The demo prints each wait instead of pausing, so it finishes at once.
Retry only what is safe to repeat. A retry has a danger. Suppose the calendar did save the event, but the reply got lost on the way back. Your workflow thinks it failed and tries again. Now the calendar holds two identical bookings. So give every booking one ID, such as B-101, and check the ID before you write. The retry finds the ID already there, so it cannot double-book. Ask yourself one question for every step: if this runs twice, what happens? Email and payments need this most. Charging a customer twice is worse than a missed retry.
Give failures a branch. Now the error paths. Picture the calendar step failing. Stop workflow is the default, and the run ends at the first failure. Continue hides the failure, and that is the trap, because the run looks green. Continue using error output is better, because it gives you a branch you own. That error output alerts the owner, so the failure stays visible. Because the run no longer counts as failed, the error workflow will not fire for that node, so the alert has to come from that branch. Pick the setting that gives every failure a branch you designed.
One error workflow for everything. Error output handles failures inside one workflow. For failures anywhere in your system, build a second workflow. Start it with an Error Trigger node, which wakes up whenever another workflow fails. Then open the booking workflow's settings and choose this one as its error workflow. When a run fails, n8n hands over the workflow name, the node that broke and the message. Your error workflow then sends those facts to your phone. One place to watch, for every workflow you build later.
An alert a person can act on. An alert that says something failed is not enough. Someone reading it on a phone at a busy hour needs to act within a minute. So the alert needs the workflow and the node that broke. It needs the error message, the booking ID and the customer's name. Here, the alert says the calendar step timed out after thirty seconds for booking B-104, for Ana. The reader knows whom to call and can book by hand before the customer leaves. Send alerts somewhere you read, such as a free Telegram bot or your work email.
Watch for silence. Some failures are not errors at all. The workflow simply never runs. A daily report that goes missing looks just like a quiet week, so nobody asks why. The fix is a heartbeat. Build a small second schedule that checks each morning whether yesterday's report arrived. If it did not, it sends you an alert. Here, the report arrived on every working day except Thursday. That silence should wake someone up. Silence is a failure too. Watch for the absence of good news, not only for red marks.
Do not switch the errors off. The most common mistake is to switch on Continue on every node. Now every run can look green, even when a calendar step failed. Two bookings were quietly lost in this example, and the run list still says success. A checkmark tells you the workflow finished, not that it worked. Before you go live, test failures on purpose. Check the calendar, not only the run list.
Three takeaways. Here are your three takeaways. First, retry only what is safe to repeat. Give each booking one ID, and check it before you write, so a retry cannot double-book. Second, route failures to a branch you designed, with error output or an error workflow, never a silent Continue. Third, alert a person with the facts, and watch for silence too. A workflow that never fails silently is one you can hand to a client.
Your exercise. Your exercise takes about thirty minutes. Open your booking workflow. On the calendar node, turn on Retry On Fail, with three tries and a wait between them. Then create a second workflow with an Error Trigger node, and set it as the error workflow in the booking workflow's settings. Finally, activate the booking workflow, then force a failure by typing a wrong calendar name and submitting the form the real way. A manual test run in the editor does not start the error workflow. Check that one test alert reaches your phone, with the workflow name, the node and the message. Bring a screenshot to the next lesson.
Explora las animaciones
Las animaciones del video, exactas y en vivo: reprodúcelas, pausa, arrastra el control deslizante o salta a un paso a tu propio ritmo.
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Responde todas las preguntas y luego comprueba. Apruebas con 70%; puedes intentarlo las veces que quieras.
Resumen de la lección
- Lectura
- Video visto
- Cuestionario aprobado (70%)
- Retry only what is safe to repeat
- Route failures to a branch you designed
- Alert a person with the facts