Home / Function/ test_strict_mode() — langchain Function Reference

test_strict_mode() — langchain Function Reference

Architecture documentation for the test_strict_mode() function in test_response_format_integration.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  9040df2d_cf16_902e_fe3a_215ab59a2d37["test_strict_mode()"]
  52a46c82_b592_7c71_f552_b6b987060948["test_response_format_integration.py"]
  9040df2d_cf16_902e_fe3a_215ab59a2d37 -->|defined in| 52a46c82_b592_7c71_f552_b6b987060948
  c6508ca5_245f_42bb_93a1_984fc946d4d0["ChatOpenAI()"]
  9040df2d_cf16_902e_fe3a_215ab59a2d37 -->|calls| c6508ca5_245f_42bb_93a1_984fc946d4d0
  style 9040df2d_cf16_902e_fe3a_215ab59a2d37 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/test_response_format_integration.py lines 148–189

def test_strict_mode(*, use_responses_api: bool) -> None:
    model_kwargs: dict[str, Any] = {"model": "gpt-5", "use_responses_api": use_responses_api}

    if "OPENAI_API_KEY" not in os.environ:
        model_kwargs["api_key"] = "foo"

    model = ChatOpenAI(**model_kwargs)

    # spy on _get_request_payload to check that `strict` is enabled
    original_method = model._get_request_payload
    payloads = []

    def capture_payload(*args: Any, **kwargs: Any) -> dict[str, Any]:
        result = original_method(*args, **kwargs)
        payloads.append(result)
        return result

    with patch.object(model, "_get_request_payload", side_effect=capture_payload):
        agent = create_agent(
            model,
            tools=[get_weather],
            response_format=ProviderStrategy(WeatherBaseModel, strict=True),
        )
        response = agent.invoke({"messages": [HumanMessage("What's the weather in Boston?")]})

        assert len(payloads) == 2
        if use_responses_api:
            assert payloads[-1]["text"]["format"]["strict"]
        else:
            assert payloads[-1]["response_format"]["json_schema"]["strict"]

    assert isinstance(response["structured_response"], WeatherBaseModel)
    assert response["structured_response"].temperature == 75.0
    assert response["structured_response"].condition.lower() == "sunny"
    assert len(response["messages"]) == 4

    assert [m.type for m in response["messages"]] == [
        "human",  # "What's the weather?"
        "ai",  # "What's the weather?"
        "tool",  # "The weather is sunny and 75°F."
        "ai",  # structured response
    ]

Domain

Subdomains

Calls

Frequently Asked Questions

What does test_strict_mode() do?
test_strict_mode() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/test_response_format_integration.py.
Where is test_strict_mode() defined?
test_strict_mode() is defined in libs/langchain_v1/tests/unit_tests/agents/test_response_format_integration.py at line 148.
What does test_strict_mode() call?
test_strict_mode() calls 1 function(s): ChatOpenAI.

Analyze Your Own Codebase

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

Try Supermodel Free