Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto Apto para principiantes
#14,590 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

@CRYPTONIKAV ya está trabajando en esto.

Desde el 13/10/2026.

  • #14593 de @CRYPTONIKAV — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
82/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
ai

Línea de trabajo

Empieza con los métodos to_element de AnnotationContent y StreamingAnnotationContent en el paquete de contenidos de Python, donde citation_type se escribe como atributo XML. Reproduce el caso serializando una anotación con tostring y analizándola de nuevo con from_element o ChatHistory.from_rendered_prompt. Está terminado cuando la ida y vuelta funciona desde la cadena serializada, con pruebas que cubran la ruta de la cadena y no solo el elemento en memoria.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
C#
Estrellas
28.6k
Forks
4.8k
Merge medio
2 d 12 h
PR fusionados (30 d)
22

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/semantic-kernel

Todos los issues de microsoft/semantic-kernel

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.