Python: Bug: ChatMessageContent.from_element drops AudioContent and BinaryContent into raw TextContent

Open Beginner friendly
#14,824 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

@halcyon-past is already working on this.

Since Nov 18, 2026.

  • #14825 by @halcyon-past — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Start in python/semantic_kernel/contents/chat_message_content.py by reading TAG_CONTENT_MAP and the from_element() handling for content tags. Check how AudioContent and BinaryContent serialize and deserialize, then verify XML and prompt round trips preserve their item types. Also check the semantic_kernel.contents.__all__ export for BinaryContent; done means both types round-trip without becoming TextContent.

Written by the indexing model from the issue text.

Description

Describe the bug

When ChatMessageContent containing AudioContent or BinaryContent is converted to an XML Element and deserialized via ChatMessageContent.from_element(), or round-tripped through prompt rendering (ChatHistory.to_prompt() / ChatHistory.from_rendered_prompt()), the AudioContent and BinaryContent items are corrupted into TextContent containing literal XML tags (e.g. <audio>...</audio>), and a warning is logged:
Unknown tag "audio" in ChatMessageContent, treating as text

Where

In python/semantic_kernel/contents/chat_message_content.py:
TAG_CONTENT_MAP includes tags for annotation, text, file_reference, function_call, function_result, image, reasoning, and streaming variants, but omits AUDIO_CONTENT_TAG ("audio") and BINARY_CONTENT_TAG ("binary").

Also, BinaryContent is omitted from semantic_kernel.contents.__all__.

To Reproduce
from semantic_kernel.contents import AudioContent, ChatMessageContent, AuthorRole

ac = AudioContent(data=b"test_audio", mime_type="audio/mpeg")
cmc = ChatMessageContent(role=AuthorRole.USER, items=[ac])
elem = cmc.to_element()
restored = ChatMessageContent.from_element(elem)

assert cmc == restored
# Fails:
# WARNING:root:Unknown tag "audio" in ChatMessageContent, treating as text
# AssertionError: ChatMessageContent(..., items=[AudioContent(...)]) != ChatMessageContent(..., items=[TextContent(text='<audio>data:audio/mpeg;,test_audio</audio>')])
Expected behavior

ChatMessageContent.from_element() correctly deserializes <audio> into AudioContent and <binary> into BinaryContent, preserving item types across prompt and XML round trips.

Platform
  • Language: Python
  • Source: main branch
  • OS: Mac / Linux / Windows
Dominant language
C#
Stars
28.8k
Forks
4.9k
Avg merge
2d 17h
Merged PRs (30d)
48

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/semantic-kernel

All issues in microsoft/semantic-kernel

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.