List parser | ğŸ¦œï¸�ğŸ”— Langchain






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 parsersList parserList parserThis output parser can be used when you want to return a list of comma-separated items.from langchain.output_parsers import CommaSeparatedListOutputParserfrom langchain.prompts import PromptTemplate, ChatPromptTemplate, HumanMessagePromptTemplatefrom langchain.llms import OpenAIfrom langchain.chat_models import ChatOpenAIoutput_parser = CommaSeparatedListOutputParser()format_instructions = output_parser.get_format_instructions()prompt = PromptTemplate(    template="List five {subject}.\n{format_instructions}",    input_variables=["subject"],    partial_variables={"format_instructions": format_instructions})model = OpenAI(temperature=0)_input = prompt.format(subject="ice cream flavors")output = model(_input)output_parser.parse(output)The resulting output will be:    ['Vanilla',     'Chocolate',     'Strawberry',     'Mint Chocolate Chip',     'Cookies and Cream']PreviousOutput parsersNextDatetime parserCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright Â© 2023 LangChain, Inc.
This output parser can be used when you want to return a list of comma-separated items.
This output parser can be used when you want to return a list of comma-separated items. ->: List parser | ğŸ¦œï¸�ğŸ”— Langchain






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 parsersList parserList parserThis output parser can be used when you want to return a list of comma-separated items.from langchain.output_parsers import CommaSeparatedListOutputParserfrom langchain.prompts import PromptTemplate, ChatPromptTemplate, HumanMessagePromptTemplatefrom langchain.llms import OpenAIfrom langchain.chat_models import ChatOpenAIoutput_parser = CommaSeparatedListOutputParser()format_instructions = output_parser.get_format_instructions()prompt = PromptTemplate(    template="List five {subject}.\n{format_instructions}",    input_variables=["subject"],    partial_variables={"format_instructions": format_instructions})model = OpenAI(temperature=0)_input = prompt.format(subject="ice cream flavors")output = model(_input)output_parser.parse(output)The resulting output will be:    ['Vanilla',     'Chocolate',     'Strawberry',     'Mint Chocolate Chip',     'Cookies and Cream']PreviousOutput parsersNextDatetime parserCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright Â© 2023 LangChain, Inc.