Home / Class/ ScoreStringResultOutputParser Class — langchain Architecture

ScoreStringResultOutputParser Class — langchain Architecture

Architecture documentation for the ScoreStringResultOutputParser class in eval_chain.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  6acf5938_7ff0_bc21_f7a7_c41e88e0ddec["ScoreStringResultOutputParser"]
  66e0c4fe_40d5_039b_24a9_26eb6155c2cc["eval_chain.py"]
  6acf5938_7ff0_bc21_f7a7_c41e88e0ddec -->|defined in| 66e0c4fe_40d5_039b_24a9_26eb6155c2cc
  31dba8aa_f4b0_d82f_77ae_00b78bcc73ad["_type()"]
  6acf5938_7ff0_bc21_f7a7_c41e88e0ddec -->|method| 31dba8aa_f4b0_d82f_77ae_00b78bcc73ad
  04d1798b_2e3d_c994_9073_b128237591cb["parse()"]
  6acf5938_7ff0_bc21_f7a7_c41e88e0ddec -->|method| 04d1798b_2e3d_c994_9073_b128237591cb

Relationship Graph

Source Code

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

class ScoreStringResultOutputParser(BaseOutputParser[dict]):
    """A parser for the output of the ScoreStringEvalChain.

    Attributes:
        _type: The type of the output parser.

    """

    @property
    def _type(self) -> str:
        """Return the type of the output parser.

        Returns:
            The type of the output parser.

        """
        return "pairwise_string_result"

    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),
        }

Frequently Asked Questions

What is the ScoreStringResultOutputParser class?
ScoreStringResultOutputParser is a class in the langchain codebase, defined in libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py.
Where is ScoreStringResultOutputParser defined?
ScoreStringResultOutputParser is defined in libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py at line 100.

Analyze Your Own Codebase

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

Try Supermodel Free