test_tools_and_structured_output() — langchain Function Reference
Architecture documentation for the test_tools_and_structured_output() function in test_base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD fa29347d_0882_c2d1_8b46_f113fb6ae264["test_tools_and_structured_output()"] bd382a4e_442c_13ae_530c_6e34bc43623d["test_base.py"] fa29347d_0882_c2d1_8b46_f113fb6ae264 -->|defined in| bd382a4e_442c_13ae_530c_6e34bc43623d style fa29347d_0882_c2d1_8b46_f113fb6ae264 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/openai/tests/integration_tests/chat_models/test_base.py lines 1144–1172
def test_tools_and_structured_output() -> None:
llm = ChatOpenAI(model="gpt-5-nano").with_structured_output(
ResponseFormat, strict=True, include_raw=True, tools=[GenerateUsername]
)
expected_keys = {"raw", "parsing_error", "parsed"}
query = "Hello"
tool_query = "Generate a user name for Alice, black hair. Use the tool."
# Test invoke
## Engage structured output
response = llm.invoke(query)
assert isinstance(response["parsed"], ResponseFormat)
## Engage tool calling
response_tools = llm.invoke(tool_query)
ai_msg = response_tools["raw"]
assert isinstance(ai_msg, AIMessage)
assert ai_msg.tool_calls
assert response_tools["parsed"] is None
# Test stream
aggregated: dict = {}
for chunk in llm.stream(tool_query):
assert isinstance(chunk, dict)
assert all(key in expected_keys for key in chunk)
aggregated = {**aggregated, **chunk}
assert all(key in aggregated for key in expected_keys)
assert isinstance(aggregated["raw"], AIMessage)
assert aggregated["raw"].tool_calls
assert aggregated["parsed"] is None
Domain
Subdomains
Source
Frequently Asked Questions
What does test_tools_and_structured_output() do?
test_tools_and_structured_output() is a function in the langchain codebase, defined in libs/partners/openai/tests/integration_tests/chat_models/test_base.py.
Where is test_tools_and_structured_output() defined?
test_tools_and_structured_output() is defined in libs/partners/openai/tests/integration_tests/chat_models/test_base.py at line 1144.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free