mirror of
https://github.com/hwchase17/langchain.git
synced 2026-07-12 02:55:21 +00:00
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 <github@mdrxy.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user