# XMLAgentOutputParser

> **Class** in `langchain_classic`

📖 [View in docs](https://reference.langchain.com/python/langchain-classic/agents/output_parsers/xml/XMLAgentOutputParser)

Parses tool invocations and final answers from XML-formatted agent output.

This parser extracts structured information from XML tags to determine whether
an agent should perform a tool action or provide a final answer. It includes
built-in escaping support to safely handle tool names and inputs
containing XML special characters.

## Signature

```python
XMLAgentOutputParser()
```

## Description

**Expected formats:**

Tool invocation (returns AgentAction):
    <tool>search</tool>
    <tool_input>what is 2 + 2</tool_input>

Final answer (returns AgentFinish):
    <final_answer>The answer is 4</final_answer>

!!! note
Minimal escaping allows tool names containing XML tags to be safely represented.
For example, a tool named `search<tool>nested</tool>` would be escaped as
`search[[tool]]nested[[/tool]]` in the XML and automatically unescaped during
parsing.

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `escape_format` | `unknown` | Yes | The escaping format to use when parsing XML content. Supports 'minimal' which uses custom delimiters like [[tool]] to replace XML tags within content, preventing parsing conflicts. Use 'minimal' if using a corresponding encoding format that uses the _escape function when formatting the output (e.g., with format_xml). |

## Extends

- `AgentOutputParser`

## Properties

- `escape_format`

## Methods

- [`parse()`](https://reference.langchain.com/python/langchain-classic/agents/output_parsers/xml/XMLAgentOutputParser/parse)
- [`get_format_instructions()`](https://reference.langchain.com/python/langchain-classic/agents/output_parsers/xml/XMLAgentOutputParser/get_format_instructions)

---

[View source on GitHub](https://github.com/langchain-ai/langchain/blob/c59e83a1ffba63d709ea4847445845edd82085dc/libs/langchain/langchain_classic/agents/output_parsers/xml.py#L26)