Skip to content

Commit

Permalink
core: xml output parser tags docstring (#28745)
Browse files Browse the repository at this point in the history
  • Loading branch information
efriis authored Dec 16, 2024
1 parent ebab2ea commit 1c120e9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions libs/core/langchain_core/output_parsers/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ class XMLOutputParser(BaseTransformOutputParser):
"""Parse an output using xml format."""

tags: Optional[list[str]] = None
"""Tags to tell the LLM to expect in the XML output.
Note this may not be perfect depending on the LLM implementation.
For example, with tags=["foo", "bar", "baz"]:
1. A well-formatted XML instance:
"<foo>\n <bar>\n <baz></baz>\n </bar>\n</foo>"
2. A badly-formatted XML instance (missing closing tag for 'bar'):
"<foo>\n <bar>\n </foo>"
3. A badly-formatted XML instance (unexpected 'tag' element):
"<foo>\n <tag>\n </tag>\n</foo>"
"""
encoding_matcher: re.Pattern = re.compile(
r"<([^>]*encoding[^>]*)>\n(.*)", re.MULTILINE | re.DOTALL
)
Expand Down

0 comments on commit 1c120e9

Please sign in to comment.