{"record":{"id":"1a9358063e420e6b","repo":"FlowiseAI/Flowise","slug":"return-output-must-be-an-object-1a9358","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/LLMNode/LLMNode.ts","lineNumber":719,"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\nmodule.exports = { nodeClass: LLMNode_SeqAgents }\n","sourceCodeStart":701,"sourceCodeEnd":728,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/sequentialagents/LLMNode/LLMNode.ts#L701-L728","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before (throws: returns a string)\nreturn JSON.stringify({ topic: input })\n\n// after\nreturn { topic: input }","handlingStrategy":"type-guard","validationCode":"const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox)\nif (response === null || typeof response !== 'object' || Array.isArray(response)) {\n  throw new Error('Update State Memory code must return a plain object')\n}","typeGuard":"const isPlainObject = (x: any): x is Record<string, unknown> =>\n  typeof x === 'object' && x !== null && !Array.isArray(x)","tryCatchPattern":null,"preventionTips":["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."],"tags":["llm-node","state-memory","code","return-type","runtime"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}