LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • MCP Adapters
    • Overview
    • Agents
    • Callbacks
    • Chains
    • Chat models
    • Embeddings
    • Evaluation
    • Globals
    • Hub
    • Memory
    • Output parsers
    • Retrievers
    • Runnables
    • LangSmith
    • Storage
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    MCP Adapters
    OverviewAgentsCallbacksChainsChat modelsEmbeddingsEvaluationGlobalsHubMemoryOutput parsersRetrieversRunnablesLangSmithStorage
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-classicagentsoutput_parsersxmlXMLAgentOutputParser
    Class●Since v1.0

    XMLAgentOutputParser

    Copy
    XMLAgentOutputParser()

    Bases

    AgentOutputParser

    Attributes

    Methods

    Inherited fromBaseOutputParser(langchain_core)

    Attributes

    AInputTypeAOutputType

    Methods

    MinvokeMainvoke
    View source on GitHub
    M
    parse_result
    Maparse_result
    Maparse
    Mparse_with_prompt
    Mdict

    Inherited fromBaseLLMOutputParser(langchain_core)

    Methods

    Mparse_resultMaparse_result

    Inherited fromRunnableSerializable(langchain_core)

    Attributes

    AnameAmodel_config

    Methods

    Mto_jsonMconfigurable_fieldsMconfigurable_alternatives

    Inherited fromSerializable(langchain_core)

    Attributes

    Alc_secretsAlc_attributesAmodel_config

    Methods

    Mis_lc_serializableMget_lc_namespaceMlc_idMto_jsonMto_json_not_implemented

    Inherited fromRunnable(langchain_core)

    Attributes

    AnameAInputTypeAOutputTypeAinput_schemaAoutput_schemaAconfig_specs

    Methods

    Mget_nameMget_input_schemaMget_input_jsonschemaMget_output_schemaMget_output_jsonschemaM

    Parameters

    NameTypeDescription
    escape_format*unknown

    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).

    attribute
    escape_format: Literal['minimal'] | None

    The format to use for escaping XML characters.

    minimal - uses custom delimiters to replace XML tags within content, preventing parsing conflicts. This is the only supported format currently.

    None - no escaping is applied, which may lead to parsing conflicts.

    method
    parse
    method
    get_format_instructions

    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.

    Expected formats:

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

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

    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.

    config_schema
    Mget_config_jsonschema
    Mget_graph
    Mget_prompts
    Mpipe
    Mpick
    Massign
    Minvoke
    Mainvoke
    Mbatch
    Mbatch_as_completed
    Mabatch
    Mabatch_as_completed
    Mstream
    Mastream
    Mastream_log
    Mastream_events
    Mtransform
    Matransform
    Mbind
    Mwith_config
    Mwith_listeners
    Mwith_alisteners
    Mwith_types
    Mwith_retry
    Mmap
    Mwith_fallbacks
    Mas_tool