{"record":{"id":"ae8b1ed08ece01e7","repo":"microsoft/semantic-kernel","slug":"no-function-result-provided-in-the-tool-message-ae8b1e","errorCode":null,"errorMessage":"No function result provided in the tool message.","messagePattern":"No function result provided in the tool message\\.","errorType":"validation","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs","lineNumber":787,"sourceCode":"\n                var result = FunctionCalling.FunctionCallsProcessor.ProcessFunctionResult(resultContent.Result ?? string.Empty);\n\n                // OpenAI does not support multimodal tool results - return error message for ImageContent\n                if (result is ImageContent)\n                {\n                    toolMessages.Add(new ToolChatMessage(resultContent.CallId, FunctionCalling.FunctionCallsProcessor.ImageContentNotSupportedErrorMessage));\n                    continue;\n                }\n\n                toolMessages.Add(new ToolChatMessage(resultContent.CallId, (string?)result ?? string.Empty));\n            }\n\n            if (toolMessages is not null)\n            {\n                return toolMessages;\n            }\n\n            throw new NotSupportedException(\"No function result provided in the tool message.\");\n        }\n\n        if (message.Role == AuthorRole.User)\n        {\n            if (message.Items is { Count: 1 } && message.Items.FirstOrDefault() is TextContent textContent)\n            {\n                return [new UserChatMessage(textContent.Text) { ParticipantName = message.AuthorName }];\n            }\n\n            return\n            [\n                new UserChatMessage(message.Items.Select(static (KernelContent item) => item switch\n                    {\n                        TextContent textContent => ChatMessageContentPart.CreateTextPart(textContent.Text),\n                        ImageContent imageContent => GetImageContentItem(imageContent),\n                        AudioContent audioContent => GetAudioContentItem(audioContent),\n                        BinaryContent binaryContent => GetBinaryContentItem(binaryContent),\n                        _ => throw new NotSupportedException($\"Unsupported chat message content type '{item.GetType()}'.\")","sourceCodeStart":769,"sourceCodeEnd":805,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs#L769-L805","documentation":"Thrown when building the tool-message portion of the request: the code reached the Tool role branch, collected toolMessages, but that collection ended up null (no function-result content was produced). A Tool/Function message in OpenAI's protocol MUST carry the result of a prior tool call; without it the request is malformed and the API would reject it anyway.","triggerScenarios":"A ChatMessage with AuthorRole.Tool or a FunctionResultContent that has neither a result value nor any result content items, so no ToolChatMessage is appended and toolMessages stays null.","commonSituations":"Manually constructing chat history and forgetting to set the function result; a function returned null and the caller added an empty Tool message; streaming/agentic loops that drop the result step.","solutions":["Ensure every Tool-role message carries a FunctionResultContent with a non-null Result, or set message.Content.","If a function legitimately returns nothing, add FunctionResultContent with an empty string result instead of omitting it.","Do not push a Tool message whose Items contain no function result."],"exampleFix":"// before\nhistory.Add(new ChatMessageContent(AuthorRole.Tool, \"\") { Metadata = new Dictionary<string,object?>() });\n// after\nhistory.Add(new ChatMessageContent(AuthorRole.Tool, \"\") {\n    Items = { new FunctionResultContent(callId, \"ok\") }\n});","handlingStrategy":"validation","validationCode":"void AddToolResult(ChatHistory h, string callId, object? result) { var items = new ChatMessageContent(AuthorRole.Tool, string.Empty) { Items = { new FunctionResultContent(callId, result ?? string.Empty) } }; h.Add(items); }","typeGuard":"static bool ToolMessageHasResult(ChatMessageContent m) => m.Role == AuthorRole.Tool && m.Items.OfType<FunctionResultContent>().Any();","tryCatchPattern":"try { await client.GetChatCompletionAsync(history); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"No function result\")) { /* attach a default result and retry */ }","preventionTips":["Always attach a FunctionResultContent to Tool messages.","Use empty-string result rather than omitting it."],"tags":["openai","function-calling","chat-history","tool-message"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}