Skip to main content
Botmartz AI Solution PVT LTD.
LANGCHAIN

LangChain Architecture Overview: Chains, Runnables, LCEL, and the New vs. Old API

LangChain evolved from procedural chains to declarative runnables. Understand LCEL (Language Chain Expression Language), the Runnable protocol, and how it simplifies building complex workflows.

SS
Soham Sharma
AI Engineer, Botmartz · July 17, 2026 · 1 min read
Read Time
1 min
Failure Modes
5
Code Snippets
3
Runnable Notebook
1
LangChain Architecture Overview: Chains, Runnables, LCEL, and the New vs. Old API

LangChain is a framework for building applications with large language models (LLMs). It started as a set of procedural chain classes but evolved into LCEL (Language Chain Expression Language), a declarative way to compose components. Runnables are the foundation: they're objects with a consistent interface (.invoke(), .batch(), .stream()) for chaining operations. This post walks through the architecture, showing how to think in terms of Runnables and when to use them.

Runnables: The Core Abstraction

A Runnable is any object with .invoke() (or .batch(), .stream()) methods. Runnables can be chained with the | operator.

Code Snippet
from langchain.prompts import PromptTemplate
from langchain_openai import ChatOpenAI

# Create components (all Runnables)
template = "You are a helpful assistant. Answer this: {question}"
prompt = PromptTemplate(input_variables=["question"], template=template)
model = ChatOpenAI(model="gpt-4")

# Chain with | operator (LCEL)
chain = prompt | model

# Invoke
response = chain.invoke({"question": "What is 2+2?"})
print(response.content)

Output:

Code Snippet
2 + 2 equals 4.

The | operator chains Runnables. The output of the left side becomes the input to the right side.

Old API vs. New API

Old API: chains were Python classes with custom logic.

Code Snippet
# Old (not recommended)
from langchain.chains import LLMChain
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-4")
prompt = PromptTemplate(input_variables=["question"], template="Q: {question}\nA:")
chain = LLMChain(prompt=prompt, llm=llm)
response = chain.run(question="What is 2+2?")

New API: Runnables are simpler and more composable.

Code Snippet
# New (recommended)
prompt | ChatOpenAI(model="gpt-4")

The new approach is more concise and composable. Prefer it for new code.

Conclusion

LangChain's architecture centers on Runnables—composable objects with a consistent interface. LCEL makes building complex workflows simple and declarative. Understanding the Runnable protocol enables you to extend LangChain with custom components. Next: we'll explore Prompt Templates and Output Parsers—how to structure requests and parse responses.

Closing Takeaways

✓
Measure retrieval precision and recall in isolation before touching the model.
✓
Chunk along document structure, not arbitrary character counts.
✓
Combine vector and keyword search — hybrid retrieval beats either alone.
✓
Treat evaluation as continuous infrastructure, not a launch-week report.
Try It Yourself
A runnable Google Colab notebook with the eval harness and hybrid search code from this post.
#LangChain#Architecture#Runnables#LCEL#LLMs
0 views
SS
Soham Sharma
AI Engineer at Botmartz, building enterprise RAG and agent systems in production. Contributing to open-source libraries.

Discussion (0)

No approved comments yet. Be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *

More Engineering Insights
AI AGENTS
9 min read
AI AGENTS
11 min read
OPEN SOURCE
6 min read
AI ENGINEERING
8 min read
CASE STUDIES
14 min read