Home / Function/ parse() — langchain Function Reference

parse() — langchain Function Reference

Architecture documentation for the parse() function in eval_chain.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  04d1798b_2e3d_c994_9073_b128237591cb["parse()"]
  6acf5938_7ff0_bc21_f7a7_c41e88e0ddec["ScoreStringResultOutputParser"]
  04d1798b_2e3d_c994_9073_b128237591cb -->|defined in| 6acf5938_7ff0_bc21_f7a7_c41e88e0ddec
  style 04d1798b_2e3d_c994_9073_b128237591cb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py lines 118–147

    def parse(self, text: str) -> dict[str, Any]:
        """Parse the output text.

        Args:
            text: The output text to parse.

        Returns:
            The parsed output.

        Raises:
            ValueError: If the verdict is invalid.

        """
        match = _FIND_DOUBLE_BRACKETS.search(text)

        if match:
            verdict = match.group(1)

        if not match or verdict not in [*list("123456789"), "10"]:
            msg = (
                f"Invalid output: {text}. "
                "Output must contain a double bracketed string\
                 with the verdict between 1 and 10."
            )
            raise ValueError(msg)

        return {
            "reasoning": text,
            "score": int(verdict),
        }

Domain

Subdomains

Frequently Asked Questions

What does parse() do?
parse() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py.
Where is parse() defined?
parse() is defined in libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py at line 118.

Analyze Your Own Codebase

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

Try Supermodel Free