Spot the bug in this LCEL chain that pipes a prompt template into a parser before the model
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Click any words you think contain an error. Click again to unmark.
The parser is in the wrong slot. Output parsers consume model output; the model has to run first. Reorder to prompt | llm | StrOutputParser().
Picture an assembly line. You write a request on a card, the chef cooks the food, the waiter plates it. The bug here is that the waiter is plating the card before the chef ever sees it. Then the chef gets the plated card and tries to do something with that. Reorder so the chef goes between the card-writer and the waiter, and the line works.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
3 minutes: identify the misordered parser, walk the type contract along each pipe, propose the corrected order, and connect the bug to LangChain's permissive runtime behavior.
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_openai import ChatOpenAI
prompt = ChatPromptTemplate.from_template('Summarise: {text}')
llm = ChatOpenAI(model='gpt-4o-mini')
# CORRECT order: prompt produces ChatPromptValue, model consumes it and returns AIMessage,
# parser extracts the .content string.
chain = prompt | llm | StrOutputParser()
result = chain.invoke({'text': 'A long article...'})
assert isinstance(result, str)
# Introspect the chain's input and output types if you want a static check
print(chain.input_schema.schema()) # expects {'text': str}
print(chain.output_schema.schema()) # strReal products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Treating LCEL pipes as syntactic sugar without checking the type contract between each stage. Pipe order is data flow, not decoration.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.