CommaSeparatedListOutputParser Class — langchain Architecture
Architecture documentation for the CommaSeparatedListOutputParser class in list.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 570c1ea0_9f3c_ba85_f3ca_127bf9b2bf02["CommaSeparatedListOutputParser"] 137024f5_2b01_9c8f_64f4_357c533282c7["ListOutputParser"] 570c1ea0_9f3c_ba85_f3ca_127bf9b2bf02 -->|extends| 137024f5_2b01_9c8f_64f4_357c533282c7 39460b97_96ad_60ff_34e4_145e3ec6b305["list.py"] 570c1ea0_9f3c_ba85_f3ca_127bf9b2bf02 -->|defined in| 39460b97_96ad_60ff_34e4_145e3ec6b305 71fc7558_af6e_68ab_2dc8_a1454c7b147c["is_lc_serializable()"] 570c1ea0_9f3c_ba85_f3ca_127bf9b2bf02 -->|method| 71fc7558_af6e_68ab_2dc8_a1454c7b147c 31d2b6e2_95a4_61a8_e6cd_b8e772ad90d9["get_lc_namespace()"] 570c1ea0_9f3c_ba85_f3ca_127bf9b2bf02 -->|method| 31d2b6e2_95a4_61a8_e6cd_b8e772ad90d9 bf2e9af3_be3c_ef07_4817_5e470685f9ef["get_format_instructions()"] 570c1ea0_9f3c_ba85_f3ca_127bf9b2bf02 -->|method| bf2e9af3_be3c_ef07_4817_5e470685f9ef 37c83659_6d94_9955_c8ef_5d62476308d7["parse()"] 570c1ea0_9f3c_ba85_f3ca_127bf9b2bf02 -->|method| 37c83659_6d94_9955_c8ef_5d62476308d7 b3a2d7c4_7ff5_6e9b_7983_3d0acb928117["_type()"] 570c1ea0_9f3c_ba85_f3ca_127bf9b2bf02 -->|method| b3a2d7c4_7ff5_6e9b_7983_3d0acb928117
Relationship Graph
Source Code
libs/core/langchain_core/output_parsers/list.py lines 139–185
class CommaSeparatedListOutputParser(ListOutputParser):
"""Parse the output of a model to a comma-separated list."""
@classmethod
def is_lc_serializable(cls) -> bool:
"""Return `True` as this class is serializable."""
return True
@classmethod
def get_lc_namespace(cls) -> list[str]:
"""Get the namespace of the LangChain object.
Returns:
`["langchain", "output_parsers", "list"]`
"""
return ["langchain", "output_parsers", "list"]
@override
def get_format_instructions(self) -> str:
"""Return the format instructions for the comma-separated list output."""
return (
"Your response should be a list of comma separated values, "
"eg: `foo, bar, baz` or `foo,bar,baz`"
)
@override
def parse(self, text: str) -> list[str]:
"""Parse the output of an LLM call.
Args:
text: The output of an LLM call.
Returns:
A list of strings.
"""
try:
reader = csv.reader(
StringIO(text), quotechar='"', delimiter=",", skipinitialspace=True
)
return [item for sublist in reader for item in sublist]
except csv.Error:
# Keep old logic for backup
return [part.strip() for part in text.split(",")]
@property
def _type(self) -> str:
return "comma-separated-list"
Extends
Source
Frequently Asked Questions
What is the CommaSeparatedListOutputParser class?
CommaSeparatedListOutputParser is a class in the langchain codebase, defined in libs/core/langchain_core/output_parsers/list.py.
Where is CommaSeparatedListOutputParser defined?
CommaSeparatedListOutputParser is defined in libs/core/langchain_core/output_parsers/list.py at line 139.
What does CommaSeparatedListOutputParser extend?
CommaSeparatedListOutputParser extends ListOutputParser.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free