Home / Class/ PairwiseStringResultOutputParser Class — langchain Architecture

PairwiseStringResultOutputParser Class — langchain Architecture

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

Entity Profile

Dependency Diagram

graph TD
  3f3ed158_53c1_18b9_92a1_d9692000f02d["PairwiseStringResultOutputParser"]
  7db782f0_522e_d3f7_666f_da5a1e80af4a["eval_chain.py"]
  3f3ed158_53c1_18b9_92a1_d9692000f02d -->|defined in| 7db782f0_522e_d3f7_666f_da5a1e80af4a
  3077a5b4_2c2e_c443_8b81_dd986fdfa721["_type()"]
  3f3ed158_53c1_18b9_92a1_d9692000f02d -->|method| 3077a5b4_2c2e_c443_8b81_dd986fdfa721
  cad0954e_480f_0aad_2b15_e02453b8c257["parse()"]
  3f3ed158_53c1_18b9_92a1_d9692000f02d -->|method| cad0954e_480f_0aad_2b15_e02453b8c257

Relationship Graph

Source Code

libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py lines 99–153

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

    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 {"A", "B", "C"}:
            msg = (
                f"Invalid output: {text}. "
                "Output must contain a double bracketed string\
                 with the verdict 'A', 'B', or 'C'."
            )
            raise ValueError(msg)
        # C means the models are tied. Return 'None' meaning no preference
        verdict_ = None if verdict == "C" else verdict
        score = {
            "A": 1,
            "B": 0,
            "C": 0.5,
        }[verdict]
        return {
            "reasoning": text,
            "value": verdict_,
            "score": score,
        }

Frequently Asked Questions

What is the PairwiseStringResultOutputParser class?
PairwiseStringResultOutputParser is a class in the langchain codebase, defined in libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py.
Where is PairwiseStringResultOutputParser defined?
PairwiseStringResultOutputParser is defined in libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py at line 99.

Analyze Your Own Codebase

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

Try Supermodel Free