A programmer intends to construct a basic workflow that performs the following sequence of operations: accepts input from a user, transforms it into an appropriate prompt for an LLM, invokes the LLM, and finally extracts the textual output. When utilizing LangChain Expression Language (LCEL) and specifically the pipe (|) operator, which of the following correctly builds the variable chain?
Answer & explanation
Correct answer: D
WHY D is correct: This is the canonical LCEL minimal chain. The pipe operator (|) chains Runnable objects left-to-right: the PromptTemplate formats the input dict into a prompt message, ChatOpenAI() calls the LLM and returns an AIMessage, and StrOutputParser() extracts the text string. The chain is invoked with chain.invoke({'question': '...'}).
WHY NOT A: The + operator is not a valid chain composition operator in LCEL. Runnable objects are composed with | (pipe), not +.
WHY NOT C: LLMChain is the legacy pre-LCEL API. While it works, it is not LCEL and does not support .stream(), .batch(), or async operations natively. The question specifies LCEL and the pipe-operator approach.
WHY NOT B: StrOutputParser() is not a wrapper constructor that accepts other objects as positional arguments. It is an instantiated Runnable that receives LLM output via | — it cannot be constructed with the prompt and LLM as parameters.