parse_result() — langchain Function Reference
Architecture documentation for the parse_result() function in openai_tools.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 6362cf2f_ac6d_027b_84a9_3cafe28b4ba5["parse_result()"] e0e99ee8_367d_95f0_2b6a_b44394251bf3["JsonOutputToolsParser"] 6362cf2f_ac6d_027b_84a9_3cafe28b4ba5 -->|defined in| e0e99ee8_367d_95f0_2b6a_b44394251bf3 8e9fd1fe_5de0_04e1_cb35_1696d2e6ac68["parse_result()"] 8e9fd1fe_5de0_04e1_cb35_1696d2e6ac68 -->|calls| 6362cf2f_ac6d_027b_84a9_3cafe28b4ba5 39c4ea69_6a74_bb81_d201_8124b23279c8["parse_result()"] 39c4ea69_6a74_bb81_d201_8124b23279c8 -->|calls| 6362cf2f_ac6d_027b_84a9_3cafe28b4ba5 6bbf0e48_c095_5f4e_dfb8_4947a3959e12["parse_tool_calls()"] 6362cf2f_ac6d_027b_84a9_3cafe28b4ba5 -->|calls| 6bbf0e48_c095_5f4e_dfb8_4947a3959e12 8e9fd1fe_5de0_04e1_cb35_1696d2e6ac68["parse_result()"] 6362cf2f_ac6d_027b_84a9_3cafe28b4ba5 -->|calls| 8e9fd1fe_5de0_04e1_cb35_1696d2e6ac68 style 6362cf2f_ac6d_027b_84a9_3cafe28b4ba5 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/output_parsers/openai_tools.py lines 166–211
def parse_result(self, result: list[Generation], *, partial: bool = False) -> Any:
"""Parse the result of an LLM call to a list of tool calls.
Args:
result: The result of the LLM call.
partial: Whether to parse partial JSON.
If `True`, the output will be a JSON object containing
all the keys that have been returned so far.
If `False`, the output will be the full JSON object.
Returns:
The parsed tool calls.
Raises:
OutputParserException: If the output is not valid JSON.
"""
generation = result[0]
if not isinstance(generation, ChatGeneration):
msg = "This output parser can only be used with a chat generation."
raise OutputParserException(msg)
message = generation.message
if isinstance(message, AIMessage) and message.tool_calls:
tool_calls = [dict(tc) for tc in message.tool_calls]
for tool_call in tool_calls:
if not self.return_id:
_ = tool_call.pop("id")
else:
try:
raw_tool_calls = copy.deepcopy(message.additional_kwargs["tool_calls"])
except KeyError:
return []
tool_calls = parse_tool_calls(
raw_tool_calls,
partial=partial,
strict=self.strict,
return_id=self.return_id,
)
# for backwards compatibility
for tc in tool_calls:
tc["type"] = tc.pop("name")
if self.first_tool_only:
return tool_calls[0] if tool_calls else None
return tool_calls
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does parse_result() do?
parse_result() is a function in the langchain codebase, defined in libs/core/langchain_core/output_parsers/openai_tools.py.
Where is parse_result() defined?
parse_result() is defined in libs/core/langchain_core/output_parsers/openai_tools.py at line 166.
What does parse_result() call?
parse_result() calls 2 function(s): parse_result, parse_tool_calls.
What calls parse_result()?
parse_result() is called by 2 function(s): parse_result, parse_result.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free