FlowiseAI/Flowise · error · Error
Return output must be an object
Error message
Return output must be an object
What it means
Thrown on the code-sandbox branch of `getUpdateStateMemory` (`selectedTab === 'updateStateMemoryCode'`). User-supplied JS runs via `executeJavaScriptCode` in a sandbox; the response is merged into state memory with `Object.assign`-style semantics, so it must be a plain object. `typeof response !== 'object'` rejects strings, numbers, booleans, and undefined.
Source
Thrown at packages/components/nodes/sequentialagents/Agent/Agent.ts:945
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)
}
}
return {}
}
const convertCustomMessagesToBaseMessages = (messages: string[], name: string, additional_kwargs: ICommonObject) => {
return messages.map((message) => {
return new HumanMessage({
content: message,
name,
additional_kwargs: Object.keys(additional_kwargs).length ? additional_kwargs : undefined
})
})
}View on GitHub (pinned to abe4a8601a)
Solutions
- Make the sandbox code `return { ... }` an object literal keyed by the state fields you want to set.
- Wrap any primitive in an object, e.g. `return { value: result }`.
- Verify the return value with `console.log(typeof response)` while debugging.
Example fix
// before
updateStateMemoryCode = "const r = compute(); return r" // r is a string -> throws [288]
// after
updateStateMemoryCode = "const r = compute(); return { result: r }" Defensive patterns
Strategy: type-guard
Validate before calling
function assertStateMemoryCodeResult(response) {
if (response === null || typeof response !== 'object' || Array.isArray(response)) {
throw new Error('updateStateMemoryCode must return a plain object, e.g. { key: value }')
}
return response
}
// in your sandbox wrapper
const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox)
assertStateMemoryCodeResult(response) Type guard
function isPlainObject(v): v is Record<string, unknown> {
return v != null && typeof v === 'object' && !Array.isArray(v)
} Prevention
- Always return an object literal `{ ... }` from updateStateMemoryCode.
- Wrap primitives: `return { value: x }` instead of `return x`.
- Test the sandbox snippet standalone before wiring it into the node.
When it happens
Trigger: The custom updateStateMemory code returns a primitive (string, number, boolean), undefined, or an array instead of an object literal.
Common situations: User wrote `return result` where `result` is a string; forgot the return statement entirely (returns undefined); returned an array thinking it would be spread into state; returned null (typeof null === 'object' but downstream code throws on null access).
Related errors
- Condition function must return a string
- Condition function must return a string
- Model is required
- Model is required
- Scenarios are required
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/0d220e0f50d8791d.
Report an issue: GitHub.