FlowiseAI/Flowise · error · Error
Return output must be an object
Error message
Return output must be an object
What it means
The 'Update State Memory (Code)' tab runs sandboxed JS whose return value is merged into agent state; it must be an object so its keys become state properties. A non-object return (string, number, boolean, undefined) throws. The executed code and the type check both live inside the try block, so a thrown JS error is also re-wrapped by the catch.
Source
Thrown at packages/components/nodes/sequentialagents/LLMNode/LLMNode.ts:719
let value = sch.value as string
if (value.startsWith('$flow')) {
value = customGet(flow, sch.value.replace('$flow.', ''))
} else if (value.startsWith('$vars')) {
value = customGet(flow, sch.value.replace('$', ''))
}
obj[key] = value
}
return obj
} catch (e) {
throw new Error(e)
}
} else if (selectedTab === 'updateStateMemoryCode' && updateStateMemoryCode) {
const sandbox = createCodeExecutionSandbox(input, variables, flow)
try {
const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox)
if (typeof response !== 'object') throw new Error('Return output must be an object')
return response
} catch (e) {
throw new Error(e)
}
}
}
module.exports = { nodeClass: LLMNode_SeqAgents }
View on GitHub (pinned to abe4a8601a)
Solutions
- Ensure every code path returns an object literal, e.g. return { result: value }.
- If producing a single scalar, wrap it: return { score: n }.
- If returning a JSON string, parse it first: return JSON.parse(str).
Example fix
// before (throws: returns a string)
return JSON.stringify({ topic: input })
// after
return { topic: input } Defensive patterns
Strategy: type-guard
Validate before calling
const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox)
if (response === null || typeof response !== 'object' || Array.isArray(response)) {
throw new Error('Update State Memory code must return a plain object')
} Type guard
const isPlainObject = (x: any): x is Record<string, unknown> => typeof x === 'object' && x !== null && !Array.isArray(x)
Prevention
- Always return an object literal from the code snippet.
- If computing a scalar, wrap it: return { result: value }.
- Never return JSON.stringify(...) — return the parsed object.
When it happens
Trigger: updateStateMemoryCode returns a primitive (e.g. a computed number or string), returns undefined (missing/empty return), or returns a JSON string instead of a parsed object.
Common situations: Code returns JSON.stringify(obj) instead of obj; a code path ends without a return; the snippet was written to print/log rather than return.
Related errors
- Key is required
- Custom function must return an object!
- Custom function must return a string!
- Aborted!
- Failed to load fs/promises. Make sure you are running in Nod
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/1a9358063e420e6b.
Report an issue: GitHub.