-
Notifications
You must be signed in to change notification settings - Fork 48k
feat(core): Add programmatic workflow validation in AI workflow builder #20998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat(core): Add programmatic workflow validation in AI workflow builder #20998
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
68308bb
to
c8e0e9b
Compare
…checks-in-the-builder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 issues found across 41 files
Prompt for AI agents (all 3 issues)
Understand the root cause of the following 3 issues and fix them.
<file name="packages/@n8n/ai-workflow-builder.ee/src/validation/checks/connections.ts">
<violation number="1" location="packages/@n8n/ai-workflow-builder.ee/src/validation/checks/connections.ts:27">
Rule violated: **Prefer Typeguards over Type casting**
`Object.entries` returns string keys, so casting `connectionType` to `NodeConnectionType` sidesteps the guard this rule expects. Please introduce a proper `NodeConnectionType` type guard (or adjust typings so the key is already constrained) instead of relying on `as` for narrowing.</violation>
</file>
<file name="packages/@n8n/ai-workflow-builder.ee/src/validation/utils/resolve-connections.ts">
<violation number="1" location="packages/@n8n/ai-workflow-builder.ee/src/validation/utils/resolve-connections.ts:43">
Rule violated: **Prefer Typeguards over Type casting**
Please avoid using `as` to narrow `result` here. Instead, tighten the typing by introducing a proper type guard (or refining the return type of `Expression.resolveWithoutWorkflow`) so that `result` is proven to be `Array<NodeConnectionType | T>` without relying on a cast.</violation>
</file>
<file name="packages/@n8n/ai-workflow-builder.ee/src/validation/checks/from-ai.ts">
<violation number="1" location="packages/@n8n/ai-workflow-builder.ee/src/validation/checks/from-ai.ts:23">
Rule violated: **Prefer Typeguards over Type casting**
The recursion relies on `as Record<string, unknown>` to narrow `value`/`item` after runtime checks, which breaks the “Prefer Typeguards over Type casting” rule. Please replace these assertions with a dedicated type guard (e.g., `isRecord`) so TypeScript narrows without casting. This applies both to the object branch and the array branch.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai
to give feedback, ask questions, or re-run the review.
totalConnections += connectionSet.length; | ||
} | ||
if (totalConnections > 0) { | ||
providedInputTypes.set(connectionType as NodeConnectionType, totalConnections); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule violated: Prefer Typeguards over Type casting
Object.entries
returns string keys, so casting connectionType
to NodeConnectionType
sidesteps the guard this rule expects. Please introduce a proper NodeConnectionType
type guard (or adjust typings so the key is already constrained) instead of relying on as
for narrowing.
Prompt for AI agents
Address the following comment on packages/@n8n/ai-workflow-builder.ee/src/validation/checks/connections.ts at line 27:
<comment>`Object.entries` returns string keys, so casting `connectionType` to `NodeConnectionType` sidesteps the guard this rule expects. Please introduce a proper `NodeConnectionType` type guard (or adjust typings so the key is already constrained) instead of relying on `as` for narrowing.</comment>
<file context>
@@ -0,0 +1,184 @@
+ totalConnections += connectionSet.length;
+ }
+ if (totalConnections > 0) {
+ providedInputTypes.set(connectionType as NodeConnectionType, totalConnections);
+ }
+ }
</file context>
throw new Error('Expression did not resolve to an array'); | ||
} | ||
|
||
return result as Array<NodeConnectionType | T>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule violated: Prefer Typeguards over Type casting
Please avoid using as
to narrow result
here. Instead, tighten the typing by introducing a proper type guard (or refining the return type of Expression.resolveWithoutWorkflow
) so that result
is proven to be Array<NodeConnectionType | T>
without relying on a cast.
Prompt for AI agents
Address the following comment on packages/@n8n/ai-workflow-builder.ee/src/validation/utils/resolve-connections.ts at line 43:
<comment>Please avoid using `as` to narrow `result` here. Instead, tighten the typing by introducing a proper type guard (or refining the return type of `Expression.resolveWithoutWorkflow`) so that `result` is proven to be `Array<NodeConnectionType | T>` without relying on a cast.</comment>
<file context>
@@ -0,0 +1,102 @@
+ throw new Error('Expression did not resolve to an array');
+ }
+
+ return result as Array<NodeConnectionType | T>;
+ }
+
</file context>
} | ||
|
||
if (value && typeof value === 'object' && !Array.isArray(value)) { | ||
if (parametersContainFromAi(value as Record<string, unknown>)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule violated: Prefer Typeguards over Type casting
The recursion relies on as Record<string, unknown>
to narrow value
/item
after runtime checks, which breaks the “Prefer Typeguards over Type casting” rule. Please replace these assertions with a dedicated type guard (e.g., isRecord
) so TypeScript narrows without casting. This applies both to the object branch and the array branch.
Prompt for AI agents
Address the following comment on packages/@n8n/ai-workflow-builder.ee/src/validation/checks/from-ai.ts at line 23:
<comment>The recursion relies on `as Record<string, unknown>` to narrow `value`/`item` after runtime checks, which breaks the “Prefer Typeguards over Type casting” rule. Please replace these assertions with a dedicated type guard (e.g., `isRecord`) so TypeScript narrows without casting. This applies both to the object branch and the array branch.</comment>
<file context>
@@ -0,0 +1,76 @@
+ }
+
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
+ if (parametersContainFromAi(value as Record<string, unknown>)) {
+ return true;
+ }
</file context>
Summary
This PR adds programmatic workflow validation capabilities to the AI workflow builder agent. The validation system runs automated checks against workflows to detect critical issues and provide feedback to the AI agent.
Key Changes
validate_workflow
tool - Allows the AI agent to validate workflows programmatically during the building processvalidate_workflow
tool and as part of evaluation process (moved tosrc/
)evaluations/
)Function
constructor approach used beforeHow it works
The agent can now call
validate_workflow()
after making changes to ensure the workflow is valid. The tool:Related Linear tickets, Github issues, and Community forum posts
Review / Merge checklist
release/backport
(if urgent fix)