LangChain Core โ€” The Building Blocks

Lesson 2: LangChain Core โ€” The Building Blocks

LangChain is the foundation layer: a collection of reusable components for talking to LLMs, plus the glue for composing them. If LangGraph is the brain's control flow, LangChain is the toolbox โ€” models, prompts, parsers, retrievers, and tools that you wire together.

What's actually in the box

The core value is standardized abstractions. Instead of learning each vendor's SDK quirks, you program against a common interface and swap the backend. The most important abstractions:

AbstractionWhat it doesExamples
Chat modelsUnified interface for chat LLMsChatOpenAI, ChatAnthropic, ChatGoogle, local via ChatOllama
Prompt templatesReusable, parameterized promptsChatPromptTemplate, PromptTemplate
Output parsersTurn model text into structured dataStrOutputParser, Pydantic parsers, structured output
Retrievers & vector storesFind relevant context for RAGFAISS, Chroma, PGVector + Retriever wrapper
Document loaders & splittersIngest and chunk source materialPyPDFLoader, RecursiveCharacterTextSplitter
Embedding modelsTurn text into vectorsOpenAIEmbeddings, HuggingFaceEmbeddings
ToolsExpose functions the model can call@tool decorator, built-in search/calculator tools
Message history / memoryRemember prior turnsInMemoryChatMessageHistory, LangGraph checkpoints
Key idea: LangChain's real product is interchangeability. Write once against BaseChatModel; run the same code against OpenAI, Anthropic, or a local model by changing one line. The same pattern repeats across every abstraction.

A minimal example

from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser

model = ChatOpenAI(model="gpt-4o-mini")
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a terse technical writer."),
    ("user", "Explain {topic} in three sentences."),
])
chain = prompt | model | StrOutputParser()

result = chain.invoke({"topic": "retrieval augmented generation"})
print(result)

Notice the | operator: that's LCEL (LangChain Expression Language), the composition syntax we'll dissect in the next lesson. Each piece is a runnable โ€” prompt in, text out โ€” and they chain together.

Package landscape

LangChain is not one package; it's an ecosystem of pip-installable pieces, which keeps your dependency tree lean:

  • langchain-core โ€” the abstractions, runnables, and interfaces (no vendor code)
  • langchain โ€” the main framework: chains, agents, memory, utilities
  • langchain-openai, langchain-anthropic, langchain-google-genai, โ€ฆ โ€” per-vendor integrations
  • langchain-community โ€” community-maintained integrations (broad, less guaranteed)
  • langchain-text-splitters, langchain-docloaders โ€” ingestion utilities
  • langgraph โ€” the orchestration engine (next lesson)
Pitfall: "LangChain" in tutorials often conflates the framework with the ecosystem. If a 2023-era tutorial imports langchain.llms.OpenAI or long-deprecated chains, the API has moved โ€” modern code imports from langchain_openai / langchain_core and prefers LCEL composition. Check the docs' version notes rather than cargo-culting old snippets.

Where LangChain stops

LangChain gives you components and one-shot pipelines. The moment you need loops, branching, persistence, or human approval โ€” the hallmarks of a real agent โ€” a linear chain isn't enough. That's the gap LangGraph fills. LangChain's own guidance has shifted: build the pipeline with LangChain, orchestrate the agent with LangGraph, and don't force everything into a chain.

Rule of thumb: Linear, stateless pipeline โ†’ LangChain + LCEL. Anything with a loop, state, or multiple actors โ†’ LangGraph.

๐Ÿง  Knowledge Check

1. What is the main value of LangChain's abstractions like BaseChatModel?

2. Which package holds the core interfaces (BaseChatModel, prompts, runnables)?

3. When is LangChain + LCEL alone NOT enough?

Further Reading