01. What is LangChain?
LangChain is an open-source framework for composing applications around large language models. It provides abstractions for prompts, model invocations, output parsing, state management, and tool use—organized into logical components that you string together into chains. The documentation categorizes these into three layers: the LangChain library (Python + JavaScript, the core abstractions), LangChain Templates (pre-built chains for common patterns like RAG), and LangChain Components (integrations with 50+ external services and model providers).
The core abstraction is the Chain. A chain is any Python callable that takes a dictionary of inputs, optionally calls an LLM or other component, and returns a dictionary of outputs. This uniformity means you can substitute a simple prompt chain for a complex multi-step pipeline without rewriting your application code. The pattern looks like this:
from langchain.schema import BaseOutputParser
class InspectionChain:
"""Demonstrates the minimal chain interface."""
input_keys: list[str] = ["user_input"]
output_keys: list[str] = ["result"]
def __call__(self, inputs: dict) -> dict:
user_input = inputs["user_input"]
# Do work here: call LLM, run regex, hit API
result = f"Processed: {user_input}"
return {"result": result}
LangChain ships factories for common chain types: LLMChain, ConversationChain, RetrievalQAChain, RouterChain, and sequential variants (SimpleSequentialChain, SequentialChain). Each wraps the pattern above with specific behaviors.
The version used in this course is LangChain 0.1.x (Python). The API changed significantly between 0.0.x and 0.1.x, particularly around memory management and the chat model abstraction. If you find answers online that use from langchain.schema import HumanMessage, those apply to 0.0.x. In 0.1.x, import from langchain_core.messages instead:
# 0.1.x compatible imports
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_ollama import ChatOllama # new integration path
LangChain does not run models. You still need an LLM backend (Ollama, OpenAI, Anthropic, etc.). LangChain orchestrates the calls, manages state between steps, and shapes inputs/outputs into types that your application can consume. The "local AI" part of this course means using Ollama as the backend because it runs GGUF-format models on your own hardware, requires no API keys, and exposes a local HTTP API that LangChain connects to.
One concrete failure mode to name upfront: LangChain's rate-limiting, retry logic, and streaming support vary by integration. Ollama's integration does not natively support retrieval-augmented generation (RAG) indexing—for that you add a vector store integration (covered in Part 2). This course focuses on operator-controlled components, not cloud-managed ones.
Inspect your installed LangChain version and list what modules are importable. Run pip show langchain to confirm version, then attempt from langchain.chains import LLMChain in a Python REPL. If the import fails, check whether you need langchain-core installed separately.