Home / Class/ EnumOutputParser Class — langchain Architecture

EnumOutputParser Class — langchain Architecture

Architecture documentation for the EnumOutputParser class in enum.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  6fc8a8d3_a1ed_0021_4545_b3b83ed1da09["EnumOutputParser"]
  36204980_b3d8_1700_6a4c_b79b8665ecf2["enum.py"]
  6fc8a8d3_a1ed_0021_4545_b3b83ed1da09 -->|defined in| 36204980_b3d8_1700_6a4c_b79b8665ecf2
  b5b6c2a2_f183_1e7e_ccc5_0215a3281034["_raise_deprecation()"]
  6fc8a8d3_a1ed_0021_4545_b3b83ed1da09 -->|method| b5b6c2a2_f183_1e7e_ccc5_0215a3281034
  5f7c0e5c_3f6d_f5a1_05a5_ad8eebaea4e6["_valid_values()"]
  6fc8a8d3_a1ed_0021_4545_b3b83ed1da09 -->|method| 5f7c0e5c_3f6d_f5a1_05a5_ad8eebaea4e6
  909f69c9_ad09_730b_309c_8f43b4b960f4["parse()"]
  6fc8a8d3_a1ed_0021_4545_b3b83ed1da09 -->|method| 909f69c9_ad09_730b_309c_8f43b4b960f4
  77298582_0e44_6c93_b7df_961790a8f794["get_format_instructions()"]
  6fc8a8d3_a1ed_0021_4545_b3b83ed1da09 -->|method| 77298582_0e44_6c93_b7df_961790a8f794
  b16f1d5f_19bc_e8c4_23b3_cf62f43dd3c9["OutputType()"]
  6fc8a8d3_a1ed_0021_4545_b3b83ed1da09 -->|method| b16f1d5f_19bc_e8c4_23b3_cf62f43dd3c9

Relationship Graph

Source Code

libs/langchain/langchain_classic/output_parsers/enum.py lines 9–45

class EnumOutputParser(BaseOutputParser[Enum]):
    """Parse an output that is one of a set of values."""

    enum: type[Enum]
    """The enum to parse. Its values must be strings."""

    @pre_init
    def _raise_deprecation(cls, values: dict) -> dict:
        enum = values["enum"]
        if not all(isinstance(e.value, str) for e in enum):
            msg = "Enum values must be strings"
            raise ValueError(msg)
        return values

    @property
    def _valid_values(self) -> list[str]:
        return [e.value for e in self.enum]

    @override
    def parse(self, response: str) -> Enum:
        try:
            return self.enum(response.strip())
        except ValueError as e:
            msg = (
                f"Response '{response}' is not one of the "
                f"expected values: {self._valid_values}"
            )
            raise OutputParserException(msg) from e

    @override
    def get_format_instructions(self) -> str:
        return f"Select one of the following options: {', '.join(self._valid_values)}"

    @property
    @override
    def OutputType(self) -> type[Enum]:
        return self.enum

Domain

Frequently Asked Questions

What is the EnumOutputParser class?
EnumOutputParser is a class in the langchain codebase, defined in libs/langchain/langchain_classic/output_parsers/enum.py.
Where is EnumOutputParser defined?
EnumOutputParser is defined in libs/langchain/langchain_classic/output_parsers/enum.py at line 9.

Analyze Your Own Codebase

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

Try Supermodel Free