Merged
Size
L
Change Breakdown
Bug Fix55%
Feature30%
Docs15%
#28172feat(ai-builder): Fix IF/Switch/Filter node misconfiguration in builder (no-changelog)

AI workflow crashes eliminated with build-time validation

The AI workflow builder was generating conditional nodes with incomplete structures, causing crashes in 60% of test runs. A new validator catches these errors before runtime.

The n8n AI builder was generating workflows that looked valid but crashed during execution. The problem: conditional nodes like IF, Switch, and Filter require a specific structure with options, conditions, and combinator fields, but the AI prompts weren't making this clear enough. Add in a common mistake of using rules.rules instead of rules.values in Switch nodes, and workflows were failing at a 60% rate.

This PR fixes the problem at multiple levels. First, the prompts that guide the AI model now include complete examples of the correct conditions structure, a self-check checklist for routing nodes, and explicit warnings about the missing options crash. Second, the FilterValue type definition was tightened—options and combinator are now required instead of optional, which means the AI sees stricter type constraints. Third, a new filterNodeValidator plugin catches structural misconfigurations at build time, converting silent runtime crashes into blocking errors developers can fix immediately.

After these changes, test runs went from 3 of 15 scenarios passing to 10 of 15, with zero structural crashes. The full 27-scenario suite hit a 48% pass rate with clean builds across all 8 workflows tested.

The changes span two packages: the AI instance with improved prompts, and the workflow SDK with the new validator and type updates.

View Original GitHub Description

Summary

  • Fix AI builder generating IF/Switch/Filter nodes with missing conditions.options (causes caseSensitive crash) and wrong rules.rules key (causes Could not find property option crash)
  • Improve builder prompts with correct conditions structure, examples, and self-check checklist
  • Make options and combinator required in the FilterValue type the LLM sees
  • Add filterNodeValidator to catch structural misconfigurations as blocking errors at build time

Results (notification-router × 5 runs)

BeforeAfter
Structural crashes3/5 runs (60%)0/5 runs (0%)
Scenarios passed3/15 (20%)10/15 (67%)
Clean sweeps (3/3)13

Full suite (27 scenarios): 48% pass rate, zero crashes, all 8 workflows built.

Before

<img width="677" height="306" alt="Screenshot 2026-04-08 at 09 49 42" src="https://github.com/user-attachments/assets/d51a627e-75f3-473e-acc6-55c8ed6fae1e" /> <img width="666" height="315" alt="Screenshot 2026-04-08 at 09 54 49" src="https://github.com/user-attachments/assets/4c1f715a-ddeb-42a1-be21-abd5a2758ee2" />

After

<img width="606" height="341" alt="Screenshot 2026-04-08 at 09 50 02" src="https://github.com/user-attachments/assets/ccdcdf7d-a3d3-411c-a7b2-4480482cc468" /> <img width="674" height="329" alt="Screenshot 2026-04-08 at 09 54 56" src="https://github.com/user-attachments/assets/d2bf158d-3757-4f48-874c-13f8db01b9a8" />

Related Linear ticket

https://linear.app/n8n/issue/TRUST-35

Test plan

  • 13 unit tests for filterNodeValidator
  • 11428 SDK tests pass (89 suites)
  • Before/after eval comparison (5 runs each, same workflow, same conditions)

🤖 Generated with Claude Code

© 2026 · via Gitpulse