test_json_output_key_tools_parser_multiple_tools_first_only() — langchain Function Reference
Architecture documentation for the test_json_output_key_tools_parser_multiple_tools_first_only() function in test_openai_tools.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 94bb34a2_c1b4_dec4_8edd_aa512fbf4c22["test_json_output_key_tools_parser_multiple_tools_first_only()"] 0f94a062_f577_31c7_fb9c_0f526b273e64["test_openai_tools.py"] 94bb34a2_c1b4_dec4_8edd_aa512fbf4c22 -->|defined in| 0f94a062_f577_31c7_fb9c_0f526b273e64 style 94bb34a2_c1b4_dec4_8edd_aa512fbf4c22 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/output_parsers/test_openai_tools.py lines 487–539
def test_json_output_key_tools_parser_multiple_tools_first_only(
*, use_tool_calls: bool
) -> None:
# Test case from the original bug report
def create_message() -> AIMessage:
tool_calls_data = [
{
"id": "call_other",
"function": {"name": "other", "arguments": '{"b":2}'},
"type": "function",
},
{
"id": "call_func",
"function": {"name": "func", "arguments": '{"a":1}'},
"type": "function",
},
]
if use_tool_calls:
return AIMessage(
content="",
tool_calls=[
{"id": "call_other", "name": "other", "args": {"b": 2}},
{"id": "call_func", "name": "func", "args": {"a": 1}},
],
)
return AIMessage(
content="",
additional_kwargs={"tool_calls": tool_calls_data},
)
result = [ChatGeneration(message=create_message())]
# Test with return_id=True
parser = JsonOutputKeyToolsParser(
key_name="func", first_tool_only=True, return_id=True
)
output = parser.parse_result(result) # type: ignore[arg-type]
# Should return the func tool call, not None
assert output is not None
assert output["type"] == "func"
assert output["args"] == {"a": 1}
assert "id" in output
# Test with return_id=False
parser_no_id = JsonOutputKeyToolsParser(
key_name="func", first_tool_only=True, return_id=False
)
output_no_id = parser_no_id.parse_result(result) # type: ignore[arg-type]
# Should return just the args
assert output_no_id == {"a": 1}
Domain
Subdomains
Source
Frequently Asked Questions
What does test_json_output_key_tools_parser_multiple_tools_first_only() do?
test_json_output_key_tools_parser_multiple_tools_first_only() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/output_parsers/test_openai_tools.py.
Where is test_json_output_key_tools_parser_multiple_tools_first_only() defined?
test_json_output_key_tools_parser_multiple_tools_first_only() is defined in libs/core/tests/unit_tests/output_parsers/test_openai_tools.py at line 487.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free