A data science team uses LangChain to build a multi-step pipeline: first summarise a document, then classify the summary into one of five categories. The team wants the classification step to receive only a clean category label string, not a raw JSON blob. Which LangChain mechanism should they add after the classification LLM call to achieve this?
- AReplace the classification LLM call with a zero-shot agent so that the agent decides the category and returns only plain text by default
- BAttach an OutputParser, such as a StrOutputParser or a custom parser, to the classification chain so that it extracts and returns the label string from the model response Correct
- CSet the chain's verbose flag to False so that intermediate JSON tokens are suppressed from the final output string
- DStore the raw JSON output in ConversationBufferMemory and retrieve only the category field in the next chain invocation
Why A is wrong: Replacing a deterministic classification step with a zero-shot agent introduces unnecessary overhead, unpredictable intermediate actions, and does not guarantee a clean label output - it is a heavier tool for a problem that parsing solves simply.
Why B is correct: OutputParsers are the LangChain abstraction responsible for transforming a raw model response into a typed or cleaned Python value. StrOutputParser returns the content string directly, while custom parsers can extract a specific field - exactly the right tool for producing a clean label.
Why C is wrong: The verbose flag controls logging/tracing output to the terminal; it has no effect on the actual string value returned by the chain to the caller. The model's raw JSON reply would still be present in the chain's output.
Why D is wrong: Memory is designed to persist conversational context across turns, not to parse structured fields out of a single model response. Using memory here adds complexity without addressing the parsing requirement.