Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Python: Bug: AnnotationContent and StreamingAnnotationContent to_element writes CitationType.X, so annotations in a rendered chat history fail to parse

Open Beginner friendly
#14,590 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

@CRYPTONIKAV is already working on this.

Since Oct 13, 2026.

  • #14593 by @CRYPTONIKAV — open

Assessment

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

Research direction

Start with the to_element methods of AnnotationContent and StreamingAnnotationContent in the Python contents package, where citation_type is written as an XML attribute. Reproduce by serializing an annotation with tostring and parsing it back with from_element or ChatHistory.from_rendered_prompt. Done means the round trip succeeds from the serialized string, with tests that cover the string path, not just the in-memory element.

Written by the indexing model from the issue text.

Description

python triage
Describe the bug

AnnotationContent.to_element() and StreamingAnnotationContent.to_element() store the CitationType enum object in the XML attribute:

if self.citation_type:
    element.set("type", self.citation_type)

CitationType is a str, Enum. When the element is serialized, the attribute is written with the enum's str() form, CitationType.FILE_CITATION, not the value file_citation. from_element() then cannot read it back. Any chat message that has an annotation with a citation type breaks as soon as the history is rendered to a prompt string and parsed back (ChatHistory.from_rendered_prompt, which is what prompt templates use for {{$chat_history}} style messages).

The existing round trip tests pass because they never serialize the element to a string, so the enum object stays in memory.

To Reproduce

Run against current main (5b4a3269a), Python 3.13:

from semantic_kernel.contents import ChatHistory, ChatMessageContent, AuthorRole, TextContent
from semantic_kernel.contents.annotation_content import AnnotationContent, CitationType

msg = ChatMessageContent(
    role=AuthorRole.ASSISTANT,
    items=[
        TextContent(text="see [1]"),
        AnnotationContent(file_id="file-1", quote="q", start_index=4, end_index=7, citation_type=CitationType.FILE_CITATION),
    ],
)
history = ChatHistory(messages=[msg])
print(msg.to_prompt())
ChatHistory.from_rendered_prompt(str(history))

Output:

<message role="assistant"><text>see [1]</text><annotation type="CitationType.FILE_CITATION" file_id="file-1" quote="q" start_index="4" end_index="7"></annotation></message>
pydantic_core._pydantic_core.ValidationError: 1 validation error for AnnotationContent
type
  Input should be 'url_citation', 'file_path', 'file_citation' or 'container_file_citation' [type=enum, input_value='CitationType.FILE_CITATION', input_type=str]

StreamingAnnotationContent has the same line and fails the same way:

from xml.etree.ElementTree import tostring, fromstring
from semantic_kernel.contents.streaming_annotation_content import StreamingAnnotationContent
c = StreamingAnnotationContent(file_id="f", citation_type=CitationType.FILE_CITATION)
StreamingAnnotationContent.from_element(fromstring(tostring(c.to_element(), encoding="unicode")))
Expected behavior

The attribute should be written as the enum value (type="file_citation") so that from_element can parse it. The fix is to use self.citation_type.value in both to_element methods.

I have a fix with tests ready and can open a PR.

Platform
  • Language: Python
  • Source: main branch (5b4a3269a)
  • OS: Windows, Python 3.13
Dominant language
C#
Stars
28.6k
Forks
4.8k
Avg merge
2d 7h
Merged PRs (30d)
20

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.