Bird
0
0

Given the code snippet:

medium📝 state output Q4 of 15
LangChain - Output Parsers
Given the code snippet:
parser = CommaSeparatedListOutputParser()
result = parser.parse('apple, banana, cherry')

What is the value of result?
A'apple banana cherry'
B['apple', 'banana', 'cherry']
C['apple banana cherry']
D'apple, banana, cherry'
Step-by-Step Solution
Solution:
  1. Step 1: Understand the parse method behavior

    The parse method splits the input string by commas and trims spaces.
  2. Step 2: Apply parsing to the input string

    Input 'apple, banana, cherry' becomes list ['apple', 'banana', 'cherry'].
  3. Final Answer:

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

    Parsed list = ['apple', 'banana', 'cherry'] [OK]
Quick Trick: parse() splits string by commas into list [OK]
Common Mistakes:
  • Expecting a single string without splitting
  • Not trimming spaces around items
  • Returning a list with one combined string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes