FlowiseAI/Flowise · error · Error

Invalid JSON in the Custom Function Input Variables: ${excep

Error message

Invalid JSON in the Custom Function Input Variables: ${exception}

What it means

Thrown by CustomFunction_Utilities.init when JSON.parse fails on `functionInputVariablesRaw`. The field is parsed only when it is a non-object (a JSON string); objects are passed through. Any invalid JSON string aborts custom-function execution before the sandbox is built.

Source

Thrown at packages/components/nodes/utilities/CustomFunction/CustomFunction.ts:105

            input,
            chatflowId: options.chatflowid,
            sessionId: options.sessionId,
            chatId: options.chatId,
            rawOutput: options.postProcessing?.rawOutput || '',
            chatHistory: options.postProcessing?.chatHistory || [],
            sourceDocuments: options.postProcessing?.sourceDocuments,
            usedTools: options.postProcessing?.usedTools,
            artifacts: options.postProcessing?.artifacts,
            fileAnnotations: options.postProcessing?.fileAnnotations
        }

        let inputVars: ICommonObject = {}
        if (functionInputVariablesRaw) {
            try {
                inputVars =
                    typeof functionInputVariablesRaw === 'object' ? functionInputVariablesRaw : JSON.parse(functionInputVariablesRaw)
            } catch (exception) {
                throw new Error('Invalid JSON in the Custom Function Input Variables: ' + exception)
            }
        }

        // Some values might be a stringified JSON, parse it
        for (const key in inputVars) {
            let value = inputVars[key]
            if (typeof value === 'string') {
                value = handleEscapeCharacters(value, true)
                if (value.startsWith('{') && value.endsWith('}')) {
                    try {
                        value = JSON.parse(value)
                    } catch (e) {
                        // ignore
                    }
                }
                inputVars[key] = value
            }
        }

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Validate the JSON in an external linter before pasting into the node.
  2. Use the Flowise JSON editor's validation (if available) or a JSON editor extension.
  3. If the value is already an object at runtime, pass it as an object — the code skips JSON.parse for objects.
  4. Trim/escape the string and retry.

Example fix

// before (malformed)
functionInputVariablesRaw = "{ key: 'value', }" // throws: Invalid JSON ...

// after (valid)
functionInputVariablesRaw = '{"key":"value"}'
Defensive patterns

Strategy: validation

Validate before calling

function parseInputVars(raw: unknown): Record<string, unknown> {
  if (raw == null) return {}
  if (typeof raw === 'object') return raw as Record<string, unknown>
  try { return JSON.parse(raw as string) }
  catch (e) { throw new Error(`functionInputVariables is not valid JSON: ${(e as Error).message}`) }
}
// validate before the node runs
const inputVars = parseInputVars(functionInputVariablesRaw)

Type guard

const isParsableJsonObject = (v: unknown): boolean => {
  if (typeof v === 'object' && v !== null) return true
  if (typeof v !== 'string') return false
  try { return typeof JSON.parse(v) === 'object' && JSON.parse(v) !== null } catch { return false }
}

Try / catch

try { JSON.parse(functionInputVariablesRaw as string) }
catch (e) { throw new Error(`Fix the Custom Function Input Variables JSON: ${(e as Error).message}`) }

Prevention

When it happens

Trigger: A user enters malformed JSON in the Custom Function node's Input Variables editor (trailing comma, unquoted keys, single quotes, stray characters); a flow variable returns a partial/cut-off JSON string; copy-paste introduced smart quotes.

Common situations: Hand-typed JSON in the node config with a syntax error; JSON truncated by a length limit upstream; mixed quote styles from a word processor; a variable resolved to a non-JSON string at runtime.

Understand the failure class

Related errors


AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12). Data as JSON: /api/errors/d55480c2e6ec9bf2. Report an issue: GitHub.