Skip to main content

CSV parser

This output parser can be used when you want to return a list of comma-separated items.

from langchain.output_parsers import CommaSeparatedListOutputParser
from langchain_core.prompts import PromptTemplate
from langchain_openai import ChatOpenAI

output_parser = CommaSeparatedListOutputParser()

format_instructions = output_parser.get_format_instructions()
prompt = PromptTemplate(
template="List five {subject}.\n{format_instructions}",
partial_variables={"format_instructions": format_instructions},

model = ChatOpenAI(temperature=0)

chain = prompt | model | output_parser
chain.invoke({"subject": "ice cream flavors"})
'Mint Chocolate Chip',
'Cookies and Cream']
for s in{"subject": "ice cream flavors"}):
['Mint Chocolate Chip']
['Cookies and Cream']

Find out api documentation for CommaSeparatedListOutputParser.

Help us out by providing feedback on this documentation page: