{"record":{"id":"38e0351b03ef4f78","repo":"n8n-io/n8n","slug":"wrong-output-type-returned","errorCode":null,"errorMessage":"Wrong output type returned","messagePattern":"Wrong output type returned","errorType":"exception","errorClass":"NodeOperationError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.ts","lineNumber":245,"sourceCode":"\tprivate handleToolResponse(response: unknown): string {\n\t\tif (typeof response === 'number') {\n\t\t\treturn response.toString();\n\t\t}\n\n\t\tif (isNodeExecutionData(response)) {\n\t\t\treturn JSON.stringify(\n\t\t\t\tresponse.map((item) => item.json),\n\t\t\t\tnull,\n\t\t\t\t2,\n\t\t\t);\n\t\t}\n\n\t\tif (isObject(response)) {\n\t\t\treturn JSON.stringify(response, null, 2);\n\t\t}\n\n\t\tif (typeof response !== 'string') {\n\t\t\tthrow new NodeOperationError(this.baseContext.getNode(), 'Wrong output type returned', {\n\t\t\t\tdescription: `The response property should be a string, but it is an ${typeof response}`,\n\t\t\t});\n\t\t}\n\n\t\treturn response;\n\t}\n\n\t/**\n\t * Executes specified sub-workflow with provided inputs\n\t */\n\tprivate async executeSubWorkflow(\n\t\tcontext: ISupplyDataFunctions | IExecuteFunctions,\n\t\tworkflowInfo: IExecuteWorkflowInfo,\n\t\titems: INodeExecutionData[],\n\t\tworkflowProxy: IWorkflowDataProxyData,\n\t\trunManager?: CallbackManagerForToolRun,\n\t): Promise<{ response: IDataObject | INodeExecutionData[]; subExecutionId: string }> {\n\t\tlet receivedData: ExecuteWorkflowData;","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.ts#L227-L263","documentation":"Thrown by WorkflowToolService.handleToolResponse (v2) when the sub-workflow response is not a number, not an INodeExecutionData[], not an object, and not a string — i.e. it is a boolean, function, symbol, bigint, or similar. The tool must serialize the response to a string for the agent, and it has no serializer for these types.","triggerScenarios":"A sub-workflow whose terminal node returns a boolean or bigint as the json value; returnAllItems=true with a non-array, non-object payload; an edge case where the response is a function/symbol from a misbehaving custom node.","commonSituations":"Sub-workflows returning a bare boolean (true/false) as the answer; numeric/bigint counters; exotic types produced by Code nodes that return non-JSON values.","solutions":["In the sub-workflow, convert the final value to a string or object before the terminal node (e.g. a Set node with String(value)).","Ensure the terminal node always emits a plain JSON-shaped item (string/number/object/array).","If returning all items, make sure the output is an array of { json: ... } items."],"exampleFix":"// before: sub-workflow returns { json: { result: true } } and only `true` is read → boolean → throws\n// after: wrap it\n{ json: { response: 'Yes' } }\n// or stringify in a Code node: return [{ json: { response: String(items[0].json.flag) } }];","handlingStrategy":"type-guard","validationCode":"if (typeof response !== 'string' && typeof response !== 'number' && !isObject(response) && !isNodeExecutionData(response)) {\n  response = String(response); // coerce before handleToolResponse\n}","typeGuard":"function isToolSerializable(v: unknown): v is string | number | object | INodeExecutionData[] {\n  return ['string','number','object'].includes(typeof v) && v !== null;\n}","tryCatchPattern":"try { return this.handleToolResponse(response); }\ncatch (e) { return String(response); }","preventionTips":["Make sub-workflow terminal nodes emit string/number/object/array payloads only.","Avoid returning bare booleans/bigints from Code nodes.","Add a final Set node that normalizes the output shape."],"tags":["workflow-tool","ai-tool","type-mismatch","response-handling"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}