From 3a6053329580659799303310d6def6990caa4fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?AI=E4=B8=8D=E6=AD=A2=E8=AF=AD?= <12096460+jnMetaCode@users.noreply.github.com> Date: Mon, 6 Jul 2026 08:31:20 +0800 Subject: [PATCH] fix(core): output parser bugs in xml.py and pydantic.py (#35641) - **Fix missing spaces in error messages in `xml.py`**: Adjacent string literals in two `ImportError` messages were missing spaces between them, resulting in concatenated words like "parser.You" and "defusedxml`See". - **Fix `partial` parameter not forwarded in `PydanticOutputParser.parse_result`**: The `partial` parameter was accepted but not passed to `super().parse_result()`, so partial parsing mode had no effect. --------- Signed-off-by: JiangNan <1394485448@qq.com> Co-authored-by: Mason Daugherty --- libs/core/langchain_core/output_parsers/pydantic.py | 2 +- libs/core/langchain_core/output_parsers/xml.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libs/core/langchain_core/output_parsers/pydantic.py b/libs/core/langchain_core/output_parsers/pydantic.py index 3f8130e1e34..27f0664b061 100644 --- a/libs/core/langchain_core/output_parsers/pydantic.py +++ b/libs/core/langchain_core/output_parsers/pydantic.py @@ -74,7 +74,7 @@ class PydanticOutputParser(JsonOutputParser, Generic[TBaseModel]): The parsed Pydantic object. """ try: - json_object = super().parse_result(result) + json_object = super().parse_result(result, partial=partial) return self._parse_obj(json_object) except OutputParserException: if partial: diff --git a/libs/core/langchain_core/output_parsers/xml.py b/libs/core/langchain_core/output_parsers/xml.py index a26a37ffcfa..f3f2bcad09c 100644 --- a/libs/core/langchain_core/output_parsers/xml.py +++ b/libs/core/langchain_core/output_parsers/xml.py @@ -63,8 +63,9 @@ class _StreamingParser: if not _HAS_DEFUSEDXML: msg = ( "defusedxml is not installed. " - "Please install it to use the defusedxml parser." - "You can install it with `pip install defusedxml` " + "Please install it to use the defusedxml parser. " + "You can install it with `pip install defusedxml`. " + "See https://github.com/tiran/defusedxml for more details" ) raise ImportError(msg) parser_ = XMLParser(target=TreeBuilder()) @@ -214,8 +215,8 @@ class XMLOutputParser(BaseTransformOutputParser[dict[str, Any]]): Raises: OutputParserException: If the XML is not well-formed. - ImportError: If defus`edxml is not installed and the `defusedxml` parser is - requested. + ImportError: If `defusedxml` is not installed and the `defusedxml` parser + is requested. """ # Try to find XML string within triple backticks # Imports are temporarily placed here to avoid issue with caching on CI @@ -224,8 +225,8 @@ class XMLOutputParser(BaseTransformOutputParser[dict[str, Any]]): if not _HAS_DEFUSEDXML: msg = ( "defusedxml is not installed. " - "Please install it to use the defusedxml parser." - "You can install it with `pip install defusedxml`" + "Please install it to use the defusedxml parser. " + "You can install it with `pip install defusedxml`. " "See https://github.com/tiran/defusedxml for more details" ) raise ImportError(msg)