{"record":{"id":"010796171fb3d966","repo":"n8n-io/n8n","slug":"input-is-not-a-valid-json-error-message","errorCode":null,"errorMessage":"Input is not a valid JSON: ${error.message}","messagePattern":"Input is not a valid JSON: (.+?)","errorType":"exception","errorClass":"NodeOperationError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/utils.ts","lineNumber":735,"sourceCode":"\t\tlet response: string = '';\n\t\tlet executionError: Error | undefined = undefined;\n\n\t\tif (!toolParameters.length) {\n\t\t\tquery = '{}';\n\t\t}\n\n\t\ttry {\n\t\t\tif (query) {\n\t\t\t\tlet dataFromModel;\n\n\t\t\t\tif (typeof query === 'string') {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tdataFromModel = jsonParse<IDataObject>(query);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (toolParameters.length === 1) {\n\t\t\t\t\t\t\tdataFromModel = { [toolParameters[0].name]: query };\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new NodeOperationError(\n\t\t\t\t\t\t\t\tctx.getNode(),\n\t\t\t\t\t\t\t\t`Input is not a valid JSON: ${error.message}`,\n\t\t\t\t\t\t\t\t{ itemIndex },\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tdataFromModel = query;\n\t\t\t\t}\n\n\t\t\t\tfor (const parameter of toolParameters) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tparameter.required &&\n\t\t\t\t\t\t(dataFromModel[parameter.name] === undefined || dataFromModel[parameter.name] === null)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthrow new NodeOperationError(\n\t\t\t\t\t\t\tctx.getNode(),\n\t\t\t\t\t\t\t`Model did not provide parameter '${parameter.name}' which is required and must be present in the input`,","sourceCodeStart":717,"sourceCodeEnd":753,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/utils.ts#L717-L753","documentation":"Thrown by configureToolFunction in the AI HTTP Request tool when the model's query string fails to parse as JSON AND the tool defines more than one parameter. With exactly one parameter the tool is lenient and wraps the raw string, but with multiple parameters it cannot guess the mapping and aborts.","triggerScenarios":"An LLM returns plain text or malformed JSON (unquoted keys, trailing commas, single quotes) as the tool call argument when the tool schema declares 2+ parameters; the model ignores the 'stringified JSON object' instruction in the tool description.","commonSituations":"Weaker models that hallucinate argument formats; long parameter lists that confuse the model; prompt/description edits that drop the JSON requirement; tool calling with a non-structured-tool agent.","solutions":["Reduce the number of required parameters or consolidate them so the single-parameter lenient path applies.","Improve the tool's description to emphasize 'valid stringified JSON object with these properties'.","Switch to a stronger model or use the structured-tool (DynamicStructuredTool) schema path so the agent framework enforces JSON.","Pre-validate the model output and re-prompt on malformed JSON."],"exampleFix":"// before: model returns 'search tomatoes' for a 2-param tool → throws\n// after: enforce schema with a structured tool so the framework serializes args\n// (use the node's 'Specify Input Schema' option, or reduce to one parameter)\n\n// defensive parse in custom code:\nlet data;\ntry { data = JSON.parse(query); }\ncatch { data = { param1: query }; /* single-param fallback */ }","handlingStrategy":"try-catch","validationCode":"let dataFromModel: IDataObject;\nif (typeof query === 'string') {\n  try { dataFromModel = JSON.parse(query); }\n  catch {\n    if (toolParameters.length === 1) dataFromModel = { [toolParameters[0].name]: query };\n    else throw new Error('Provide a valid JSON object with all parameters');\n  }\n} else dataFromModel = query as IDataObject;","typeGuard":"function isParsableJson(s: string): boolean {\n  try { JSON.parse(s); return true; } catch { return false; }\n}","tryCatchPattern":"try { dataFromModel = jsonParse<IDataObject>(query); }\ncatch (e) { /* single-param fallback or re-prompt the model */ }","preventionTips":["Keep tool parameter count low or use a structured-tool schema.","Re-prompt the model with the parse error so it can self-correct.","Include an explicit 'must be valid JSON' clause in the tool description."],"tags":["ai-tool","llm-input","json","http-request-tool","model-validation"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}