@@ -43,19 +43,19 @@ class _StreamingParser:
4343 """Streaming parser for XML.
4444
4545 This implementation is pulled into a class to avoid implementation
46- drift between transform and atransform of the XMLOutputParser.
46+ drift between transform and atransform of the ` XMLOutputParser` .
4747 """
4848
4949 def __init__ (self , parser : Literal ["defusedxml" , "xml" ]) -> None :
5050 """Initialize the streaming parser.
5151
5252 Args:
53- parser: Parser to use for XML parsing. Can be either 'defusedxml' or 'xml'.
54- See documentation in XMLOutputParser for more information.
53+ parser: Parser to use for XML parsing. Can be either ` 'defusedxml'` or
54+ `'xml'`. See documentation in ` XMLOutputParser` for more information.
5555
5656 Raises:
57- ImportError: If defusedxml is not installed and the defusedxml
58- parser is requested.
57+ ImportError: If ` defusedxml` is not installed and the ` defusedxml` parser is
58+ requested.
5959 """
6060 if parser == "defusedxml" :
6161 if not _HAS_DEFUSEDXML :
@@ -79,10 +79,10 @@ def parse(self, chunk: str | BaseMessage) -> Iterator[AddableDict]:
7979 """Parse a chunk of text.
8080
8181 Args:
82- chunk: A chunk of text to parse. This can be a string or a BaseMessage.
82+ chunk: A chunk of text to parse. This can be a `str` or a ` BaseMessage` .
8383
8484 Yields:
85- A dictionary representing the parsed XML element.
85+ A `dict` representing the parsed XML element.
8686
8787 Raises:
8888 xml.etree.ElementTree.ParseError: If the XML is not well-formed.
@@ -147,46 +147,49 @@ def close(self) -> None:
147147
148148
149149class XMLOutputParser (BaseTransformOutputParser ):
150- """Parse an output using xml format."""
150+ """Parse an output using xml format.
151+
152+ Returns a dictionary of tags.
153+ """
151154
152155 tags : list [str ] | None = None
153156 """Tags to tell the LLM to expect in the XML output.
154157
155158 Note this may not be perfect depending on the LLM implementation.
156159
157- For example, with tags=["foo", "bar", "baz"]:
160+ For example, with ` tags=["foo", "bar", "baz"]` :
158161
159162 1. A well-formatted XML instance:
160- "<foo>\n <bar>\n <baz></baz>\n </bar>\n </foo>"
163+ ` "<foo>\n <bar>\n <baz></baz>\n </bar>\n </foo>"`
161164
162165 2. A badly-formatted XML instance (missing closing tag for 'bar'):
163- "<foo>\n <bar>\n </foo>"
166+ ` "<foo>\n <bar>\n </foo>"`
164167
165168 3. A badly-formatted XML instance (unexpected 'tag' element):
166- "<foo>\n <tag>\n </tag>\n </foo>"
169+ ` "<foo>\n <tag>\n </tag>\n </foo>"`
167170 """
168171 encoding_matcher : re .Pattern = re .compile (
169172 r"<([^>]*encoding[^>]*)>\n(.*)" , re .MULTILINE | re .DOTALL
170173 )
171174 parser : Literal ["defusedxml" , "xml" ] = "defusedxml"
172- """Parser to use for XML parsing. Can be either 'defusedxml' or 'xml'.
175+ """Parser to use for XML parsing. Can be either ` 'defusedxml'` or ` 'xml'` .
173176
174- * 'defusedxml' is the default parser and is used to prevent XML vulnerabilities
175- present in some distributions of Python's standard library xml.
176- `defusedxml` is a wrapper around the standard library parser that
177- sets up the parser with secure defaults.
178- * 'xml' is the standard library parser.
177+ * ` 'defusedxml'` is the default parser and is used to prevent XML vulnerabilities
178+ present in some distributions of Python's standard library xml.
179+ `defusedxml` is a wrapper around the standard library parser that
180+ sets up the parser with secure defaults.
181+ * ` 'xml'` is the standard library parser.
179182
180- Use `xml` only if you are sure that your distribution of the standard library
181- is not vulnerable to XML vulnerabilities.
183+ Use `xml` only if you are sure that your distribution of the standard library is not
184+ vulnerable to XML vulnerabilities.
182185
183186 Please review the following resources for more information:
184187
185188 * https://docs.python.org/3/library/xml.html#xml-vulnerabilities
186189 * https://github.com/tiran/defusedxml
187190
188- The standard library relies on libexpat for parsing XML:
189- https://github.com/libexpat/libexpat
191+ The standard library relies on [` libexpat`](https://github.com/libexpat/libexpat)
192+ for parsing XML.
190193 """
191194
192195 def get_format_instructions (self ) -> str :
@@ -200,12 +203,12 @@ def parse(self, text: str) -> dict[str, str | list[Any]]:
200203 text: The output of an LLM call.
201204
202205 Returns:
203- A dictionary representing the parsed XML.
206+ A `dict` representing the parsed XML.
204207
205208 Raises:
206209 OutputParserException: If the XML is not well-formed.
207- ImportError: If defusedxml is not installed and the defusedxml
208- parser is requested.
210+ ImportError: If defus`edxml is not installed and the ` defusedxml` parser is
211+ requested.
209212 """
210213 # Try to find XML string within triple backticks
211214 # Imports are temporarily placed here to avoid issue with caching on CI
0 commit comments