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
- Validate the JSON in an external linter before pasting into the node.
- Use the Flowise JSON editor's validation (if available) or a JSON editor extension.
- If the value is already an object at runtime, pass it as an object — the code skips JSON.parse for objects.
- 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
- Use a JSON editor with syntax validation for node config.
- If the value is already an object, pass it as an object to skip parsing.
- Lint input-variable JSON in CI for flows stored as code.
- Avoid copy-pasting from rich-text editors that introduce smart quotes.
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
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Invalid JSON in the Chat NVIDIA NIM's baseOptions: ${excepti
- Invalid JSON in the IfElse's Input Variables: ${exception}
- Invalid JSON in the ChatOpenAI's BaseOptions: ${exception}
- Invalid JSON in the ChatOpenAI's BaseOptions: ${exception}
- Invalid JSON in the ChatOpenRouter's BaseOptions: ${exceptio
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/d55480c2e6ec9bf2.
Report an issue: GitHub.