FlowiseAI/Flowise · error · Error
Condition function must return a string
Error message
Condition function must return a string
What it means
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.
Source
Thrown at packages/components/nodes/sequentialagents/ConditionAgent/ConditionAgent.ts:556
const variables = await getVars(appDataSource, databaseEntities, nodeData, options)
const flow = {
chatflowId: options.chatflowid,
sessionId: options.sessionId,
chatId: options.chatId,
input,
state,
output: result,
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 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`.
Example fix
// before conditionFunction = "return score > 0.5" // boolean -> throws [298] // after conditionFunction = "return score > 0.5 ? 'Positive' : 'Negative'"
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}`)
}
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
- 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.
When it happens
Trigger: The Condition Agent's condition function returns a non-string — typically the raw boolean from a comparison, a number, or omits `return`.
Common situations: User wrote `return result > 0` expecting branching; the function returns a classification object; forgot `return` on some code path.
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/83a92377557cfa92.
Report an issue: GitHub.