{"record":{"id":"b384bfcd1f58222e","repo":"n8n-io/n8n","slug":"failed-to-parse-query-error-as-error-message","errorCode":null,"errorMessage":"Failed to parse query: ${(error as Error).message}","messagePattern":"Failed to parse query: (.+?)","errorType":"exception","errorClass":"NodeOperationError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/ToolExecutor/ToolExecutor.node.ts","lineNumber":93,"sourceCode":"\t\t// If there are approved HITL tools, we need to execute the gated tools first\n\t\tconst hitlResult = processHitlResponses(response, 0);\n\n\t\tif (hitlResult.hasApprovedHitlTools && hitlResult.pendingGatedToolRequest) {\n\t\t\t// Return the gated tool request immediately\n\t\t\t// The Agent will resume after the gated tool executes\n\t\t\treturn hitlResult.pendingGatedToolRequest;\n\t\t}\n\n\t\tconst query = this.getNodeParameter('query', 0, {}) as string | object;\n\t\tconst toolName = this.getNodeParameter('toolName', 0, '') as string;\n\t\tconst node = this.getNodeParameter('node', 0, '') as string;\n\n\t\tlet parsedQuery: Record<string, unknown>;\n\n\t\ttry {\n\t\t\tparsedQuery = typeof query === 'string' ? JSON.parse(query) : query;\n\t\t} catch (error) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t`Failed to parse query: ${(error as Error).message}`,\n\t\t\t);\n\t\t}\n\n\t\tconst getQueryData = (name: string) => {\n\t\t\t// node names in query may have underscores in place of spaces, use it for accessing the query data.\n\t\t\treturn (get(parsedQuery, name, null) ?? get(parsedQuery, name.replaceAll(' ', '_'), null)) as\n\t\t\t\t| Record<string, unknown>\n\t\t\t\t| string\n\t\t\t\t| null;\n\t\t};\n\n\t\tconst resultData: INodeExecutionData[] = [];\n\t\tconst toolInputs = await this.getInputConnectionData(NodeConnectionTypes.AiTool, 0);\n\n\t\tif (!toolInputs || !Array.isArray(toolInputs)) {\n\t\t\tthrow new NodeOperationError(this.getNode(), 'No tool inputs found');","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/ToolExecutor/ToolExecutor.node.ts#L75-L111","documentation":"Thrown by the ToolExecutor node when the 'query' parameter is a string that fails JSON.parse. The node expects query to be either a JSON string or an object that maps tool names to their input arguments; unparseable text cannot be turned into that map.","triggerScenarios":"query = getNodeParameter('query', 0, {}) and if typeof query === 'string', JSON.parse(query) runs in a try/catch. A SyntaxError from JSON.parse triggers NodeOperationError 'Failed to parse query: <message>'. Fires when the user provides free text or malformed JSON in the query field.","commonSituations":"User types plain-language text into the query field instead of a JSON object; missing braces/quotes/commas in hand-written JSON; expression that resolves to undefined or non-JSON string; trailing commas.","solutions":["Provide query as a valid JSON object string, e.g. '{\"search\": {\"q\": \"n8n\"}}'.","If passing an object via an expression, ensure the expression yields an object, not its stringified-but-invalid form.","Use a Set node upstream to construct the query object and reference it.","Validate the JSON in a scratch tool before pasting it into the parameter."],"exampleFix":"// before: query = 'search for n8n'\n// after: query = '{ \"search\": { \"q\": \"n8n\" } }'","handlingStrategy":"validation","validationCode":"function asQueryObject(query) {\n  if (typeof query !== 'string') return query;\n  const obj = JSON.parse(query); // throws clearly if invalid\n  if (obj === null || typeof obj !== 'object') throw new Error('query must be a JSON object');\n  return obj;\n}","typeGuard":null,"tryCatchPattern":"try {\n  parsedQuery = typeof query === 'string' ? JSON.parse(query) : query;\n} catch (e) {\n  // surface a field-level validation error to the user with the offending text\n}","preventionTips":["Always provide query as a JSON object string.","Build the query object with a Set node and pass the object directly.","Validate JSON in a scratch tool before pasting into the parameter."],"tags":["tool-executor","json","parsing","config"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}