LangChain Architecture: Models, Prompts, Chains
The three building blocks: ChatModels, PromptTemplates, and chains that compose them.
LangChain Architecture: Models, Prompts, Chains is a free AI Agents lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AI Agents learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why LangChain?
LangChain is the most popular Python framework for building LLM apps. It provides:
- Adapters for every major LLM provider
- Loaders and parsers for many data sources
- Memory, agents, and chains primitives
- Vector store integrations
Critics call it bloated; supporters love its breadth. We focus on the core that has stabilised: LCEL.
Three Core Concepts
- Models — LLMs and ChatModels you call
- Prompts — templates that produce messages
- Chains — compositions that pipe prompts -> models -> parsers
Models
A unified interface across providers:
from langchain_openai import ChatOpenAI
from langchain_anthropic import ChatAnthropic
openai_model = ChatOpenAI(model='gpt-4o-mini', temperature=0.2)
claude_model = ChatAnthropic(model='claude-sonnet-4-5')
resp = openai_model.invoke('Hello!')
print(resp.content)Prompt Templates
Reusable prompts with variables:
from langchain.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages([
('system', 'You are a {role} assistant.'),
('user', '{question}')
])
messages = prompt.invoke({'role': 'SQL', 'question': 'How do I delete rows?'})
print(messages.to_messages())Chains: The Pipe Operator
Combine a prompt + model + parser with |:
from langchain.schema.output_parser import StrOutputParser
chain = prompt | openai_model | StrOutputParser()
result = chain.invoke({'role': 'SQL', 'question': 'How do I delete rows?'})
print(result)Output Parsers
Convert raw model output to Python types:
from langchain.output_parsers import PydanticOutputParser
from pydantic import BaseModel
class Plan(BaseModel):
steps: list[str]
parser = PydanticOutputParser(pydantic_object=Plan)
chain = prompt | model | parserRunnables and the Runnable Protocol
Every chain element is a Runnable with:
.invoke(input)— synchronous.ainvoke(input)— async.stream(input)— token streaming.batch(inputs)— parallel batches
The pipe operator composes them.
Streaming
for chunk in chain.stream({'role': 'helpful', 'question': 'Tell a story.'}):
print(chunk, end='', flush=True)Batch
results = chain.batch([
{'role': 'SQL', 'question': 'Q1'},
{'role': 'SQL', 'question': 'Q2'}
])
# Runs in parallel.Configuration at Runtime
Override model parameters per call:
result = chain.invoke(
{'role': 'helpful', 'question': '...'},
config={'configurable': {'temperature': 0.0}}
)LangChain Hub
Pull community-curated prompts:
from langchain import hub
rag_prompt = hub.pull('rlm/rag-prompt')When NOT to Use LangChain
For very simple agents (one model call, one tool), LangChain is over-engineered. Write the call directly. Use LangChain when you need composability, retries, observability, and tested integrations.
Chain Operator
What does the | operator do in LangChain?
Recap
Models + Prompts + Chains, glued by |. Next: loaders and vector stores in the LangChain ecosystem.
Frequently asked questions
Is the “LangChain Architecture: Models, Prompts, Chains” lesson free?
Yes — the full text of “LangChain Architecture: Models, Prompts, Chains” is free to read here on the web, and the AI Agents course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AI Agents course, upgrade to CoddyKit PRO.
What will I learn in “LangChain Architecture: Models, Prompts, Chains”?
The three building blocks: ChatModels, PromptTemplates, and chains that compose them. You practise AI Agents with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AI Agents?
No prior experience is required. AI Agents on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “LangChain Architecture: Models, Prompts, Chains” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AI Agents lesson?
Yes. Every AI Agents lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- LangChain Architecture: Models, Prompts, Chains
- Loaders, Splitters and Vector Stores
- LCEL (LangChain Expression Language)
- Building a RAG Chain End-to-End