{"record":{"id":"2080c791283f57e2","repo":"FlowiseAI/Flowise","slug":"invalid-condition-exception-2080c7","errorCode":null,"errorMessage":"Invalid Condition: ${exception}","messagePattern":"Invalid Condition: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/sequentialagents/ConditionAgent/ConditionAgent.ts","lineNumber":595,"sourceCode":"                    }\n                } else if (item.variable.startsWith('$')) {\n                    const nodeId = item.variable.replace('$', '')\n\n                    const messageOutputs = ((state.messages as unknown as BaseMessage[]) ?? []).filter(\n                        (message) => message.additional_kwargs && message.additional_kwargs?.nodeId === nodeId\n                    )\n                    const messageOutput = messageOutputs[messageOutputs.length - 1]\n\n                    if (messageOutput) {\n                        if (checkCondition(messageOutput.content as string, item.operation, item.value)) {\n                            return item.output\n                        }\n                    }\n                }\n            }\n            return 'End'\n        } catch (exception) {\n            throw new Error('Invalid Condition: ' + exception)\n        }\n    }\n}\n\nmodule.exports = { nodeClass: ConditionAgent_SeqAgents }\n","sourceCodeStart":577,"sourceCodeEnd":601,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/sequentialagents/ConditionAgent/ConditionAgent.ts#L577-L601","documentation":"Catch-all thrown by the Condition node's UI-grid evaluator (conditionUI branch). Any inner failure during condition evaluation — JSON.parse of the grid, customGet on a $flow/$vars path, checkCondition's type coercion, or casting messageOutput.content to string — is caught and re-thrown with the prefix 'Invalid Condition: ' plus the original exception. The wrapper preserves the root cause in its suffix, so read the appended text to find the real failure.","triggerScenarios":"The conditionUI value is a non-empty string that fails JSON.parse; a grid item.variable is undefined (caught by the explicit 'Condition variable is required!' check, then re-wrapped); a $nodeId reference points to a node that emitted no message so messageOutput is undefined and later coerced; checkCondition receives a content value that is an array/object (multi-part LLM content) cast with `as string`; an unsupported operation string reaches the switch in checkCondition.","commonSituations":"Editing the condition grid in the UI then deploying untested; renaming or deleting an upstream sequential node so a $nodeId reference dangles; an upstream LLM returning multimodal/array content that is no longer a plain string; hand-editing the exported chatflow JSON and corrupting the conditionUI array.","solutions":["Read the text appended after 'Invalid Condition: ' — it names the real error (SyntaxError for JSON, TypeError for a bad cast, etc.).","Validate the conditionUI JSON in a linter; confirm it is an array of {variable, operation, value, output} items.","For every item.variable starting with '$', confirm the referenced nodeId still exists and produced a message in state.messages.","If the upstream node emits array/object content, flatten it to a string before it reaches the comparison, or reference a $flow./$vars. scalar instead."],"exampleFix":"// before: casts multi-part content to string, throws on .content being an array\nif (checkCondition(messageOutput.content as string, item.operation, item.value)) { return item.output }\n\n// after: normalize content to a string first\nconst raw = messageOutput.content\nconst text = typeof raw === 'string' ? raw : Array.isArray(raw) ? raw.map(p => typeof p === 'string' ? p : p?.text ?? '').join('') : String(raw ?? '')\nif (checkCondition(text, item.operation, item.value)) { return item.output }","handlingStrategy":"try-catch","validationCode":"function validateConditionGrid(conditionUI: unknown): {variable:string;operation:string;value:any;output:string}[] {\n  const items = typeof conditionUI === 'string' ? JSON.parse(conditionUI) : conditionUI\n  if (!Array.isArray(items)) throw new Error('conditionUI must be an array')\n  return items.map((it, i) => {\n    if (!it || !it.variable) throw new Error(`Row ${i}: variable is required`)\n    return it\n  })\n}","typeGuard":"const isConditionItem = (x: any): x is {variable:string;operation:string;value:any;output:string} =>\n  !!x && typeof x === 'object' && typeof x.variable === 'string' && typeof x.operation === 'string'","tryCatchPattern":"try {\n  // evaluate condition grid\n} catch (e) {\n  // unwrap the 'Invalid Condition: <inner>' prefix to inspect the real cause\n  const inner = String(e?.message ?? e).replace(/^Invalid Condition:\\s*/, '')\n  logger.error({ inner }, 'condition evaluation failed')\n  throw e\n}","preventionTips":["Always validate the conditionUI JSON and each item's variable field before deploying.","Keep upstream node ids stable — never rename/delete a node that a $-reference points at without updating the grid.","Treat multi-part LLM content as potentially non-string and normalize before comparison."],"tags":["sequential-agents","condition","validation","error-wrapping"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}