{"record":{"id":"83a92377557cfa92","repo":"FlowiseAI/Flowise","slug":"condition-function-must-return-a-string-83a923","errorCode":null,"errorMessage":"Condition function must return a string","messagePattern":"Condition function must return a string","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/sequentialagents/ConditionAgent/ConditionAgent.ts","lineNumber":556,"sourceCode":"    const variables = await getVars(appDataSource, databaseEntities, nodeData, options)\n\n    const flow = {\n        chatflowId: options.chatflowid,\n        sessionId: options.sessionId,\n        chatId: options.chatId,\n        input,\n        state,\n        output: result,\n        vars: prepareSandboxVars(variables)\n    }\n\n    if (selectedTab === 'conditionFunction' && conditionFunction) {\n        const sandbox = createCodeExecutionSandbox(input, variables, flow)\n\n        try {\n            const response = await executeJavaScriptCode(conditionFunction, sandbox)\n\n            if (typeof response !== 'string') throw new Error('Condition function must return a string')\n            return response\n        } catch (e) {\n            throw new Error(e)\n        }\n    } else if (selectedTab === 'conditionUI' && conditionUI) {\n        try {\n            const conditionItems: IConditionGridItem[] = typeof conditionUI === 'string' ? JSON.parse(conditionUI) : conditionUI\n\n            for (const item of conditionItems) {\n                if (!item.variable) throw new Error('Condition variable is required!')\n\n                if (item.variable.startsWith('$flow')) {\n                    const variableValue = customGet(flow, item.variable.replace('$flow.', ''))\n                    if (checkCondition(variableValue, item.operation, item.value)) {\n                        return item.output\n                    }\n                } else if (item.variable.startsWith('$vars')) {\n                    const variableValue = customGet(flow, item.variable.replace('$', ''))","sourceCodeStart":538,"sourceCodeEnd":574,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/sequentialagents/ConditionAgent/ConditionAgent.ts#L538-L574","documentation":"ConditionAgent analog of error 292. On the `conditionFunction` branch, the sandbox return value selects the next graph branch and therefore must be a string. `typeof response !== 'string'` rejects booleans, numbers, objects, and undefined.","triggerScenarios":"The Condition Agent's condition function returns a non-string — typically the raw boolean from a comparison, a number, or omits `return`.","commonSituations":"User wrote `return result > 0` expecting branching; the function returns a classification object; forgot `return` on some code path.","solutions":["Return one of the configured output labels as a string literal — e.g. `return score > 0.5 ? 'Positive' : 'Negative'`.","Coerce with `String(response)` if the value is dynamic.","Make sure every code path hits a `return`."],"exampleFix":"// before\nconditionFunction = \"return score > 0.5\" // boolean -> throws [298]\n\n// after\nconditionFunction = \"return score > 0.5 ? 'Positive' : 'Negative'\"","handlingStrategy":"type-guard","validationCode":"function assertConditionFunctionResult(response) {\n  if (typeof response !== 'string') {\n    throw new Error(`Condition function must return a string label, got ${typeof response}`)\n  }\n  return response\n}\n\nconst result = await executeJavaScriptCode(conditionFunction, sandbox)\nassertConditionFunctionResult(result)","typeGuard":"function isConditionResult(v): v is string {\n  return typeof v === 'string' && v.length > 0\n}","tryCatchPattern":null,"preventionTips":["Return one of the configured output labels as a string literal.","Do not return raw booleans from comparisons — map to labels.","Make sure every code path returns."],"tags":["condition","code-sandbox","validation","configuration"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}