n8n Switch Node Boolean Pitfall: Silent Type Coercion That Breaks Flows
n8n Switch/If nodes can silently misroute when a boolean value is treated as a string, causing missed alerts or wrong branch execution. The root cause is type mismatch between templated values (strings) and expected boolean types-an easy-to-overlook issue that can have outsized operational impact.
The reported issue where a Switch node evaluates a value like 'true ' as a string rather than a boolean is a classic example of implicit type coercion in templating systems. Upstream nodes may emit JSON booleans, but using templating expressions or certain node outputs can stringify values or introduce whitespace characters. Because n8n does not always surface a clear error in these cases, flows can silently follow the wrong branch.
For businesses, silent failures are more dangerous than explicit errors: missed alerts, failed SLAs, and customer-impacting incidents may occur without easy detection. Teams that depend on citizen developers using visual automation tools are particularly exposed because these issues are subtle and hard to catch without unit tests or runtime assertions.
Mitigations are straightforward and should be standardized. Coerce and validate types explicitly before conditional logic: use a Function/Set node to cast values (e.g., Boolean(value) or JSON.parse where applicable), trim strings, and replace templated conditions with direct JSON path access like $json["shouldEscalate"]. Add monitoring and fail-safe branches that log unexpected types and raise alerts instead of silently continuing.
Leaders should require basic testing and observability for automation flows: add automated smoke tests for critical branches, include schema validation steps for inputs, and maintain a runbook for diagnosing flow logic. Educate low-code developers about type hygiene and establish code-review checkpoints for workflows that influence customer-facing systems or compliance-sensitive processes.
Original Source
n8n Community
