Skip to content

fix(core): preserve children in XMLOutputParser mixed-content nodes#36944

Closed
zxuhan7 (zxuhan) wants to merge 1 commit intolangchain-ai:masterfrom
zxuhan:fix/36744-xml-mixed-content
Closed

fix(core): preserve children in XMLOutputParser mixed-content nodes#36944
zxuhan7 (zxuhan) wants to merge 1 commit intolangchain-ai:masterfrom
zxuhan:fix/36744-xml-mixed-content

Conversation

@zxuhan
Copy link
Copy Markdown

Closes #36744


XMLOutputParser._root_to_dict returns {tag: text} whenever an element has any non-whitespace text. For an element that also has child elements, this early return silently discards the children — e.g. <result>Summary<detail>info</detail></result> parses to {'result': 'Summary'} and <detail> is lost.

The early return is the correct behavior for leaf nodes (a tag wrapping plain text). The fix restricts it to elements with no children (len(root) == 0), so non-leaf elements fall through into the existing loop that walks children. Output shape for leaves and pure-children parents is unchanged. Preserving the parent's text alongside its children is a separate enhancement and is out of scope here.

AI agent involvement: this contribution was drafted with assistance from an AI coding agent.

@github-actions github-actions Bot added core `langchain-core` package issues & PRs fix For PRs that implement a fix size: XS < 50 LOC labels Apr 22, 2026
@github-actions
Copy link
Copy Markdown

This PR has been automatically closed because you are not assigned to the linked issue.

External contributors must be assigned to an issue before opening a PR for it. Please:

  1. Comment on the linked issue to request assignment from a maintainer
  2. Once assigned, your PR will be reopened automatically

Maintainers: reopen this PR or remove the missing-issue-link label to bypass this check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core `langchain-core` package issues & PRs external fix For PRs that implement a fix missing-issue-link new-contributor size: XS < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XMLOutputParser._root_to_dict drops child elements when parent has text

1 participant