enum.py — langchain Source File
Architecture documentation for enum.py, a python file in the langchain codebase. 5 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 36204980_b3d8_1700_6a4c_b79b8665ecf2["enum.py"] 36204980_b3d8_1700_6a4c_b79b8665ecf2["enum.py"] 36204980_b3d8_1700_6a4c_b79b8665ecf2 --> 36204980_b3d8_1700_6a4c_b79b8665ecf2 75137834_4ba7_dc43_7ec5_182c05eceedf["langchain_core.exceptions"] 36204980_b3d8_1700_6a4c_b79b8665ecf2 --> 75137834_4ba7_dc43_7ec5_182c05eceedf 83d7c7fd_1989_762c_9cf3_cecb50ada22b["langchain_core.output_parsers"] 36204980_b3d8_1700_6a4c_b79b8665ecf2 --> 83d7c7fd_1989_762c_9cf3_cecb50ada22b f4d905c6_a2b2_eb8f_be9b_7808b72f6a16["langchain_core.utils"] 36204980_b3d8_1700_6a4c_b79b8665ecf2 --> f4d905c6_a2b2_eb8f_be9b_7808b72f6a16 91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"] 36204980_b3d8_1700_6a4c_b79b8665ecf2 --> 91721f45_4909_e489_8c1f_084f8bd87145 36204980_b3d8_1700_6a4c_b79b8665ecf2["enum.py"] 36204980_b3d8_1700_6a4c_b79b8665ecf2 --> 36204980_b3d8_1700_6a4c_b79b8665ecf2 style 36204980_b3d8_1700_6a4c_b79b8665ecf2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from enum import Enum
from langchain_core.exceptions import OutputParserException
from langchain_core.output_parsers import BaseOutputParser
from langchain_core.utils import pre_init
from typing_extensions import override
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
Subdomains
Classes
Dependencies
- enum.py
- langchain_core.exceptions
- langchain_core.output_parsers
- langchain_core.utils
- typing_extensions
Source
Frequently Asked Questions
What does enum.py do?
enum.py is a source file in the langchain codebase, written in python. It belongs to the OutputParsing domain, StreamingParsers subdomain.
What does enum.py depend on?
enum.py imports 5 module(s): enum.py, langchain_core.exceptions, langchain_core.output_parsers, langchain_core.utils, typing_extensions.
What files import enum.py?
enum.py is imported by 1 file(s): enum.py.
Where is enum.py in the architecture?
enum.py is located at libs/langchain/langchain_classic/output_parsers/enum.py (domain: OutputParsing, subdomain: StreamingParsers, directory: libs/langchain/langchain_classic/output_parsers).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free