Home / Function/ test_malformed_xml_with_nested_tags() — langchain Function Reference

test_malformed_xml_with_nested_tags() — langchain Function Reference

Architecture documentation for the test_malformed_xml_with_nested_tags() function in test_xml.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  47887a44_0a6f_c87c_365f_d48d3bb45d88["test_malformed_xml_with_nested_tags()"]
  972f46cf_6d67_3d50_b55a_eec185ef4348["test_xml.py"]
  47887a44_0a6f_c87c_365f_d48d3bb45d88 -->|defined in| 972f46cf_6d67_3d50_b55a_eec185ef4348
  style 47887a44_0a6f_c87c_365f_d48d3bb45d88 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/tests/unit_tests/agents/output_parsers/test_xml.py lines 37–58

def test_malformed_xml_with_nested_tags() -> None:
    """Test handling of tool names with XML tags via format_xml minimal escaping."""
    from langchain_classic.agents.format_scratchpad.xml import format_xml

    # Create an AgentAction with XML tags in the tool name
    action = AgentAction(tool="search<tool>nested</tool>", tool_input="query", log="")

    # The format_xml function should escape the XML tags using custom delimiters
    formatted_xml = format_xml([(action, "observation")])

    # Extract just the tool part for parsing
    tool_part = formatted_xml.split("<observation>")[0]  # Remove observation part

    # Now test that the parser can handle the escaped XML
    parser = XMLAgentOutputParser(escape_format="minimal")
    output = parser.invoke(tool_part)

    # The parser should unescape and extract the original tool name
    expected_output = AgentAction(
        tool="search<tool>nested</tool>", tool_input="query", log=tool_part
    )
    assert output == expected_output

Domain

Subdomains

Frequently Asked Questions

What does test_malformed_xml_with_nested_tags() do?
test_malformed_xml_with_nested_tags() is a function in the langchain codebase, defined in libs/langchain/tests/unit_tests/agents/output_parsers/test_xml.py.
Where is test_malformed_xml_with_nested_tags() defined?
test_malformed_xml_with_nested_tags() is defined in libs/langchain/tests/unit_tests/agents/output_parsers/test_xml.py at line 37.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free