Home / Function/ test_autostrategy_with_anonymous_json_schema() — langchain Function Reference

test_autostrategy_with_anonymous_json_schema() — langchain Function Reference

Architecture documentation for the test_autostrategy_with_anonymous_json_schema() function in test_response_format.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  7a420102_1432_6217_e6fb_e0d0c6a960f4["test_autostrategy_with_anonymous_json_schema()"]
  5b61036b_6078_395b_d306_03640f401013["TestResponseFormatAsModel"]
  7a420102_1432_6217_e6fb_e0d0c6a960f4 -->|defined in| 5b61036b_6078_395b_d306_03640f401013
  style 7a420102_1432_6217_e6fb_e0d0c6a960f4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/test_response_format.py lines 200–229

    def test_autostrategy_with_anonymous_json_schema(self) -> None:
        """Test response_format as anonymous JSON schema (AutoStrategy).

        Verifies that tool name mismatch is avoided when using AutoStrategy with
        schemas that generate random names by ensuring the ToolStrategy instance
        is reused during execution.
        """
        anonymous_schema = {
            "type": "object",
            "properties": {
                "result": {"type": "string"},
            },
            "required": ["result"],
        }

        with patch("langchain.agents.factory._supports_provider_strategy", return_value=False):
            model = FakeToolCallingModel(tool_calls=[])
            agent = create_agent(model, [], response_format=anonymous_schema)

            # We expect a recursion error or similar because we didn't mock the tool call
            # matching our anonymous schema, but it should NOT raise ValueError
            # during the binding phase.
            try:
                agent.invoke({"messages": [HumanMessage("hi")]}, config={"recursion_limit": 1})
            except ValueError as e:
                if "which wasn't declared" in str(e):
                    pytest.fail(f"Tool name mismatch occurred: {e}")
            except Exception:  # noqa: S110
                # Other exceptions mean we passed the binding phase
                pass

Domain

Subdomains

Frequently Asked Questions

What does test_autostrategy_with_anonymous_json_schema() do?
test_autostrategy_with_anonymous_json_schema() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/test_response_format.py.
Where is test_autostrategy_with_anonymous_json_schema() defined?
test_autostrategy_with_anonymous_json_schema() is defined in libs/langchain_v1/tests/unit_tests/agents/test_response_format.py at line 200.

Analyze Your Own Codebase

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

Try Supermodel Free