How to Handle Errors in Automated Workflows
Why Workflows Fail
Workflow failures fall into five categories, and each requires a different handling strategy:
Transient infrastructure failures. The external API is temporarily down, a network timeout occurs, or a server returns a 500/502/503 error. These resolve on their own within seconds or minutes. The correct response is to wait and retry. If you do not retry, the workflow fails permanently for a problem that would have resolved itself.
Rate limiting. You are sending requests to an API faster than the service allows. Stripe allows 100 per second, Slack allows roughly 1 per second, most SaaS APIs allow 5-60 per second depending on your plan. The API returns a 429 status code, usually with a Retry-After header telling you how long to wait. The correct response is to pause and retry after the specified delay.
Invalid data. The input data does not match what the workflow expects. A required field is missing, an email address is malformed, a number field contains text, or a date is in the wrong format. The API returns a 400 error explaining what is wrong. Retrying will not fix this because the data itself is the problem. The correct response is to log the error, skip or quarantine the record, and alert a human if the issue is systemic.
Authentication failures. Your API key expired, was revoked, or lacks permission for the requested operation. The API returns 401 or 403. Retrying will not fix this. The correct response is to alert someone immediately because all subsequent calls with this credential will also fail until the key is renewed or permissions are updated.
Logic errors. Your workflow assumes a database record exists, but it was deleted. Your condition evaluates a variable that was never set because an earlier step was skipped. Your AI classification returned an unexpected value that no condition branch handles. These are bugs in your workflow design, not external failures. The correct response is to log detailed context and alert a developer.
Retry Logic: The Foundation of Error Handling
Retries handle the most common failure type: transient errors from external services. A properly configured retry strategy resolves 80-90% of workflow failures without human involvement.
Exponential Backoff
The standard retry pattern is exponential backoff: wait an increasing amount of time between each retry attempt. First retry after 2 seconds, second after 4 seconds, third after 8 seconds, fourth after 16 seconds. This gives the external service time to recover without overwhelming it with repeated requests during an outage.
Most workflow platforms let you configure retry behavior per action node: maximum number of retries (3-5 is typical), initial delay (1-5 seconds), backoff multiplier (2x is standard), and maximum delay (60-120 seconds). Setting these values prevents your workflow from retrying forever or retrying so fast that it makes the problem worse.
When to Retry vs When to Stop
Retry on: 429 (rate limited), 500, 502, 503, 504 (server errors), network timeouts, and connection refused errors. These are all transient problems where retrying has a reasonable chance of success.
Do not retry on: 400 (bad request), 401 (unauthorized), 403 (forbidden), 404 (not found), or 422 (unprocessable entity). These are deterministic errors where retrying with the same data will produce the same failure. Retrying wastes time and API quota. Instead, route these to an error handling path that logs the problem and takes appropriate action.
Idempotency: Safe to Retry
Before enabling retries, make sure the action is safe to execute more than once. Reading data is always safe to retry. Sending an email is not, because retrying after a timeout might send the email twice if the first attempt actually succeeded before the timeout fired.
For actions that create records or send messages, add idempotency checks: before creating a record, check if one with the same unique identifier already exists. Before sending a message, check if the message was already sent for this workflow execution. Many APIs support idempotency keys, a unique identifier you include with the request that tells the API "if you already processed a request with this key, return the original result instead of processing it again."
Fallback Paths
When retries fail or the error is not retryable, your workflow needs a fallback path that prevents complete failure. Fallback paths are alternative action sequences that execute when the primary path cannot.
Queue and Retry Later
If an API is completely down (not just slow), save the data that needs to be sent and process it later. Write the pending action to a database queue table with the payload, target API, and timestamp. A separate scheduled workflow checks the queue every 15 minutes and attempts to process queued items. Once the API recovers, the queued items process without data loss.
Alternative Service
If your primary email provider is down, can you send through a backup provider? If your primary SMS service is unreachable, can you queue the message in a secondary service? Having a fallback service for critical communication channels prevents customer-facing failures when one provider has issues.
Graceful Degradation
If a non-critical step fails, the workflow can continue without it. A lead processing workflow might have steps for CRM update, email send, Slack notification, and analytics logging. If the Slack notification fails, the lead is still captured in the CRM and the email is still sent. The Slack failure should not roll back the entire workflow. Configure non-critical steps to "continue on failure" while critical steps use "stop on failure."
Alerting and Notification
The worst outcome of a workflow error is not the error itself, it is nobody knowing about it. A workflow that silently fails for three days before someone notices has potentially lost hundreds of leads, orders, or support tickets.
What to Alert On
- Repeated failures: A single transient failure that resolves on retry does not need an alert. Three consecutive failures of the same step within an hour probably means something is broken and needs attention.
- Authentication failures: Any 401 or 403 error needs an immediate alert because it affects all subsequent executions until the credential is fixed.
- Data validation failures above threshold: If 5% of incoming records fail validation, that is normal dirty data. If 50% suddenly fail, something changed upstream and needs investigation.
- Workflow execution count anomalies: A workflow that normally runs 50 times per day suddenly running 0 times (trigger broken) or 5000 times (infinite loop or duplicate triggers) needs immediate attention.
- Latency spikes: A workflow that normally completes in 3 seconds suddenly taking 60 seconds might indicate an external service degradation that could escalate to failures.
Alert Fatigue Prevention
If every transient failure sends an alert, you will receive dozens of notifications per day and start ignoring them. When a real problem occurs, you will miss it in the noise. To prevent alert fatigue:
- Only alert on failures that retries did not resolve
- Group related alerts (10 failures of the same type in 5 minutes becomes one alert, not 10)
- Separate critical alerts (authentication failures, complete workflow stoppage) from informational alerts (individual record skipped due to bad data)
- Send critical alerts via SMS, informational alerts via email or Slack
Preventing Duplicate Actions
Duplicate actions are the most common side effect of poor error handling. A workflow sends a confirmation email, the connection times out before receiving the server's response, the retry logic triggers, and the email sends again. The customer receives two identical confirmation emails.
Prevention strategies:
Execution-level deduplication. Generate a unique execution ID when the workflow starts. Pass this ID to every action. Before each action executes, check if that execution ID has already completed this step. If it has, skip it. This handles retries within the same execution and also handles entire workflow re-executions from duplicate trigger events.
Record-level deduplication. Before inserting a database record, check if a record with the same unique key already exists. Use upsert operations (insert if new, update if exists) instead of plain inserts. This prevents duplicate records even if the workflow runs twice for the same event.
Time-window deduplication. For actions like sending emails, check if the same email was sent to the same address within the last 5 minutes. If it was, skip. This catches duplicates from slightly different trigger events (a customer clicks submit twice) as well as from workflow retries.
Logging for Debugging
When an error occurs, you need enough context to diagnose the cause without reproducing it. Good workflow logging captures:
- The full trigger payload: What data started this workflow execution?
- Each step's input and output: What variables did the step receive and what did it produce?
- API request and response details: For external API calls, log the request URL, method, headers (redact authentication tokens), request body, response status code, and response body.
- Timing information: How long did each step take? Slow steps indicate potential timeout risks.
- The exact error message and stack trace: For failures, capture the full error detail, not just "step failed."
Be careful with logging sensitive data. Do not log full credit card numbers, passwords, API keys, or personally identifiable information beyond what is needed for debugging. Most workflow platforms let you mark certain fields as sensitive, which redacts them in logs.
Error Handling Checklist
For every workflow you deploy, verify these items:
- Every API call has retry logic with exponential backoff configured
- Non-retryable errors (400, 401, 403) route to a separate error path, not the retry queue
- Critical steps stop the workflow on failure; non-critical steps continue
- Authentication failures trigger an immediate alert
- Repeated failures within a time window trigger a consolidated alert
- All actions that create records or send messages have deduplication checks
- Execution logs capture enough context to diagnose failures without reproduction
- Sensitive data is redacted from logs
- A fallback path exists for the most critical actions (especially customer-facing ones)
- You have tested error handling with intentionally triggered failures