FlowiseAI/Flowise · error · Error
Condition function must return a string
Error message
Condition function must return a string
What it means
On the `conditionFunction` branch, user JS executes in a sandbox and its return value is used to select the next graph branch — so it must be a string matching one of the Condition's output labels. `typeof response !== 'string'` rejects numbers, booleans, objects, and undefined before they reach the graph router.
Source
Thrown at packages/components/nodes/sequentialagents/Condition/Condition.ts:287
const selectedTab = tabIdentifier ? tabIdentifier.split(`_${nodeData.id}`)[0] : 'conditionUI'
const variables = await getVars(appDataSource, databaseEntities, nodeData, options)
const flow = {
chatflowId: options.chatflowid,
sessionId: options.sessionId,
chatId: options.chatId,
input,
state,
vars: prepareSandboxVars(variables)
}
if (selectedTab === 'conditionFunction' && conditionFunction) {
const sandbox = createCodeExecutionSandbox(input, variables, flow)
try {
const response = await executeJavaScriptCode(conditionFunction, sandbox)
if (typeof response !== 'string') throw new Error('Condition function must return a string')
return response
} catch (e) {
throw new Error(e)
}
} else if (selectedTab === 'conditionUI' && conditionUI) {
try {
const conditionItems: IConditionGridItem[] = typeof conditionUI === 'string' ? JSON.parse(conditionUI) : conditionUI
for (const item of conditionItems) {
if (!item.variable) throw new Error('Condition variable is required!')
if (item.variable.startsWith('$flow')) {
const variableValue = customGet(flow, item.variable.replace('$flow.', ''))
if (checkCondition(variableValue, item.operation, item.value)) {
return item.output
}
} else if (item.variable.startsWith('$vars')) {
const variableValue = customGet(flow, item.variable.replace('$', ''))View on GitHub (pinned to abe4a8601a)
Solutions
- Return one of the configured Condition output labels as a literal string — e.g. `return age > 18 ? 'Approved' : 'End'`.
- If the value is dynamic, coerce with `String(response)` and ensure it matches an output label.
- Verify the function always hits a `return` on every code path.
Example fix
// before conditionFunction = "return age > 18" // returns boolean -> throws [292] // after conditionFunction = "return age > 18 ? 'Approved' : 'End'"
Defensive patterns
Strategy: type-guard
Validate before calling
function assertConditionFunctionResult(response) {
if (typeof response !== 'string') {
throw new Error(`Condition function must return a string label, got ${typeof response}: ${JSON.stringify(response)}`)
}
return response
}
const result = await executeJavaScriptCode(conditionFunction, sandbox)
assertConditionFunctionResult(result) Type guard
function isConditionResult(v): v is string {
return typeof v === 'string' && v.length > 0
} Prevention
- Always return one of the configured output labels as a string literal.
- Avoid returning raw booleans from comparisons — map them to labels.
- Confirm every code path ends in a `return`.
When it happens
Trigger: The condition function returns a boolean (e.g. the raw comparison result), a number, an object, or omits `return` (undefined).
Common situations: User wrote `return age > 18` expecting it to branch, but the router needs a label; the function returns the variable itself instead of an output label; the function returns the result of a comparison operator (boolean).
Related errors
- Condition function must return a string
- Return output must be an object
- Model is required
- Model is required
- Scenarios are required
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/37a905ac4a333bc1.
Report an issue: GitHub.