Module 1: Foundations

What Is LangChain

Learning objectives

  • Explain the core mental model behind What Is LangChain
  • Apply What Is LangChain within Foundations
  • Identify important boundaries, trade-offs, and failure modes
  • Produce concrete evidence from the practice exercise

Related: LangChain Why It Exists | LangChain Core Concepts | LangChain Architecture Overview | LangChain Index


A Working Definition

LangChain is a framework for building applications with LLMs through composability. It provides a standard interface for chaining together different components — models, prompts, parsers, memory, tools, and retrievers — into coherent pipelines.

A precise one-line definition:

LangChain is a toolkit that turns raw LLM calls into structured, reusable, and observable workflows.

That definition has four operative words:

Toolkit. Not a single library. LangChain is an ecosystem: langchain-core (abstractions), langchain (integrations), langchain-community (community integrations), and partner packages (langchain-openai, langchain-anthropic, etc.).

Raw LLM calls. A direct API call returns text. LangChain wraps that call with input validation, prompt templating, output parsing, error handling, and retry logic.

Reusable. Components are designed as interchangeable primitives. Swap GPT-4 for Claude, or a vector DB for a keyword index, without rewriting the pipeline.

Observable. Built-in callbacks, tracing (LangSmith), and streaming hooks let you inspect what happens inside a chain.


LangChain vs Direct LLM Usage

A direct LLM call:

import openai
response = openai.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "What is RAG?"}]
)
print(response.choices[0].message.content)

A LangChain chain:

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

model = ChatOpenAI(model="gpt-4")
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a helpful assistant."),
    ("human", "What is {topic}?")
])
parser = StrOutputParser()

chain = prompt | model | parser
result = chain.invoke({"topic": "RAG"})

The difference is not just syntax. The LangChain version:

  • Separates concerns (prompt vs model vs parser)
  • Is composable (prompt | model | parser is a runnable graph)
  • Can be batched, streamed, or traced without rewriting the logic
  • Can swap the model by changing one line

LangChain vs Other Frameworks

FrameworkCenter of gravityMental model
Direct API callsThe prompt"I am calling a function"
LangChainComposable chains"I am building a pipeline of LLM-shaped nodes"
LlamaIndexData ingestion and retrieval"I am building a knowledge engine"
HaystackDocument search pipelines"I am building a search system"
Hermes / OpenClawAgent runtime"I am running an agent loop"

LangChain sits in the middle. It is general-purpose: you can build simple chains, complex agents, or retrieval pipelines with the same set of abstractions.


Philosophy

Composability

The pipe operator (|) is the central design metaphor. If prompt A, model B, and parser C are all Runnable, then A | B | C is also a Runnable. This lets you build arbitrarily complex systems from simple, tested parts.

Interoperability

LangChain does not own the model, the vector DB, or the tool. It owns the interface. Any component that implements the BaseChatModel, BaseRetriever, or BaseTool interface can be dropped into a chain.

Observability by default

Every Runnable supports callbacks, metadata, and tags. When you attach a LangSmith tracer, you get a full execution graph without instrumenting each step manually.


What LangChain Is Not

  • Not a model provider. You bring your own API keys and models.
  • Not a vector database. It interfaces with dozens, but stores nothing itself.
  • **Not an agent framework only.** Agents are one pattern; most LangChain usage is simple chains.
  • Not a no-code platform. You write Python (or TypeScript); there is no drag-and-drop UI.
  • Not magic. Every step is a deterministic function call or an LLM call. If you understand both, you understand the chain.

A One-Sentence Mental Model to Carry Forward

A LangChain pipeline is a directed graph of Runnable nodes, where edges are data flow and each node is a deterministic transform or an LLM call.

Everything else — agents, memory, retrieval — is a specific arrangement of those nodes. Keep it pinned for the rest of the course.

See LangChain Chains for the deep dive.


Related

  • LangChain Why It Exists — the problems that motivate the framework
  • LangChain Core Concepts — the vocabulary used everywhere else
  • LangChain Architecture Overview — the block diagram of the runtime
  • LangChain Chains — how to build and run chains
  • LangChain Index — full topic map

Practice lab

Implement the smallest runnable agent workflow that demonstrates What Is LangChain. Trace inputs, state, model and tool calls, outputs, and cost; inject one failure and add a regression test that prevents it from returning.

Review questions

  1. What problem does What Is LangChain solve, and what assumptions does it rely on?
  2. Which boundary or failure case is easiest to miss, and how would you expose it?
  3. What alternative design would you consider, and what trade-off would change the decision?
  4. What artifact, trace, test, or metric proves that your implementation is correct?

Completion evidence

  • A working artifact, annotated trace, or reproducible experiment
  • At least one normal case and one deliberately failing or boundary case
  • A concise explanation of the design choice and its trade-offs
  • Saved output showing how correctness was evaluated