{"record":{"id":"3f4432c8f2dda8c1","repo":"microsoft/semantic-kernel","slug":"unsupported-chat-message-content-type-item-getty","errorCode":null,"errorMessage":"Unsupported chat message content type '{item.GetType()}'.","messagePattern":"Unsupported chat message content type '(.+?)'\\.","errorType":"validation","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs","lineNumber":805,"sourceCode":"            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()}'.\")\n                    }))\n                { ParticipantName = message.AuthorName }\n            ];\n        }\n\n        if (message.Role == AuthorRole.Assistant)\n        {\n            var toolCalls = new List<ChatToolCall>();\n\n            // Handling function calls supplied via either:\n            // ChatCompletionsToolCall.ToolCalls collection items or\n            // ChatMessageContent.Metadata collection item with 'ChatResponseMessage.FunctionToolCalls' key.\n            IEnumerable<ChatToolCall>? tools = (message as OpenAIChatMessageContent)?.ToolCalls;\n            if (tools is null && message.Metadata?.TryGetValue(OpenAIChatMessageContent.FunctionToolCallsProperty, out object? toolCallsObject) is true)\n            {\n                tools = toolCallsObject as IEnumerable<ChatToolCall>;\n                if (tools is null && toolCallsObject is JsonElement { ValueKind: JsonValueKind.Array } array)\n                {","sourceCodeStart":787,"sourceCodeEnd":823,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs#L787-L823","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nuserMsg.Items.Add(new FunctionCallContent(\"foo\", \"bar\"));\n// after\nuserMsg.Items.Add(new TextContent(\"called foo\"));","handlingStrategy":"type-guard","validationCode":"static bool IsSupportedUserContent(KernelContent c) => c is TextContent or ImageContent or AudioContent or BinaryContent;","typeGuard":"static bool UserItemsAllSupported(ChatMessageContent m) => m.Role == AuthorRole.User && m.Items.All(IsSupportedUserContent);","tryCatchPattern":"try { await client.GetChatCompletionAsync(history); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"content type\")) { /* strip unsupported items */ }","preventionTips":["Keep user-role Items limited to the four mapped content types.","Move FunctionCallContent to assistant messages."],"tags":["openai","chat-completion","content-parts","user-message"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}