Home / Function/ test_structured_output_and_tools() — langchain Function Reference

test_structured_output_and_tools() — langchain Function Reference

Architecture documentation for the test_structured_output_and_tools() function in test_base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  c0d41ff5_ef12_cc3e_9f68_9cc32d8a3567["test_structured_output_and_tools()"]
  bd382a4e_442c_13ae_530c_6e34bc43623d["test_base.py"]
  c0d41ff5_ef12_cc3e_9f68_9cc32d8a3567 -->|defined in| bd382a4e_442c_13ae_530c_6e34bc43623d
  style c0d41ff5_ef12_cc3e_9f68_9cc32d8a3567 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/openai/tests/integration_tests/chat_models/test_base.py lines 1116–1141

def test_structured_output_and_tools(schema: Any) -> None:
    llm = ChatOpenAI(model="gpt-5-nano", verbosity="low").bind_tools(
        [GenerateUsername], strict=True, response_format=schema
    )

    response = llm.invoke("What weighs more, a pound of feathers or a pound of gold?")
    if schema == ResponseFormat:
        parsed = response.additional_kwargs["parsed"]
        assert isinstance(parsed, ResponseFormat)
    else:
        parsed = json.loads(response.text)
        assert isinstance(parsed, dict)
        assert parsed["response"]
        assert parsed["explanation"]

    # Test streaming tool calls
    full: BaseMessageChunk | None = None
    for chunk in llm.stream(
        "Generate a user name for Alice, black hair. Use the tool."
    ):
        assert isinstance(chunk, AIMessageChunk)
        full = chunk if full is None else full + chunk
    assert isinstance(full, AIMessageChunk)
    assert len(full.tool_calls) == 1
    tool_call = full.tool_calls[0]
    assert tool_call["name"] == "GenerateUsername"

Domain

Subdomains

Frequently Asked Questions

What does test_structured_output_and_tools() do?
test_structured_output_and_tools() is a function in the langchain codebase, defined in libs/partners/openai/tests/integration_tests/chat_models/test_base.py.
Where is test_structured_output_and_tools() defined?
test_structured_output_and_tools() is defined in libs/partners/openai/tests/integration_tests/chat_models/test_base.py at line 1116.

Analyze Your Own Codebase

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

Try Supermodel Free