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
API Reference:
chain.invoke({"person": "Frank Sinatra"})
<Colors.BLUE: 'blue'>
Find out api documentation for EnumOutputParser.