microsoft/semantic-kernel · error · NotSupportedException
Unsupported chat message content type '{item.GetType()}'.
Error message
Unsupported chat message content type '{item.GetType()}'. What it means
Thrown inside the multi-part User message builder. It maps each KernelContent item to an OpenAI content part for TextContent, ImageContent, AudioContent, and BinaryContent. Any other KernelContent-derived type (e.g. FunctionCallContent, a custom content subclass) has no wire representation in a user message, so it is rejected.
Source
Thrown at dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs:805
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()}'.")
}))
{ ParticipantName = message.AuthorName }
];
}
if (message.Role == AuthorRole.Assistant)
{
var toolCalls = new List<ChatToolCall>();
// Handling function calls supplied via either:
// ChatCompletionsToolCall.ToolCalls collection items or
// ChatMessageContent.Metadata collection item with 'ChatResponseMessage.FunctionToolCalls' key.
IEnumerable<ChatToolCall>? tools = (message as OpenAIChatMessageContent)?.ToolCalls;
if (tools is null && message.Metadata?.TryGetValue(OpenAIChatMessageContent.FunctionToolCallsProperty, out object? toolCallsObject) is true)
{
tools = toolCallsObject as IEnumerable<ChatToolCall>;
if (tools is null && toolCallsObject is JsonElement { ValueKind: JsonValueKind.Array } array)
{View on GitHub (pinned to c028a0c7dc)
Solutions
- Keep user-role Items limited to TextContent, ImageContent, AudioContent, and BinaryContent.
- Move function-call content to an Assistant-role message instead.
- If you have a custom content type, flatten it to TextContent before adding to a user message.
Example fix
// before
userMsg.Items.Add(new FunctionCallContent("foo", "bar"));
// after
userMsg.Items.Add(new TextContent("called foo")); Defensive patterns
Strategy: type-guard
Validate before calling
static bool IsSupportedUserContent(KernelContent c) => c is TextContent or ImageContent or AudioContent or BinaryContent;
Type guard
static bool UserItemsAllSupported(ChatMessageContent m) => m.Role == AuthorRole.User && m.Items.All(IsSupportedUserContent);
Try / catch
try { await client.GetChatCompletionAsync(history); }
catch (NotSupportedException ex) when (ex.Message.Contains("content type")) { /* strip unsupported items */ } Prevention
- Keep user-role Items limited to the four mapped content types.
- Move FunctionCallContent to assistant messages.
When it happens
Trigger: A user-role ChatMessageContent whose Items collection contains a content type other than the four supported ones — for example a FunctionCallContent or a custom content class added to the items list.
Common situations: Reusing a message's Items collection across roles; programmatically merging function-call content into a user message; third-party content extensions not yet mapped by the connector.
Related errors
- Failed to get a response from the chat completion service.
- The provided reasoning effort '{textEffortLevel}' is not sup
- The provided reasoning effort '{effortLevelObject.GetType()}
- The provided web search options '{executionSettings.WebSearc
- Role {message.Role} is not supported.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/3f4432c8f2dda8c1.
Report an issue: GitHub.