Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q7 of 15
LangChain - Output Parsers
What is wrong with this code snippet?
from langchain.output_parsers import StrOutputParser
parser = StrOutputParser
result = parser.parse('test')
AThe string 'test' is invalid input.
BStrOutputParser is not instantiated before calling parse.
CThe import statement is incorrect.
Dparse method does not exist on StrOutputParser.
Step-by-Step Solution
Solution:
  1. Step 1: Check object instantiation

    StrOutputParser must be called with parentheses to create an instance.
  2. Step 2: Identify error cause

    Assigning parser = StrOutputParser without () means parser is a class, not an instance, so parse() call fails.
  3. Final Answer:

    StrOutputParser is not instantiated before calling parse. -> Option B
  4. Quick Check:

    Instantiate class with () before using methods [OK]
Quick Trick: Use parentheses to instantiate classes before method calls [OK]
Common Mistakes:
  • Forgetting () after class name
  • Assuming parse is a static method
  • Misreading import errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes