Home / Function/ parse_result() — langchain Function Reference

parse_result() — langchain Function Reference

Architecture documentation for the parse_result() function in openai_functions.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  98d5e301_aa7f_77b7_a131_74872a325c64["parse_result()"]
  c87c79f6_cc60_a735_2e43_64e256d72497["PydanticOutputFunctionsParser"]
  98d5e301_aa7f_77b7_a131_74872a325c64 -->|defined in| c87c79f6_cc60_a735_2e43_64e256d72497
  style 98d5e301_aa7f_77b7_a131_74872a325c64 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/output_parsers/openai_functions.py lines 259–292

    def parse_result(self, result: list[Generation], *, partial: bool = False) -> Any:
        """Parse the result of an LLM call to a JSON object.

        Args:
            result: The result of the LLM call.
            partial: Whether to parse partial JSON objects.

        Raises:
            ValueError: If the Pydantic schema is not valid.

        Returns:
            The parsed JSON object.
        """
        result_ = super().parse_result(result)
        if self.args_only:
            if hasattr(self.pydantic_schema, "model_validate_json"):
                pydantic_args = self.pydantic_schema.model_validate_json(result_)
            else:
                pydantic_args = self.pydantic_schema.parse_raw(result_)  # type: ignore[attr-defined]
        else:
            fn_name = result_["name"]
            args = result_["arguments"]
            if isinstance(self.pydantic_schema, dict):
                pydantic_schema = self.pydantic_schema[fn_name]
            else:
                pydantic_schema = self.pydantic_schema
            if issubclass(pydantic_schema, BaseModel):
                pydantic_args = pydantic_schema.model_validate_json(args)
            elif issubclass(pydantic_schema, BaseModelV1):
                pydantic_args = pydantic_schema.parse_raw(args)
            else:
                msg = f"Unsupported Pydantic schema: {pydantic_schema}"
                raise ValueError(msg)
        return pydantic_args

Domain

Subdomains

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_functions.py.
Where is parse_result() defined?
parse_result() is defined in libs/core/langchain_core/output_parsers/openai_functions.py at line 259.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free