{"record":{"id":"acdb976ed9969374","repo":"FlowiseAI/Flowise","slug":"invalid-json-in-the-custom-function-input-variable","errorCode":null,"errorMessage":"Invalid JSON in the Custom Function Input Variables: ${exception}","messagePattern":"Invalid JSON in the Custom Function Input Variables: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/sequentialagents/CustomFunction/CustomFunction.ts","lineNumber":119,"sourceCode":"        if (!sequentialNodes || !sequentialNodes.length) throw new Error('Custom function must have a predecessor!')\n\n        const executeFunc = async (state: ISeqAgentsState) => {\n            const variables = await getVars(appDataSource, databaseEntities, nodeData, options)\n            const flow = {\n                chatflowId: options.chatflowid,\n                sessionId: options.sessionId,\n                chatId: options.chatId,\n                input,\n                state\n            }\n\n            let inputVars: ICommonObject = {}\n            if (functionInputVariablesRaw) {\n                try {\n                    inputVars =\n                        typeof functionInputVariablesRaw === 'object' ? functionInputVariablesRaw : JSON.parse(functionInputVariablesRaw)\n                } catch (exception) {\n                    throw new Error('Invalid JSON in the Custom Function Input Variables: ' + exception)\n                }\n            }\n\n            // Some values might be a stringified JSON, parse it\n            for (const key in inputVars) {\n                let value = inputVars[key]\n                if (typeof value === 'string') {\n                    value = handleEscapeCharacters(value, true)\n                    if (value.startsWith('{') && value.endsWith('}')) {\n                        try {\n                            value = JSON.parse(value)\n                            const nodeId = value.id || ''\n                            if (nodeId) {\n                                const messages = state.messages as unknown as BaseMessage[]\n                                const content = messages.find((msg) => msg.additional_kwargs?.nodeId === nodeId)?.content\n                                if (content) {\n                                    value = content\n                                }","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/sequentialagents/CustomFunction/CustomFunction.ts#L101-L137","documentation":"The Custom Function's 'Input Variables' field is parsed at runtime (inside executeFunc) with JSON.parse when it is a string. If the string is not valid JSON, the SyntaxError is caught and re-thrown with this prefix. This is a runtime error, not an init error — it surfaces only when the node actually executes.","triggerScenarios":"functionInputVariablesRaw is a non-empty string containing a trailing comma, unquoted key, smart/curly quotes, a truncated value, or single quotes instead of double quotes; the field was hand-typed instead of using the structured editor.","commonSituations":"Pasting JSON from documentation that introduced smart quotes; partial edit left mid-typing before a test run; exporting then re-importing a flow with mangled escaping.","solutions":["Paste the current Input Variables value into a JSON linter (e.g. jsonlint.com) and fix the reported syntax error.","Prefer the structured Input Variables editor over raw JSON so the field is always a valid object.","For a single variable, use the minimal shape {\"name\":\"value\"}."],"exampleFix":"// before (throws)\n{\"theme\": \"sales\", \"limit\": 5,}\n\n// after\n{\"theme\": \"sales\", \"limit\": 5}","handlingStrategy":"validation","validationCode":"function parseInputVars(raw: unknown): Record<string, unknown> {\n  if (!raw) return {}\n  const obj = typeof raw === 'string' ? JSON.parse(raw) : raw\n  if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) throw new Error('Input Variables must be a JSON object')\n  return obj as Record<string, unknown>\n}","typeGuard":"const isInputVarsObject = (x: any): x is Record<string, unknown> =>\n  typeof x === 'object' && x !== null && !Array.isArray(x)","tryCatchPattern":"try { JSON.parse(functionInputVariablesRaw) } catch (e) { throw new Error('Input Variables JSON invalid: ' + e.message) }","preventionTips":["Prefer the structured Input Variables editor over raw JSON.","Lint any hand-authored JSON before pasting into the field."],"tags":["json","custom-function","input-variables","runtime"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}