FlowiseAI/Flowise · error · Error
Invalid Flow State
Error message
Invalid Flow State
What it means
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).
Source
Thrown at packages/components/nodes/agentflow/Start/Start.ts:777
type: 'boolean',
description: 'Persist the state in the same session',
optional: true
}
]
}
async run(nodeData: INodeData, input: string | Record<string, any>, options: ICommonObject): Promise<any> {
const _flowState = nodeData.inputs?.startState as string
const startInputType = nodeData.inputs?.startInputType as string
const startEphemeralMemory = nodeData.inputs?.startEphemeralMemory as boolean
const startPersistState = nodeData.inputs?.startPersistState as boolean
let flowStateArray = []
if (_flowState) {
try {
flowStateArray = typeof _flowState === 'string' ? JSON.parse(_flowState) : _flowState
} catch (error) {
throw new Error('Invalid Flow State')
}
}
let flowState: Record<string, any> = {}
for (const state of flowStateArray) {
flowState[state.key] = state.value
}
const runtimeState = options.agentflowRuntime?.state as ICommonObject
if (startPersistState === true && runtimeState && Object.keys(runtimeState).length) {
for (const state in runtimeState) {
flowState[state] = runtimeState[state]
}
}
const inputData: ICommonObject = {}
const outputData: ICommonObject = {}
View on GitHub (pinned to abe4a8601a)
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)`.
Example fix
// before
} catch (error) {
throw new Error('Invalid Flow State')
}
// after
} catch (error) {
throw new Error(`Invalid Flow State: ${(error as Error).message}. Input: ${typeof _flowState === 'string' ? _flowState.slice(0, 120) : '<object>'}`)
} Defensive patterns
Strategy: validation
Validate before calling
const s = nodeData.inputs?.startState
if (typeof s === 'string' && s.trim() !== '') {
const parsed = JSON.parse(s) // throws here with a clear message if invalid
if (!Array.isArray(parsed)) throw new Error('startState must be a JSON array of {key,value}')
} Type guard
const isStateArray = (v: unknown): v is { key: string; value: unknown }[] =>
Array.isArray(v) && v.every((i) => i && typeof i.key === 'string') Try / catch
try {
await startNode.run(nodeData, input, options)
} catch (e) {
if ((e as Error).message === 'Invalid Flow State') {
// re-enter State as valid JSON [{"key":..,"value":..}]
}
throw e
} Prevention
- 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.
When it happens
Trigger: 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`).
Common situations: 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.
Related errors
- Invalid input array
- Model is required
- Tool not selected
- Invalid agentflow ID: must be a valid UUID
- Invalid base URL: must be a valid URL
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/4d40e0a3cd91670e.
Report an issue: GitHub.