Spot the bug in this LCEL chain that pipes a prompt template into a parser before the model
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.
Detailed answer & concept explanation~5 min readEverything 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. 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.
- LangChain's official LCEL examples uniformly show prompt | model | parser ordering
- LangSmith traces of this buggy chain visually expose the misordered hops as type-mismatched steps
- Production teams running Claude Opus 4.7 and GPT-5.5 chains add chain-output type assertions in CI to catch this class of bug
- Vercel AI SDK avoids this category entirely by exposing model calls as functions rather than pipes
What an interviewer would ask next. Try answering before peeking at the approach.
QWhat does StrOutputParser actually do under the hood, and when would PydanticOutputParser be the right choice instead?
QWhy does the chain not raise a clean TypeError even though there is a type mismatch?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
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.
Same topic, related formats. Practice these next.