This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
backendcritical PriorityID: langchain-modern-lcel-runnable

LangChain Expression Language (LCEL) & Runnable Pipeline Standard

Production standard for LangChain applications using LangChain Expression Language (LCEL). Deprecates legacy AgentExecutor, LLMChain, and initialize_agent in favor of composable Runnable sequences with native streaming, async batching, and LangSmith tracing.

Prohibited Anti-Pattern: AI imports deprecated AgentExecutor or LLMChain from langchain, triggering deprecation crashes in production.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: LangChain Expression Language (LCEL) & Runnable Pipeline Standard - Production standard for LangChain applications using LangChain Expression Language (LCEL). Deprecates legacy AgentExecutor, LLMChain, and initialize_agent in favor of composable Runnable sequences with native streaming, async batching, and LangSmith tracing.
globs: **/*chain*.py, **/*agent*.py, **/*langchain*.ts
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/langchain-modern-lcel-runnable"
---

# LangChain Expression Language (LCEL) & Runnable Pipeline Standard

> **Severity**: CRITICAL | **Category**: backend
> **Anti-Pattern Warning**: AI imports deprecated AgentExecutor or LLMChain from langchain, triggering deprecation crashes in production.

## System Constraints
You are a LangChain platform architect. Never import or use deprecated LangChain v0.1 classes such as LLMChain, initialize_agent, or AgentExecutor. Always construct pipelines using LangChain Expression Language (LCEL) with the pipe operator (|), RunnablePassthrough, and custom tool binding via model.bind_tools().

## Strict Guidelines
- Compose prompt templates, models, and parsers using the LCEL pipe operator (|) rather than LLMChain.
- Implement tool-calling agents using create_tool_calling_agent and modern AgentExecutor from langchain.agents, or prefer LangGraph StateGraph.
- Always implement async streaming with chain.astream() or chain.astream_events() to enable real-time UI token streaming.
- Pass callbacks or LangSmith metadata tags in the config dictionary ({'configurable': {...}, 'tags': [...]}) for end-to-end tracing.

## Bad vs Good Implementations
### Composable LCEL Pipeline vs Deprecated LLMChain

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: LLMChain lacks native token streaming, does not integrate cleanly with async runtimes, and prints deprecation warnings.
```python
# ANTI-PATTERN: Deprecated LLMChain (deprecated in LangChain 0.2/0.3, removed in 1.0)
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from langchain_openai import ChatOpenAI

prompt = PromptTemplate.from_template("Summarize: {topic}")
llm = ChatOpenAI(model="gpt-4o")
chain = LLMChain(llm=llm, prompt=prompt) # DEPRECATED!
res = chain.run("Quantum Computing")
```

#### Production Standard (Correct)
> **Standard**: LCEL provides out-of-the-box support for async streaming, parallel branch execution, batch processing, and LangSmith observability.
```python
# PRODUCTION STANDARD: Modern LangChain LCEL Pipeline
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import RunnablePassthrough
from langchain_openai import ChatOpenAI

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a concise research analyst."),
    ("human", "Summarize key trends in {topic} with citations.")
])
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0.1)
research_chain = ({"topic": RunnablePassthrough()} | prompt | llm | StrOutputParser())

async def run_pipeline(query: str):
    async for chunk in research_chain.astream(query):
        print(chunk, end="", flush=True)
```

### Modern Tool Calling Binding in LCEL

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Zero-shot ReAct prompts are fragile, burn excessive tokens, and fail to leverage model-native tool calling APIs.
```python
# ANTI-PATTERN: Passing tools as strings in legacy agent initializers
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION)
```

#### Production Standard (Correct)
> **Standard**: Binds tools directly into the OpenAI function-calling format with native schema validation.
```python
# PRODUCTION STANDARD: model.bind_tools with structured tool definitions
from langchain_core.tools import tool

@tool
def lookup_inventory(sku: str) -> int:
    """Query warehouse stock for product SKU."""
    return 42

llm_with_tools = ChatOpenAI(model="gpt-4o").bind_tools([lookup_inventory])
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: LangChain Expression Language (LCEL) & Runnable Pipeline Standard

LangChain Expression Language (LCEL) & Runnable Pipeline Standard defines an industrial-grade behavioral standard for backend engineering. Production standard for LangChain applications using LangChain Expression Language (LCEL). Deprecates legacy AgentExecutor, LLMChain, and initialize_agent in favor of composable Runnable sequences with native streaming, async batching, and LangSmith tracing. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: AI imports deprecated AgentExecutor or LLMChain from langchain, triggering deprecation crashes in production. Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftAI imports deprecated AgentExecutor or LLMChain from langchain, triggering deprecation crashes in production.Critical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Compose prompt templates, models, and parsers using the LCEL pipe operator (|) rather than LLMChain.

Compose prompt templates, models, and parsers using the LCEL pipe operator (|) rather than LLMChain.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Implement tool-calling agents using create_tool_calling_agent and modern AgentExecutor from langchain.agents, or prefer LangGraph StateGraph.

Implement tool-calling agents using create_tool_calling_agent and modern AgentExecutor from langchain.agents, or prefer LangGraph StateGraph.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Always implement async streaming with chain.astream() or chain.astream_events() to enable real-time UI token streaming.

Always implement async streaming with chain.astream() or chain.astream_events() to enable real-time UI token streaming.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Pass callbacks or LangSmith metadata tags in the config dictionary ({'configurable'

Pass callbacks or LangSmith metadata tags in the config dictionary ({'configurable': {...}, 'tags': [...]}) for end-to-end tracing.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is LangChain Expression Language (LCEL) & Runnable Pipeline Standard critical for AI coding assistants?

Production standard for LangChain applications using LangChain Expression Language (LCEL). Deprecates legacy AgentExecutor, LLMChain, and initialize_agent in favor of composable Runnable sequences with native streaming, async batching, and LangSmith tracing. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (AI imports deprecated AgentExecutor or LLMChain from langchain, triggering deprecation crashes in production.) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

LangChain