parse_tool_call() — langchain Function Reference
Architecture documentation for the parse_tool_call() function in openai_tools.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD e8f94337_2009_5435_591f_0564f45c2b7c["parse_tool_call()"] 7d2ea6eb_ed7a_3052_c920_cb5cdc943964["openai_tools.py"] e8f94337_2009_5435_591f_0564f45c2b7c -->|defined in| 7d2ea6eb_ed7a_3052_c920_cb5cdc943964 4003ba8b_78e7_841b_b3e6_0fd0ffd5b52d["parse_tool_calls()"] 4003ba8b_78e7_841b_b3e6_0fd0ffd5b52d -->|calls| e8f94337_2009_5435_591f_0564f45c2b7c style e8f94337_2009_5435_591f_0564f45c2b7c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/output_parsers/openai_tools.py lines 27–78
def parse_tool_call(
raw_tool_call: dict[str, Any],
*,
partial: bool = False,
strict: bool = False,
return_id: bool = True,
) -> dict[str, Any] | None:
"""Parse a single tool call.
Args:
raw_tool_call: The raw tool call to parse.
partial: Whether to parse partial JSON.
strict: Whether to allow non-JSON-compliant strings.
return_id: Whether to return the tool call id.
Returns:
The parsed tool call.
Raises:
OutputParserException: If the tool call is not valid JSON.
"""
if "function" not in raw_tool_call:
return None
arguments = raw_tool_call["function"]["arguments"]
if partial:
try:
function_args = parse_partial_json(arguments, strict=strict)
except (JSONDecodeError, TypeError): # None args raise TypeError
return None
# Handle None or empty string arguments for parameter-less tools
elif not arguments:
function_args = {}
else:
try:
function_args = json.loads(arguments, strict=strict)
except JSONDecodeError as e:
msg = (
f"Function {raw_tool_call['function']['name']} arguments:\n\n"
f"{arguments}\n\nare not valid JSON. "
f"Received JSONDecodeError {e}"
)
raise OutputParserException(msg) from e
parsed = {
"name": raw_tool_call["function"]["name"] or "",
"args": function_args or {},
}
if return_id:
parsed["id"] = raw_tool_call.get("id")
parsed = create_tool_call(**parsed) # type: ignore[assignment,arg-type]
return parsed
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does parse_tool_call() do?
parse_tool_call() is a function in the langchain codebase, defined in libs/core/langchain_core/output_parsers/openai_tools.py.
Where is parse_tool_call() defined?
parse_tool_call() is defined in libs/core/langchain_core/output_parsers/openai_tools.py at line 27.
What calls parse_tool_call()?
parse_tool_call() is called by 1 function(s): parse_tool_calls.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free