_parse_arguments_from_tool_call() — langchain Function Reference
Architecture documentation for the _parse_arguments_from_tool_call() function in chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD ef2fbbf4_d176_ecab_7ad5_9a91394db4ee["_parse_arguments_from_tool_call()"] 5b41b5a0_b415_2ecd_9522_191ca69202ca["chat_models.py"] ef2fbbf4_d176_ecab_7ad5_9a91394db4ee -->|defined in| 5b41b5a0_b415_2ecd_9522_191ca69202ca 22b4b72b_4c0e_fde2_2401_52040de102e0["_get_tool_calls_from_response()"] 22b4b72b_4c0e_fde2_2401_52040de102e0 -->|calls| ef2fbbf4_d176_ecab_7ad5_9a91394db4ee e6c4a9df_6037_7280_75cd_a57b75d96dfe["_parse_json_string()"] ef2fbbf4_d176_ecab_7ad5_9a91394db4ee -->|calls| e6c4a9df_6037_7280_75cd_a57b75d96dfe style ef2fbbf4_d176_ecab_7ad5_9a91394db4ee fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/ollama/langchain_ollama/chat_models.py lines 170–204
def _parse_arguments_from_tool_call(
raw_tool_call: dict[str, Any],
) -> dict[str, Any] | None:
"""Parse arguments by trying to parse any shallowly nested string-encoded JSON.
Band-aid fix for issue in Ollama with inconsistent tool call argument structure.
Should be removed/changed if fixed upstream.
See https://github.com/ollama/ollama/issues/6155
"""
if "function" not in raw_tool_call:
return None
function_name = raw_tool_call["function"]["name"]
arguments = raw_tool_call["function"]["arguments"]
parsed_arguments: dict = {}
if isinstance(arguments, dict):
for key, value in arguments.items():
# Filter out metadata fields like 'functionName' that echo function name
if key == "functionName" and value == function_name:
continue
if isinstance(value, str):
parsed_value = _parse_json_string(
value, skip=True, raw_tool_call=raw_tool_call
)
if isinstance(parsed_value, (dict, list)):
parsed_arguments[key] = parsed_value
else:
parsed_arguments[key] = value
else:
parsed_arguments[key] = value
else:
parsed_arguments = _parse_json_string(
arguments, skip=False, raw_tool_call=raw_tool_call
)
return parsed_arguments
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does _parse_arguments_from_tool_call() do?
_parse_arguments_from_tool_call() is a function in the langchain codebase, defined in libs/partners/ollama/langchain_ollama/chat_models.py.
Where is _parse_arguments_from_tool_call() defined?
_parse_arguments_from_tool_call() is defined in libs/partners/ollama/langchain_ollama/chat_models.py at line 170.
What does _parse_arguments_from_tool_call() call?
_parse_arguments_from_tool_call() calls 1 function(s): _parse_json_string.
What calls _parse_arguments_from_tool_call()?
_parse_arguments_from_tool_call() is called by 1 function(s): _get_tool_calls_from_response.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free