Skip to main content

Enum parser

This notebook shows how to use an Enum output parser.

from langchain.output_parsers.enum import EnumOutputParser

API Reference:

from enum import Enum


class Colors(Enum):
RED = "red"
GREEN = "green"
BLUE = "blue"
parser = EnumOutputParser(enum=Colors)
from langchain_core.prompts import PromptTemplate
from langchain_openai import ChatOpenAI

prompt = PromptTemplate.from_template(
"""What color eyes does this person have?

> Person: {person}

Instructions: {instructions}"""
).partial(instructions=parser.get_format_instructions())
chain = prompt | ChatOpenAI() | parser
chain.invoke({"person": "Frank Sinatra"})
<Colors.BLUE: 'blue'>

Find out api documentation for EnumOutputParser.


Help us out by providing feedback on this documentation page: