Most AI workflows look great in demos. Clean input, clean output, everyone's happy.
Then real data shows up. A user submits something unexpected. An API returns a weird format. A field is missing. And the whole thing either silently fails or produces garbage that nobody catches until a client asks why something's wrong.
That's not an AI problem. That's a logic problem. Specifically, it's a branching problem.
Here's the system I use to handle edge cases before they become fires.
Why Most Workflows Are Fragile
When you build with Claude, n8n, or Make.com, you're usually optimizing for the happy path. The input looks like you expect. The model does what you want. The output lands where it should.
But in production, the happy path is maybe 70% of what actually happens. The other 30% is edge cases. Incomplete data. Ambiguous inputs. Unexpected formats. Timeouts. Empty arrays.
If your workflow has no branching logic, it treats all of that like the happy path and produces wrong results confidently. Which is worse than failing loudly.
The Three Layers of Branching I Use
I think about branching in three distinct layers. Each one catches a different class of problem.
Layer 1: Input Validation Before Anything Runs
Before any AI node fires, I run a validation step. This is usually a simple function node in n8n or a filter step in Make.com. It checks for the fields I actually need.
Not just "does this field exist" but "does this field have usable content." An empty string passes existence checks. It still breaks your prompt.
I set three possible outputs from this layer: clean, repairable, and dead.
- Clean means the input looks right, pass it through.
- Repairable means something's off but I can normalize it before the AI sees it. Wrong format, extra whitespace, a field that came in as a number when I expected a string.
- Dead means the input is too broken to fix automatically. Route it to a human review queue, log it, and stop.
Most builders skip the repairable category entirely. They just pass or fail. That middle layer saves a lot of workflows from dying on minor formatting issues.
Layer 2: Output Validation After the Model Responds
The model ran. Now what did it actually return?
I always validate AI output before it touches anything downstream. Claude is generally consistent, but "generally" isn't good enough in production. It occasionally returns a different structure. It occasionally adds explanation text when you only wanted JSON. It occasionally refuses parts of a request.
My output validation checks three things:
- Is it the right format? If I asked for JSON, is this actually parseable JSON?
- Are the required keys present? Not just any response, the specific fields I need downstream.
- Does the content pass a basic sanity check? Not empty. Not a refusal. Not a hallucinated non-answer.
If it fails any of these, I don't retry blindly. I route to a repair prompt that gives Claude the bad output and asks it to fix the specific problem. One retry with context. If it fails again, it goes to the dead queue.
Layer 3: Downstream Dependency Checks
This one most people never build until something breaks badly.
Even if input is clean and output looks valid, the downstream systems your workflow connects to can fail. An API is rate-limited. A database write fails. A webhook endpoint is down.
I add a dependency check after every external write. If the write fails, I don't just log it and move on. I check whether the failure is recoverable (retry in 60 seconds) or terminal (log, alert, stop).
The decision is simple: if the failure could cause data inconsistency or a silent wrong state downstream, it's terminal. Stop the workflow. Alert me. Don't let it cascade.
