{"record":{"id":"41c4811f07caa6f4","repo":"n8n-io/n8n","slug":"tool-message-is-missing-a-tool-result-content-bloc","errorCode":null,"errorMessage":"Tool message is missing a tool-result content block","messagePattern":"Tool message is missing a tool-result content block","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/ai-utilities/src/converters/message.ts","lineNumber":356,"sourceCode":"\t\t\t\t.filter(isN8nToolCallBlock)\n\t\t\t\t.map((c) => ({\n\t\t\t\t\ttype: 'tool_call',\n\t\t\t\t\tid: c.toolCallId,\n\t\t\t\t\tname: c.toolName,\n\t\t\t\t\targs: jsonParse<Record<string, unknown>>(c.input, { fallbackValue: {} }),\n\t\t\t\t}));\n\t\t\tconst nonToolContent = lcContent.filter((c) => c.type !== 'tool_call');\n\t\t\treturn new LangchainMessages.AIMessage({\n\t\t\t\tcontent: nonToolContent,\n\t\t\t\tid: message.id,\n\t\t\t\tname: message.name,\n\t\t\t\ttool_calls: toolCalls.length > 0 ? toolCalls : undefined,\n\t\t\t});\n\t\t}\n\t\tcase 'tool': {\n\t\t\tconst toolResult = message.content.find(isN8nToolResultBlock);\n\t\t\tif (!toolResult) {\n\t\t\t\tthrow new Error('Tool message is missing a tool-result content block');\n\t\t\t}\n\t\t\tconst content =\n\t\t\t\ttypeof toolResult.result === 'string'\n\t\t\t\t\t? toolResult.result\n\t\t\t\t\t: JSON.stringify(toolResult.result);\n\t\t\treturn new LangchainMessages.ToolMessage({\n\t\t\t\tcontent,\n\t\t\t\ttool_call_id: toolResult.toolCallId,\n\t\t\t\tname: message.name,\n\t\t\t\tstatus: toolResult.isError ? 'error' : 'success',\n\t\t\t});\n\t\t}\n\t\tdefault:\n\t\t\treturn new LangchainMessages.HumanMessage({\n\t\t\t\tcontent: lcContent,\n\t\t\t\tid: message.id,\n\t\t\t\tname: message.name,\n\t\t\t});","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/ai-utilities/src/converters/message.ts#L338-L374","documentation":"In toLcMessage's `tool` role branch, a tool message is required to carry at least one tool-result content block (found via isN8nToolResultBlock). The Langchain ToolMessage needs a tool_call_id and content from that result; a tool message with only text/other blocks has no result to attach, so the converter rejects it rather than fabricating an empty ToolMessage.","triggerScenarios":"Constructing an n8n message with role:'tool' whose content array contains no tool-result block — e.g. only a text block, or content was stripped/filtered before conversion; a tool-reply pipeline that lost the result block in transit.","commonSituations":"A message-merging/trimming routine removed the tool-result block but kept role:'tool'; an LLM/provider adapter emitted a tool message with text only; truncation logic dropped tool blocks by type.","solutions":["Ensure every role:'tool' message includes a tool-result content block (isN8nToolResultBlock) with toolCallId and result.","When trimming conversation history, drop whole tool messages rather than stripping their result blocks.","If the result is genuinely missing, convert the message to role:'user' with text instead."],"exampleFix":"// before\n{ role: 'tool', content: [{ type: 'text', text: 'done' }] }\n\n// after\n{ role: 'tool', content: [{ type: 'tool_result', toolCallId: 'call_1', result: 'done' }] }","handlingStrategy":"validation","validationCode":"import { isN8nToolResultBlock } from '@n8n/ai-utilities';\nfunction hasToolResult(content: unknown[]): boolean {\n  return content.some(isN8nToolResultBlock);\n}\nif (msg.role === 'tool' && !hasToolResult(msg.content)) {\n  throw new Error('tool message must include a tool-result block');\n}","typeGuard":"function isToolMessageWithResult(m: { role: string; content: unknown[] }): boolean {\n  return m.role !== 'tool' || m.content.some(isN8nToolResultBlock);\n}","tryCatchPattern":null,"preventionTips":["Always attach a tool-result block (with toolCallId + result) when building role:'tool' messages.","When trimming history, drop whole tool messages, not their result blocks.","If the result is missing, convert the message to role:'user' instead."],"tags":["converters","langchain","tool-calls","messages"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}