The first app I built with an LLM in it was an email tool. Pick a template, fill in the blanks, done. Or let the model write the whole email for you.
The template part was easy. The LLM part needed real engineering.
I wrote my own system to keep the structure of a prompt separate from the user’s data, so a prompt change didn’t mean touching five places. I wrote the glue between model calls. And I had to think about what happens when people send weird input to the model.
Those are exactly the problems LangChain is built to solve. So I took Pluralsight’s Introduction to LangChain to see how a framework handles them. Here’s what it gets right, where the course oversells it, and what’s still up to you.
Easy to Build, Hard to Ship
Building a demo with AI in it is easy. Making it production ready is hard.
The reason is simple. A normal function gives you the same output for the same input. An LLM doesn’t. Ask it the same thing twice and you get two different answers. That’s fine for a chatbot demo. It’s not fine when the output goes into a database or another system.
LangChain’s pitch is structured and predictable LLM applications. It sits between your application (UI, business logic, data) and the model provider, and handles the prompts, the chains and the output parsing.
In practice that means:
- It connects prompts, models, memory and tools
- It gives you a predictable workflow
- It removes a lot of fragile glue code
That last one is the real value. Glue code is where LLM apps quietly break.
One Big Prompt Is Not Software
The most common anti-pattern in LLM apps is the mega-prompt. “First do this, then do that, then format it like this.”
It works, sort of. But you can’t see the outcome of each step. You don’t control what comes out in between. When the final answer is wrong, you have no idea which step went wrong.
That’s not software. That’s an experiment you run again and hope for a better result.
The fix is prompt chaining. Split the work into small steps, and the output of one step becomes the input of the next. Every transformation is explicit, so you can inspect, test and swap each step on its own.
A nice side effect: you can use a cheap model for the small, boring steps and save the expensive model for the step that actually needs it.
The Building Blocks
LangChain has five core components:
- Prompt Template: the input to the model
- Model: generates text based on text
- Output Parser: turns that text into something your code can use
- Callbacks: events you can hook into while it runs
- Chain: wires all of the above into one workflow
Prompt Templates
Think of a prompt template as a function signature for your prompt. The fixed instructions are defined once, and the variable data is injected at runtime.
Summarize: {text}
Inject text = "Hi I'm Evert" and you get Summarize: Hi I'm Evert. Nothing fancy. But it kills manual string concatenation, and a prompt change happens in one place.
It’s the same pattern I built by hand for the email app. Here it’s a standard component.
For chat models there’s ChatPromptTemplate. Instead of one string, the input is a list of messages: a system message, a human message, and optionally an assistant message. Structure and data stay separated.
LCEL: Pipes, Like Linux
LangChain Expression Language (LCEL) wires the components together with |, just like a Linux pipe.
chain = prompt | model | parser
The prompt goes into the model, the model output goes into the parser. It turns imperative code (“call this, then take the result and call that”) into a declarative pipeline. If you’ve ever written cat file | grep foo | sort, it reads naturally right away.
Output Parsers
An output parser turns the unpredictable text an LLM produces into structured data. There are a few levels:
StrOutputParsergives you a Python stringListOutputParsergives you a Python listJsonOutputParsergives you a Python dictPydanticOutputParsergives you a typed Python object
StrOutputParser shows up in almost every example. A chat model returns an AIMessage object with content, metadata, tool calls and so on. The parser pulls out the text, so the next step gets a plain str.
The Pydantic parser is where it gets useful. Extracting structured data from a customer review:
from typing import Literal
from pydantic import BaseModel
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import PydanticOutputParser
class Review(BaseModel):
customer_name: str
product: str
sentiment: Literal["Positive", "Neutral", "Negative"]
parser = PydanticOutputParser(pydantic_object=Review)
prompt = ChatPromptTemplate.from_messages([
("system", "Extract the customer name, product and sentiment.\n{format_instructions}"),
("human", "{text}"),
]).partial(format_instructions=parser.get_format_instructions())
chain = prompt | model | parser
review = chain.invoke({
"text": "Hi, I'm Evert. I recently bought the new Wireless Headphones "
"from your store. The sound quality is excellent and the battery "
"lasts all day. I'm really happy with my purchase!"
})
# Review(customer_name='Evert', product='Wireless Headphones', sentiment='Positive')
Two details make this work:
get_format_instructions()returns a plain string you put in your prompt. It tells the model how to format its answer so the parser can read it. For a list parser that’s a bit thin: “Your response should be a list of comma separated values”. With Pydantic it generates a proper schema description from your class, and that works well..partial()pre-fills some of the template’s variables and returns a new template. The format instructions are baked in once, instead of passed on everyinvoke.
Few-Shot Examples Do the Heavy Lifting
The simplest technique is also one of the most effective. If you want consistent output, give the model examples.
The course used IT incident severity. Put a few past incidents and their severity in the prompt, and the model ranks new incidents the same way. Add rules on top: if it affects 100 people, it’s high. If it only affects Diana from HR, it’s low.
No fine-tuning, no magic. Just examples.
A Parser Doesn’t Ensure Anything
The course says an output parser validates the output against a schema, “ensuring predictable results”.
That’s overselling it. A parser checks. It doesn’t fix. It tells you, after the fact, that the model got it wrong.
Predictability comes from what you do next. There are four options:
- Retry with a correction prompt. Send the model its own bad output plus the error (“field
pricemust be a number, got ’ten euros’”) and ask again. Models are good at fixing a mistake once you point it out. LangChain hasRetryOutputParserfor this, and.with_retry()for plain re-attempts. Cap the retries: every one costs a model call. - Reformat automatically. Repair the output without asking the original question again. That can be plain code, like stripping markdown fences around JSON, or a small second model call that only reformats. That’s
OutputFixingParser. Cheaper than a full retry, but it only fixes formatting, not wrong content. - Fall back to a safe default. Return something you know is valid: an empty list, an “unknown” category, or the answer from a different model. That’s
.with_fallbacks([...]). Make sure downstream code can tell a default from a real answer. - Log and fail predictably. Record the raw output, the error and the input, then raise a clear exception. The alternative is a half-parsed result crashing something three steps later, or bad data quietly landing in a table.
safe_chain = chain.with_retry(stop_after_attempt=3).with_fallbacks([fallback_chain])
The parser is the check. The failure plan is the guarantee.
Controlling How It Runs
With more than one chain, you need to decide how they run together:
- Sequential:
prompt | model | parser, one after another - Parallel:
RunnableParallelfeeds several chains the same input and combines the results - Conditional: route to a different path based on the result, a bit like a pattern match
Then there’s RunnableLambda. It wraps a normal Python function so it becomes a step in a chain, with the same interface as every other component: invoke, batch, stream and the | operator. Ideal for the small bits of logic between model calls.
One distinction worth keeping: context is your application data. It travels through the chain and shapes the output. Metadata describes the execution. It’s for tracing and debugging, and it doesn’t change the output.
If You Have No Data, You Can’t Debug
When a chain fails, you need to see what happened at each step. Otherwise you’re guessing.
LangChain’s answer is callbacks. Extend BaseCallbackHandler, implement methods like on_chain_start, on_llm_start, on_llm_end and on_chain_end, and pass the handler in when you invoke:
workflow.invoke(
{"text": "..."},
config={"callbacks": [MyHandler()], "metadata": {"run": "test"}},
)
The course example only prints each step. The real value is further down the road: tracing every step in production, catching schema drift, and checking exactly what each step hands to the next.
The Hard Part Isn’t the Framework
LangChain looks simple, and the API mostly is. The hard part is design: how do you cut your logic into steps? Ten tiny chains, or a few bigger ones? Which steps belong together?
No course answers that. It comes from building things, and it’s the same judgement call as splitting any codebase into functions.
Then there’s the weird-input problem from my email app. Prompt templates keep instructions and user data apart, and that helps. But separating them isn’t the same as defending against them. Prompt injection deserves its own post.
What I’m Taking With Me
Treat prompts like code. Small steps you can see, test and swap out. That’s the difference between an experiment and software.
A parser checks, it doesn’t fix. Predictability comes from validation plus a plan for when validation fails.
The course did one thing really well: every question I had was answered in the next video. That doesn’t happen often.
LangChain won’t design your app for you. But it takes care of the glue, so you can focus on the parts that matter.
Evert