Bird
0
0

Given the following code snippet, what will be the output?

medium📝 component behavior Q13 of 15
LangChain - Output Parsers
Given the following code snippet, what will be the output?
from langchain.output_parsers import CommaSeparatedListOutputParser
parser = CommaSeparatedListOutputParser()
text = 'apple, banana , cherry, date'
result = parser.parse(text)
print(result)
A['apple banana cherry date']
B['apple, banana , cherry, date']
C['apple', ' banana ', ' cherry', ' date']
D['apple', 'banana', 'cherry', 'date']
Step-by-Step Solution
Solution:
  1. Step 1: Understand parse behavior

    The parser splits the string by commas and trims spaces around each item.
  2. Step 2: Apply trimming to each item

    Items like ' banana ' become 'banana' after trimming.
  3. Final Answer:

    ['apple', 'banana', 'cherry', 'date'] -> Option D
  4. Quick Check:

    Split by comma + trim spaces = A [OK]
Quick Trick: Parser trims spaces after splitting by commas [OK]
Common Mistakes:
  • Not trimming spaces around items
  • Returning the whole string as one item
  • Splitting by spaces instead of commas

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes