freedzhost.cloud

n8n: route, repair and generate workflows, with guardrails

Level AdvancedEstimated time 1 hRead first n8n: an agentic clock that notices what stoppedA word you don't know? Glossary

The clock (previous article) notices; this article acts. Two workflows of our network change the state of the machines by themselves: one routes a request to the right model, the other repairs a model that crashed. Each one is useful exactly as long as its guardrails hold.

Signed webhookHMAC checkedJudgeclassifies, private by defaultRuleswhat is allowedActthen verifyEventok · failedone retry, +25 srefused: bad signature
A request in plain words becomes an action only through checks. The signature proves who sent it, the judge classifies it (private by default), fixed rules decide, the result is verified, one retry after 25 seconds, and every outcome is written down.

1. Route: from plain words to the right model

An agent or a person asks in plain words: "load something good at reading a very long document". The workflow:

  1. Checks the signature. The caller signs the body with a shared HMAC key; n8n's Crypto node recomputes it over the raw body and refuses any mismatch. An unsigned webhook is a door.
  2. Asks the judge (Homelab 14) to classify the request into a short list of uses: code, long document, quick answer, vision… The data class is private by default, so nothing goes to a hosted model.
  3. Applies fixed rules: reuse what already serves, never take the card a game uses, refuse while a model is loading.
  4. Acts, then verifies that the right model really answers. If not, one retry after 25 seconds, never a loop.
  5. Writes an event with the outcome, failed as an error.

2. Heal: reload what crashed, within limits

When a model's container stops, an event says so. A workflow runs every minute, reads the new events with a cursor (it remembers the last event it handled, and lags 60 seconds behind the newest to avoid reading half-written rows), and decides per lost model. Its rules come from the action, not from anyone's confidence:

3. Workflows written by code

Clicking workflows together in the editor does not scale, and it cannot be reviewed. Our most important ones are generated by small Python scripts that write the workflow JSON: nodes, connections, the JavaScript of the Code nodes as plain strings. A change is a diff in a script, reviewed like any code; the JSON is imported into n8n, and every version is kept in a dated backup folder. Rebuilding them on a fresh n8n is running the scripts again; the simpler workflows are kept as exported JSON.

Traps we paid for

n8n's expression sandbox refuses some names: a field called caller made a workflow fail. Rename fields rather than fight the sandbox.

A node that silently falls back is worse than one that fails. Our judge node required a field we did not send; instead of an error, the request went down another path without anyone seeing. Validate inputs in a Code node before the call, and test each branch.

Running a workflow from n8n's command line fails while the server runs (they share a port). Test through the webhook, or through the clock.

Changes to a workflow's active state did not always apply until n8n restarted in our version. After a change, check that the workflow really runs.

Found this useful? Tell us what to measure next.