Home / Function/ test_structured_response_preserved() — langchain Function Reference

test_structured_response_preserved() — langchain Function Reference

Architecture documentation for the test_structured_response_preserved() function in test_wrap_model_call_state_update.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  2f3bb608_7ff4_8a29_55b9_22dd6fee84f9["test_structured_response_preserved()"]
  269d8393_43ba_e665_6d86_95d75ce0c396["TestComposition"]
  2f3bb608_7ff4_8a29_55b9_22dd6fee84f9 -->|defined in| 269d8393_43ba_e665_6d86_95d75ce0c396
  style 2f3bb608_7ff4_8a29_55b9_22dd6fee84f9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py lines 610–636

    def test_structured_response_preserved(self) -> None:
        """ExtendedModelResponse preserves structured_response from ModelResponse."""

        class StructuredMiddleware(AgentMiddleware):
            def wrap_model_call(
                self,
                request: ModelRequest,
                handler: Callable[[ModelRequest], ModelResponse],
            ) -> ExtendedModelResponse:
                response = handler(request)
                response_with_structured = ModelResponse(
                    result=response.result,
                    structured_response={"key": "value"},
                )
                return ExtendedModelResponse(
                    model_response=response_with_structured,
                )

        model = GenericFakeChatModel(messages=iter([AIMessage(content="Hello")]))
        agent = create_agent(model=model, middleware=[StructuredMiddleware()])

        result = agent.invoke({"messages": [HumanMessage("Hi")]})

        assert result.get("structured_response") == {"key": "value"}
        messages = result["messages"]
        assert len(messages) == 2
        assert messages[1].content == "Hello"

Domain

Subdomains

Frequently Asked Questions

What does test_structured_response_preserved() do?
test_structured_response_preserved() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py.
Where is test_structured_response_preserved() defined?
test_structured_response_preserved() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py at line 610.

Analyze Your Own Codebase

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

Try Supermodel Free