parse_result() — langchain Function Reference
Architecture documentation for the parse_result() function in output_parsers.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD de78512b_344e_3561_9fd0_66bcf46d91d3["parse_result()"] c0648688_ea16_89e6_d980_3faef9185745["ToolsOutputParser"] de78512b_344e_3561_9fd0_66bcf46d91d3 -->|defined in| c0648688_ea16_89e6_d980_3faef9185745 15e58607_fd55_2228_f86b_4cc17f42fa97["_pydantic_parse()"] de78512b_344e_3561_9fd0_66bcf46d91d3 -->|calls| 15e58607_fd55_2228_f86b_4cc17f42fa97 470cac50_e74a_5b1d_dcca_af4864b0170e["_extract_tool_calls_from_message()"] de78512b_344e_3561_9fd0_66bcf46d91d3 -->|calls| 470cac50_e74a_5b1d_dcca_af4864b0170e style de78512b_344e_3561_9fd0_66bcf46d91d3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/anthropic/langchain_anthropic/output_parsers.py lines 28–64
def parse_result(self, result: list[Generation], *, partial: bool = False) -> Any:
"""Parse a list of candidate model Generations into a specific format.
Args:
result: A list of `Generation` to be parsed. The Generations are assumed
to be different candidate outputs for a single model input.
partial: (Not used) Whether the result is a partial result. If `True`, the
parser may return a partial result, which may not be complete or valid.
Returns:
Structured output.
"""
if not result or not isinstance(result[0], ChatGeneration):
return None if self.first_tool_only else []
message = cast("AIMessage", result[0].message)
tool_calls: list = [
dict(tc) for tc in _extract_tool_calls_from_message(message)
]
if isinstance(message.content, list):
# Map tool call id to index
id_to_index = {
block["id"]: i
for i, block in enumerate(message.content)
if isinstance(block, dict) and block["type"] == "tool_use"
}
tool_calls = [{**tc, "index": id_to_index[tc["id"]]} for tc in tool_calls]
if self.pydantic_schemas:
tool_calls = [self._pydantic_parse(tc) for tc in tool_calls]
elif self.args_only:
tool_calls = [tc["args"] for tc in tool_calls]
else:
pass
if self.first_tool_only:
return tool_calls[0] if tool_calls else None
return list(tool_calls)
Domain
Subdomains
Source
Frequently Asked Questions
What does parse_result() do?
parse_result() is a function in the langchain codebase, defined in libs/partners/anthropic/langchain_anthropic/output_parsers.py.
Where is parse_result() defined?
parse_result() is defined in libs/partners/anthropic/langchain_anthropic/output_parsers.py at line 28.
What does parse_result() call?
parse_result() calls 2 function(s): _extract_tool_calls_from_message, _pydantic_parse.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free