microsoft/semantic-kernel · error · NotSupportedException
No function result provided in the tool message.
Error message
No function result provided in the tool message.
What it means
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.
Source
Thrown at dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs:787
var result = FunctionCalling.FunctionCallsProcessor.ProcessFunctionResult(resultContent.Result ?? string.Empty);
// OpenAI does not support multimodal tool results - return error message for ImageContent
if (result is ImageContent)
{
toolMessages.Add(new ToolChatMessage(resultContent.CallId, FunctionCalling.FunctionCallsProcessor.ImageContentNotSupportedErrorMessage));
continue;
}
toolMessages.Add(new ToolChatMessage(resultContent.CallId, (string?)result ?? string.Empty));
}
if (toolMessages is not null)
{
return toolMessages;
}
throw new NotSupportedException("No function result provided in the tool message.");
}
if (message.Role == AuthorRole.User)
{
if (message.Items is { Count: 1 } && message.Items.FirstOrDefault() is TextContent textContent)
{
return [new UserChatMessage(textContent.Text) { ParticipantName = message.AuthorName }];
}
return
[
new UserChatMessage(message.Items.Select(static (KernelContent item) => item switch
{
TextContent textContent => ChatMessageContentPart.CreateTextPart(textContent.Text),
ImageContent imageContent => GetImageContentItem(imageContent),
AudioContent audioContent => GetAudioContentItem(audioContent),
BinaryContent binaryContent => GetBinaryContentItem(binaryContent),
_ => throw new NotSupportedException($"Unsupported chat message content type '{item.GetType()}'.")View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before
history.Add(new ChatMessageContent(AuthorRole.Tool, "") { Metadata = new Dictionary<string,object?>() });
// after
history.Add(new ChatMessageContent(AuthorRole.Tool, "") {
Items = { new FunctionResultContent(callId, "ok") }
}); Defensive patterns
Strategy: validation
Validate before calling
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); } Type guard
static bool ToolMessageHasResult(ChatMessageContent m) => m.Role == AuthorRole.Tool && m.Items.OfType<FunctionResultContent>().Any();
Try / catch
try { await client.GetChatCompletionAsync(history); }
catch (NotSupportedException ex) when (ex.Message.Contains("No function result")) { /* attach a default result and retry */ } Prevention
- Always attach a FunctionResultContent to Tool messages.
- Use empty-string result rather than omitting it.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Data is not available for {cityName}.
- {nameof(executionSettings.ToolCallBehavior)} and {nameof(exe
- Unsupported function choice '{config.Choice}'.
- Function call required but no function steps found for agent
- Tool message found without a preceding message.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/ae8b1ed08ece01e7.
Report an issue: GitHub.