From c16c25f1c311e30f3b56dd4932944ad969f442ab Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Fri, 20 Sep 2024 15:23:52 -0400 Subject: [PATCH 1/2] x --- libs/core/langchain_core/output_parsers/xml.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/core/langchain_core/output_parsers/xml.py b/libs/core/langchain_core/output_parsers/xml.py index 96ca870cab664..dd99782aa7a7f 100644 --- a/libs/core/langchain_core/output_parsers/xml.py +++ b/libs/core/langchain_core/output_parsers/xml.py @@ -189,7 +189,7 @@ def parse(self, text: str) -> dict[str, Union[str, list[Any]]]: # likely if you're reading this you can move them to the top of the file if self.parser == "defusedxml": try: - import defusedxml # type: ignore + from defusedxml import ElementTree # type: ignore except ImportError as e: raise ImportError( "defusedxml is not installed. " @@ -197,7 +197,7 @@ def parse(self, text: str) -> dict[str, Union[str, list[Any]]]: "You can install it with `pip install defusedxml`" "See https://github.com/tiran/defusedxml for more details" ) from e - _et = defusedxml.ElementTree # Use the defusedxml parser + _et = ElementTree # Use the defusedxml parser else: _et = ET # Use the standard library parser From 8b17a02e8e74c1d9414c620579110ccba7668dec Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Fri, 20 Sep 2024 16:45:58 -0400 Subject: [PATCH 2/2] x --- libs/core/langchain_core/output_parsers/xml.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/core/langchain_core/output_parsers/xml.py b/libs/core/langchain_core/output_parsers/xml.py index dd99782aa7a7f..3d55bed32d6f9 100644 --- a/libs/core/langchain_core/output_parsers/xml.py +++ b/libs/core/langchain_core/output_parsers/xml.py @@ -211,10 +211,9 @@ def parse(self, text: str) -> dict[str, Union[str, list[Any]]]: text = text.strip() try: - root = ET.fromstring(text) + root = _et.fromstring(text) return self._root_to_dict(root) - - except ET.ParseError as e: + except _et.ParseError as e: msg = f"Failed to parse XML format from completion {text}. Got: {e}" raise OutputParserException(msg, llm_output=text) from e