{"record":{"id":"4d40e0a3cd91670e","repo":"FlowiseAI/Flowise","slug":"invalid-flow-state","errorCode":null,"errorMessage":"Invalid Flow State","messagePattern":"Invalid Flow State","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/agentflow/Start/Start.ts","lineNumber":777,"sourceCode":"                type: 'boolean',\n                description: 'Persist the state in the same session',\n                optional: true\n            }\n        ]\n    }\n\n    async run(nodeData: INodeData, input: string | Record<string, any>, options: ICommonObject): Promise<any> {\n        const _flowState = nodeData.inputs?.startState as string\n        const startInputType = nodeData.inputs?.startInputType as string\n        const startEphemeralMemory = nodeData.inputs?.startEphemeralMemory as boolean\n        const startPersistState = nodeData.inputs?.startPersistState as boolean\n\n        let flowStateArray = []\n        if (_flowState) {\n            try {\n                flowStateArray = typeof _flowState === 'string' ? JSON.parse(_flowState) : _flowState\n            } catch (error) {\n                throw new Error('Invalid Flow State')\n            }\n        }\n\n        let flowState: Record<string, any> = {}\n        for (const state of flowStateArray) {\n            flowState[state.key] = state.value\n        }\n\n        const runtimeState = options.agentflowRuntime?.state as ICommonObject\n        if (startPersistState === true && runtimeState && Object.keys(runtimeState).length) {\n            for (const state in runtimeState) {\n                flowState[state] = runtimeState[state]\n            }\n        }\n\n        const inputData: ICommonObject = {}\n        const outputData: ICommonObject = {}\n","sourceCodeStart":759,"sourceCodeEnd":795,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/agentflow/Start/Start.ts#L759-L795","documentation":"Start_Agentflow.run() parses the node's `startState` input into an array of {key,value} entries. When the input is a string, JSON.parse is attempted; if parsing throws, the node reports 'Invalid Flow State' rather than exposing the parse error. A valid-but-non-array result is not caught here (it would fail later at the for-loop).","triggerScenarios":"startState is a hand-edited string with a syntax error (trailing comma, unquoted key, single quotes), truncated JSON from a variable, or a string that is not JSON at all (e.g. `color=red`).","commonSituations":"User types state inline as `key=value` instead of JSON; copy-paste introduces smart quotes; a templating/variable step injects an unescaped value breaking the JSON; the field is bound to a runtime variable that returns `undefined` stringified poorly.","solutions":["Open the Start node and re-enter State as valid JSON: `[{\"key\":\"userId\",\"value\":\"123\"}]`.","Paste the current value into a JSON linter to find the syntax error.","If binding to a variable, ensure it produces a JSON string or pass an object (non-string is used directly without parsing).","Patch the catch to include the parse error message: `throw new Error('Invalid Flow State: ' + (error as Error).message)`."],"exampleFix":"// before\n            } catch (error) {\n                throw new Error('Invalid Flow State')\n            }\n// after\n            } catch (error) {\n                throw new Error(`Invalid Flow State: ${(error as Error).message}. Input: ${typeof _flowState === 'string' ? _flowState.slice(0, 120) : '<object>'}`)\n            }","handlingStrategy":"validation","validationCode":"const s = nodeData.inputs?.startState\nif (typeof s === 'string' && s.trim() !== '') {\n  const parsed = JSON.parse(s) // throws here with a clear message if invalid\n  if (!Array.isArray(parsed)) throw new Error('startState must be a JSON array of {key,value}')\n}","typeGuard":"const isStateArray = (v: unknown): v is { key: string; value: unknown }[] =>\n  Array.isArray(v) && v.every((i) => i && typeof i.key === 'string')","tryCatchPattern":"try {\n  await startNode.run(nodeData, input, options)\n} catch (e) {\n  if ((e as Error).message === 'Invalid Flow State') {\n    // re-enter State as valid JSON [{\"key\":..,\"value\":..}]\n  }\n  throw e\n}","preventionTips":["Always author State as JSON, never key=value text.","Lint the JSON in the editor before saving.","Bind to a variable that emits a real JSON string or object."],"tags":["agentflow","start-node","json-parse","validation","config"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}