{"record":{"id":"0d220e0f50d8791d","repo":"FlowiseAI/Flowise","slug":"return-output-must-be-an-object","errorCode":null,"errorMessage":"Return output must be an object","messagePattern":"Return output must be an object","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/sequentialagents/Agent/Agent.ts","lineNumber":945,"sourceCode":"                let value = sch.value as string\n                if (value.startsWith('$flow')) {\n                    value = customGet(flow, sch.value.replace('$flow.', ''))\n                } else if (value.startsWith('$vars')) {\n                    value = customGet(flow, sch.value.replace('$', ''))\n                }\n                obj[key] = value\n            }\n            return obj\n        } catch (e) {\n            throw new Error(e)\n        }\n    } else if (selectedTab === 'updateStateMemoryCode' && updateStateMemoryCode) {\n        const sandbox = createCodeExecutionSandbox(input, variables, flow)\n\n        try {\n            const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox)\n\n            if (typeof response !== 'object') throw new Error('Return output must be an object')\n            return response\n        } catch (e) {\n            throw new Error(e)\n        }\n    }\n\n    return {}\n}\n\nconst convertCustomMessagesToBaseMessages = (messages: string[], name: string, additional_kwargs: ICommonObject) => {\n    return messages.map((message) => {\n        return new HumanMessage({\n            content: message,\n            name,\n            additional_kwargs: Object.keys(additional_kwargs).length ? additional_kwargs : undefined\n        })\n    })\n}","sourceCodeStart":927,"sourceCodeEnd":963,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/sequentialagents/Agent/Agent.ts#L927-L963","documentation":"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.","triggerScenarios":"The custom updateStateMemory code returns a primitive (string, number, boolean), undefined, or an array instead of an object literal.","commonSituations":"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).","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."],"exampleFix":"// before\nupdateStateMemoryCode = \"const r = compute(); return r\" // r is a string -> throws [288]\n\n// after\nupdateStateMemoryCode = \"const r = compute(); return { result: r }\"","handlingStrategy":"type-guard","validationCode":"function assertStateMemoryCodeResult(response) {\n  if (response === null || typeof response !== 'object' || Array.isArray(response)) {\n    throw new Error('updateStateMemoryCode must return a plain object, e.g. { key: value }')\n  }\n  return response\n}\n\n// in your sandbox wrapper\nconst response = await executeJavaScriptCode(updateStateMemoryCode, sandbox)\nassertStateMemoryCodeResult(response)","typeGuard":"function isPlainObject(v): v is Record<string, unknown> {\n  return v != null && typeof v === 'object' && !Array.isArray(v)\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["code-sandbox","state-memory","validation","configuration"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}