fix(core): Validate non-empty prompts in AI vendor nodes before API calls (backport to release-candidate/2.21.x)#30820
Merged
alexander-gekov merged 1 commit intoMay 20, 2026
Conversation
5 tasks
alexander-gekov
approved these changes
May 20, 2026
Bundle ReportChanges will decrease total bundle size by 8.44kB (-0.02%) ⬇️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: editor-ui-esmAssets Changed:
|
Contributor
There was a problem hiding this comment.
1 issue found across 22 files
Architecture diagram
sequenceDiagram
participant WF as Workflow Engine
participant NV as AI Vendor Node
participant PV as Prompt Validator
participant API as Upstream AI API
Note over WF,API: NEW: Prompt validation before external API calls
WF->>NV: execute(i)
NV->>NV: Extract node parameters (modelId, prompt/text, options, etc.)
alt Text/Message Operations (Anthropic, Gemini, OpenAI v1/v2)
NV->>PV: validateMessages(messages, addAttachments)
PV->>PV: Filter out empty/whitespace-only messages
alt No non-empty messages AND no attachments
PV-->>NV: throw NodeOperationError("A non-empty prompt is required.")
else Has valid content
PV-->>NV: Return filtered messages
end
else Image/Video Generate Operations (all vendors)
NV->>PV: validatePrompt(prompt)
PV->>PV: Check prompt.trim() is non-empty
alt Prompt empty or whitespace-only
PV-->>NV: throw NodeOperationError("A non-empty prompt is required.")
else Valid prompt
PV-->>NV: Continue
end
else Analyze Operations (all vendors via baseAnalyze.ts)
NV->>PV: validateText(text)
PV->>PV: Check text.trim() is non-empty
alt Text empty or whitespace-only
PV-->>NV: throw NodeOperationError("A non-empty prompt is required.")
else Valid text
PV-->>NV: Continue
end
end
alt Validation PASSED
NV->>API: Make AI provider request (HTTP/HTTPS)
API-->>NV: Return AI response (success/error)
NV-->>WF: Return execution data
else Validation FAILED
NV-->>WF: NodeOperationError with itemIndex
Note over WF: Workflow fails fast at node level<br/>No API call made, no resource waste
end
Note over NV,PV: Special case: Anthropic allows empty messages when attachments are present
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Performance ComparisonComparing current → latest master → 14-day baseline docker-stats
Idle baseline with Instance AI module loaded
Memory consumption baseline with starter plan resources
How to read this table
|
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Backport of #30795 to
release-candidate/2.21.x.Checklist for the author (@alexander-gekov) to go through.
After this PR has been merged, it will be picked up in the next patch release for release track.
Original description
Summary
AI vendor nodes (Google Gemini, OpenAI, Anthropic) did not validate that user prompts are non-empty before sending requests to upstream APIs. Empty or whitespace-only prompts result in wasted API round-trips (400 errors from providers) and, when routed through the AI Gateway, waste proxy resources without any budget deduction.
This PR adds
trim() + empty checkwithNodeOperationErrorin each operation'sexecute()before the API call, ensuring workflows fail fast at the node level with a clear error message.Changes
Text message operations (Priority 1):
Generation operations (Priority 2):
Analyze operations (Priority 3):
baseAnalyze.tsbaseAnalyze.tsHow to test
NodeOperationErrorwith message "A non-empty prompt is required." instead of making an API callRelated Linear tickets, Github issues, and Community forum posts
https://linear.app/n8n/issue/NODE-5096
Review / Merge checklist
Backport to Beta,Backport to Stable, orBackport to v1(if the PR is an urgent fix that needs to be backported)🤖 PR Summary generated by AI
Made with Cursor