Automation · · 5 min read
n8n error workflows: catch failed AI lead handoffs before retrying
Build a separate failure handler, test it with a controlled automatic run, and recover a lead handoff without blindly creating another CRM record.
By Sociologix Editorial

A captured lead is not yet a completed handoff
A visitor submits a project request. An AI step classifies it, then a CRM node creates the opportunity. If that final step fails, a pleasant website confirmation can hide an unfinished sales task. Build a visible recovery path before adding more intelligence to the workflow.
This AI-assisted editorial guide uses n8n documentation checked September 24, 2026. The JavaScript transformation was checked locally with synthetic payloads; the connected workflow and notification delivery have not been tested in a live n8n account.
1. Give failures their own workflow
Create a workflow named Lead intake — error handler. Add Error Trigger as its first node and save it. In your lead-processing workflow, open Options, then Settings, select this handler under Error workflow, and save. One handler can serve several workflows. [1]
The handler itself does not need to be published. Error Trigger responds to failures from automatic executions; clicking Execute Workflow in the editor is not an end-to-end test of this path. [2]
For this proposed design, capture the incoming request in durable storage before classification. Assign a stable intake ID and record separate states such as received, processing, needs_review and delivered. Those states are your application design, not statuses n8n creates automatically.
2. Turn the error event into a small operational record
After Error Trigger, add a Code node with JavaScript and Run Once for All Items. Use the transformation below to select operational fields. The Code node supports this execution mode without additional libraries. [3]
Execution IDs and URLs are not always present, particularly when the trigger fails. Treat them as optional. The fallback below checks the trigger error for a node name and leaves missing links null. [1]
Connect the result to your existing incident queue or team notification destination. Include an accountable owner and a link when available. Keep raw error bodies and customer messages out of broad alerts; investigate sensitive detail in the restricted execution record. The example intentionally does not copy the error message or stack trace.
const event = $input.first().json;
return [{
json: {
workflowId: event.workflow?.id ?? null,
workflowName: event.workflow?.name ?? "Unknown workflow",
executionId: event.execution?.id ?? null,
executionUrl: event.execution?.url ?? null,
failedStep: event.execution?.lastNodeExecuted
?? event.trigger?.error?.node?.name
?? "Trigger or unknown step",
status: "needs_review"
}
}];3. Prove the path with a controlled automatic failure
Create a separate staging workflow containing Schedule Trigger followed by Stop And Error. In Stop And Error, choose Error Message and enter TEST_ONLY: simulated lead handoff failure. This node deliberately fails an execution. Assign your error handler to this staging workflow. [4]
Configure Schedule Trigger with a Minutes interval and Minutes Between Triggers set to 1. Check the workflow timezone, save and publish this staging workflow, and let the schedule initiate the test. Scheduled workflows must be published. [5]
Observe one failed staging execution and the corresponding handler execution, then unpublish the staging workflow so it stops producing test incidents. Check that the intended destination received the operational record. Test missing execution-link data separately with a synthetic Code-node input; manual testing there checks the transformation, not Error Trigger delivery.
If no handler runs, check the assigned Error workflow and confirm the failure came from an automatic execution. If the handler runs but the alert does not arrive, inspect the destination node and its credentials rather than repeatedly failing the lead workflow.
4. Make the website response mean what it says
For webhook intake, set the Webhook node to respond using Respond to Webhook. That response node can return a JSON body and a configured response code. An error before the first response node produces a 500 response; a workflow that finishes without executing that node can return a standard 200 message. Do not use HTTP success alone as proof of CRM delivery. [6]
In this proposed architecture, send a received confirmation only after the intake record is stored. Include its reference and describe the next step without claiming an opportunity already exists. If later processing fails, staff can find the durable request and update its state. An error event does not automatically contain your original intake ID: retain the relationship between execution and intake in restricted storage when processing starts.
5. Recover deliberately, then check the business record
A timeout can leave the caller uncertain even when a remote write succeeded. Before rerunning a CRM creation step, look up the intake ID in the destination. Where supported, use an idempotency key or a uniqueness rule tied to that ID. This is a proposed duplicate-prevention design; each CRM has different capabilities.
Limit retry attempts and route unresolved cases to a named person. An AI classification failure may need a corrected input or manual decision; repeating the same request is not a universal repair. Keep customer-facing commitments separate from automated retry policy.
- Failed handoff: a synthetic request remains available with an owner and a recoverable status.
- Missing execution URL: the incident still identifies the workflow and does not render a broken link.
- Repeated intake ID: recovery finds the existing CRM record instead of creating a second one.
- Notification failure: a reviewer can locate the failed handler and follow a documented fallback.
- Completion: mark delivered only after checking the expected destination record, not merely restarting a workflow.
Sources & further reading
Make your lead workflow easier to operate
Sociologix can help map intake, AI classification, CRM handoffs and human recovery into one observable workflow. Bring your current tools and a sample failure case to a consultation.
Talk to Sociologix