NCA-GENL - Experimentation (22% of the exam) - Section 3.5
Use LangChain to organise and compose LLM workflows.
Use LangChain to compose LLM-powered workflows by chaining prompts, memory, tools, and retrievers into coherent pipelines for tasks such as document question answering and autonomous agents. Recognise how LangChain abstractions like chains, agents, and document loaders reduce boilerplate and simplify experimentation.
LangChain
Practice question for this objective
lock_openFree sampleExperimentationmedium
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 responsecheck_circle 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
Identify OutputParsers as the correct LangChain component for transforming raw LLM responses into structured or cleaned output values. When a LangChain chain calls an LLM, the response is an AIMessage or a raw string depending on the model wrapper. An OutputParser sits at the end of the chain and converts that raw response into the desired Python type - a string, a list, a Pydantic model, or any structured object. StrOutputParser strips the message envelope to a plain string, making it ideal for label extraction. Agents, memory, and verbose settings all serve different purposes and do not perform response parsing.
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.
Answers that look right on this material and are not. Each one is a distractor from a different question in the NCA-GENL bank for this domain.
Enable verbose mode on the model object, which prints token-by-token output to standard error for later collection.
errorWhy it is wrong: Tempting because verbose mode does emit some output, but it is console-oriented and per-component, not a structured per-step event stream for a dashboard, so it does not capture latency and usage cleanly across the chain.
RunnableSequence, which passes the input through each branch one after another so every branch sees the transformed output of the previous one
errorWhy it is wrong: RunnableSequence is a core LCEL construct, so it is a believable answer, but it chains steps serially where each consumes the prior output, which is the opposite of running three independent branches on the same original input.
Wrap the function with RunnablePassthrough, which executes the callable on the input and substitutes its return value before forwarding to the next step
errorWhy it is wrong: RunnablePassthrough is a real composition helper, which is the trap, but in its bare form it forwards the input unchanged and does not run a transformation function, so it would not apply the trimming and lower-casing.