Course Content
LangChain Mastery
7 sections · 109 lessons
What is LangChain, and how is it used in NLP applications?
What you need to know
A real NLP feature is almost never one model call. A support bot has to turn the question into a prompt, find the right help articles, call the model, and turn the reply into something the app can show. LangChain gives you a standard building block for each of those steps, and a standard way to join them.
1from langchain.chat_models import init_chat_model2from langchain_core.prompts import ChatPromptTemplate3from langchain_core.output_parsers import StrOutputParser45llm = init_chat_model("openai:gpt-5.4-mini", temperature=0)6prompt = ChatPromptTemplate.from_messages([7 ("system", "Label the ticket as billing, technical or other. One word only."),8 ("human", "{ticket}"),9])10classify = prompt | llm | StrOutputParser()11print(classify.invoke({"ticket": "I was charged twice for March."})) # billingThe template fills in the ticket, the model replies with an AIMessage, and the parser turns that message into a plain string. Because classify is a Runnable, classify.batch([...]) and classify.stream(...) work with no extra code.
How the project is split (LangChain 1.x)
| Package | What it holds |
|---|---|
langchain-core | The interfaces: Runnables, messages, prompts, parsers, tools |
langchain | init_chat_model, create_agent, middleware |
langchain-openai, langchain-anthropic, ... | One package per provider |
langgraph | The runtime for stateful, looping agents and workflows |
langchain-classic | Legacy LLMChain, RetrievalQA, old memory classes |
langsmith | Tracing, evaluation and prompt management |
Typical NLP uses
- RAG (retrieval-augmented generation): find relevant passages, then answer from them.
- Extraction: turn an invoice or email into a validated Pydantic object.
- Classification and routing: label a ticket and send it to the right flow.
- Agents: the model picks tools (search, SQL, an API) in a loop.
When not to use it
For one fixed prompt and one provider, the provider's own SDK is simpler and has fewer layers to debug. LangChain earns its place when you need several steps, swappable models, retrieval, tracing, or an agent loop.
A real-life example
A Pune SaaS payroll company has 1,400 help-centre articles and gets about 3,000 support chats a day. Their bot is a small LangChain pipeline: a retriever finds the 4 most relevant articles, a ChatPromptTemplate puts them in the prompt with the question, the model answers, and a parser returns the answer plus the article links. When the team later moved from one model provider to another to save cost, they changed one string in init_chat_model; the prompt, retriever and parser code stayed the same. LangSmith tracing showed each step's latency, which is how they found that retrieval, not the model, took 60% of the time.
Follow-up questions to expect
- "How is LangChain different from LangGraph?" — LangChain gives the building blocks and a ready-made agent (
create_agent); LangGraph is the lower-level runtime for stateful graphs with loops, branches, persistence and human approval steps.create_agentruns on LangGraph. - "Is
LLMChainstill used?" — It is deprecated and moved tolangchain-classic. The replacement isprompt | llm | parser. - "Why not just call the OpenAI SDK?" — For one call, do that. LangChain pays off when you need to swap providers, compose steps, stream, batch, or trace.