Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãOPromptsLanguage modelsOutput parsersList parserDatetime parserEnum parserAuto-fixing parserPydantic (JSON) parserRetry parserStructured output parserXML parserRetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesMoreModulesModel I/‚ÄãOOutput parsersEnum parserEnum parserThis notebook shows how to use an Enum output parser.from langchain.output_parsers.enum import EnumOutputParserfrom enum import Enumclass Colors(Enum):    RED = "red"    GREEN = "green"    BLUE = "blue"parser = EnumOutputParser(enum=Colors)parser.parse("red")    <Colors.RED: 'red'># Can handle spacesparser.parse(" green")    <Colors.GREEN: 'green'># And new linesparser.parse("blue\n")    <Colors.BLUE: 'blue'># And raises errors when appropriateparser.parse("yellow")    ---------------------------------------------------------------------------    ValueError                                Traceback (most recent call last)    File ~/workplace/langchain/langchain/output_parsers/enum.py:25, in EnumOutputParser.parse(self, response)         24 try:    ---> 25     return self.enum(response.strip())         26 except ValueError:    File ~/.pyenv/versions/3.9.1/lib/python3.9/enum.py:315, in EnumMeta.__call__(cls, value, names, module, qualname, type, start)        314 if names is None:  # simple value lookup    --> 315     return cls.__new__(cls, value)        316 # otherwise, functional API: we're creating a new Enum type    File ~/.pyenv/versions/3.9.1/lib/python3.9/enum.py:611, in Enum.__new__(cls, value)        610 if result is None and exc is None:    --> 611     raise ve_exc        612 elif exc is None:    ValueError: 'yellow' is not a valid Colors        During handling of the above exception, another exception
This notebook shows how to use an Enum output parser.
This notebook shows how to use an Enum output parser. ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãOPromptsLanguage modelsOutput parsersList parserDatetime parserEnum parserAuto-fixing parserPydantic (JSON) parserRetry parserStructured output parserXML parserRetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesMoreModulesModel I/‚ÄãOOutput parsersEnum parserEnum parserThis notebook shows how to use an Enum output parser.from langchain.output_parsers.enum import EnumOutputParserfrom enum import Enumclass Colors(Enum):    RED = "red"    GREEN = "green"    BLUE = "blue"parser = EnumOutputParser(enum=Colors)parser.parse("red")    <Colors.RED: 'red'># Can handle spacesparser.parse(" green")    <Colors.GREEN: 'green'># And new linesparser.parse("blue\n")    <Colors.BLUE: 'blue'># And raises errors when appropriateparser.parse("yellow")    ---------------------------------------------------------------------------    ValueError                                Traceback (most recent call last)    File ~/workplace/langchain/langchain/output_parsers/enum.py:25, in EnumOutputParser.parse(self, response)         24 try:    ---> 25     return self.enum(response.strip())         26 except ValueError:    File ~/.pyenv/versions/3.9.1/lib/python3.9/enum.py:315, in EnumMeta.__call__(cls, value, names, module, qualname, type, start)        314 if names is None:  # simple value lookup    --> 315     return cls.__new__(cls, value)        316 # otherwise, functional API: we're creating a new Enum type    File ~/.pyenv/versions/3.9.1/lib/python3.9/enum.py:611, in Enum.__new__(cls, value)        610 if result is None and exc is None:    --> 611     raise ve_exc        612 elif exc is None:    ValueError: 'yellow' is not a valid Colors        During handling of the above exception, another exception