AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

XMLOutputParser._Root_to_dict Drops Child Elements When Parent Has Text

The XMLOutputParser's _root_to_dict method returns early with only the text content when an XML element has both text and child elements, silently discarding the children. This causes loss of data in mixed-content XML.

highConfidence 92%LangchainVector StoresChainsAffected V1.3.0a1

Origin Analysis

The _root_to_dict function checks `if root.text` and immediately returns `{root.tag: root.text}`, without checking for the presence of child elements. This early return occurs regardless of whether children exist, so mixed content is not handled.
from langchain_core.output_parsers import XMLOutputParser parser = XMLOutputParser() xml_str = "<result>Summary<detail>info</detail></result>" parsed = parser.parse(f"```xml\n{xml_str}\n```") print(parsed) # Actual: {'result': 'Summary'}, Expected: {'result': [{'_text': 'Summary'}, {'detail': 'info'}]}

Fixing Code Block

Edge Case Audit

This change alters the output structure for mixed-content elements from a string to a list, which may break downstream code expecting a simple string. Users relying on the previous behavior (though buggy) should update their code. To roll back, revert to the original early-return logic. The fix ignores whitespace-only text nodes to avoid spurious '_text' entries. However, mixed content with multiple text segments separated by children is not fully supported; only the initial text (root.text) is captured, and tail text of children is lost.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state