Skip to content

LangChain Expression Language (LCEL) and Manual Tool Calling

A comprehensive guide to LangChain Expression Language (LCEL) and Manual Tool Calling, two fundamental concepts for building modular, composable, and production-ready AI applications. This note explains how LCEL simplifies chaining prompts, LLMs, tools, retrievers, and output parsers into reusable pipelines while also covering manual tool invocation, structured outputs, validation, enterprise workflow patterns, and best practices.


Part 1 — LangChain Expression Language (LCEL)

1. Overview

As AI applications become more sophisticated, developers need a better way to build, compose, and manage complex AI workflows.

Traditional LangChain development often involved chaining multiple components together using imperative Python code. While effective for simple applications, this approach becomes increasingly difficult to maintain as workflows grow in complexity.

To address this challenge, LangChain introduced the LangChain Expression Language (LCEL).

LCEL provides a declarative way to build AI pipelines by composing reusable building blocks such as prompts, language models, tools, parsers, and business logic.

Instead of writing large amounts of orchestration code, developers can express workflows using simple pipeline operators.

For example:

User Input


Prompt Template


Large Language Model


Output Parser


Final Response

LCEL makes AI applications:

  • Modular
  • Reusable
  • Readable
  • Composable
  • Easier to maintain

Alongside LCEL, developers often use Manual Tool Calling, where the application explicitly controls when and how tools are executed instead of relying entirely on automated agents.

Together, LCEL and Manual Tool Calling provide a powerful foundation for building production-ready AI applications.


2. What is LCEL?

LangChain Expression Language (LCEL) is a declarative framework for composing AI workflows using reusable LangChain components.

Instead of manually coordinating every step, LCEL allows developers to connect components into pipelines.

Think of LCEL as a pipeline language for AI applications.

Example:

Prompt


LLM


Parser


Response

Every component receives an input and produces an output that can be passed to the next component.

LCEL promotes:

  • Simplicity
  • Reusability
  • Modularity
  • Maintainability

It has become the preferred way to build modern LangChain applications.


3. Why LCEL?

Before LCEL, developers manually orchestrated AI workflows.

Example:

Prompt


Call LLM


Receive Response


Parse Output


Return Result

Each step required explicit Python code.

As workflows became larger, applications became:

  • Harder to read
  • Difficult to debug
  • Less reusable
  • Difficult to extend

LCEL solves these problems by allowing developers to compose workflows declaratively.

Benefits include:

  • Cleaner code
  • Less boilerplate
  • Easier testing
  • Better scalability
  • Reusable building blocks

LCEL separates workflow definition from implementation details.


4. Evolution of LangChain Chains

LangChain has evolved significantly.

Traditional Chain

Prompt


LLM


Parser

Implemented using custom Python code.


Sequential Chains

Multiple chains connected together.

Prompt


LLM


Parser


Business Logic

LCEL

Everything becomes a reusable pipeline.

Prompt


LLM


Output Parser


Tool


Response

This evolution greatly simplifies workflow construction.


5. Core Concepts of LCEL

LCEL is built around several important ideas.

Composition

Applications are built by connecting reusable components.


Pipelines

Outputs automatically become inputs for the next component.


Reusability

Each component can be reused across multiple workflows.


Declarative Design

Developers describe what should happen rather than how every step should execute.


Standard Interfaces

Every component follows a common interface.

This consistency allows components to be combined easily.


6. Runnable Interface

At the heart of LCEL is the Runnable interface.

A Runnable is any component capable of:

  • Accepting input
  • Performing an operation
  • Producing output

Examples include:

  • Prompt Templates
  • Large Language Models
  • Output Parsers
  • Python Functions
  • Tool Calls
  • Retrieval Components

Conceptually:

Input


Runnable


Output

Because every component behaves as a Runnable, they can be composed together seamlessly.


7. RunnableSequence

A RunnableSequence executes components one after another.

Each component receives the output of the previous component.

Workflow:

User Input


Prompt


LLM


Parser


Final Output

This is the most common LCEL execution pattern.

Use RunnableSequence when:

  • Steps are dependent
  • Outputs flow sequentially
  • Each stage requires the previous result

Examples include:

  • Question Answering
  • Text Summarization
  • Translation
  • Document Analysis

8. RunnableParallel

Not every task requires sequential execution.

Independent operations can execute simultaneously using RunnableParallel.

Workflow:

            User Input
      ┌──────────┼──────────┐
      ▼          ▼          ▼
Prompt A    Prompt B    Prompt C
      │          │          │
      ▼          ▼          ▼
 LLM A      LLM B      LLM C
      └──────────┼──────────┘
         Combined Result

Benefits include:

  • Reduced latency
  • Better resource utilization
  • Faster execution
  • Improved scalability

RunnableParallel is ideal for independent AI tasks.


9. Pipe (|) Operator

One of LCEL's most recognizable features is the pipe operator (|).

Instead of writing imperative orchestration code, developers connect components using pipelines.

Conceptually:

Prompt

|

LLM

|

Parser

Visual representation:

Prompt


LLM


Parser

Advantages include:

  • Readable workflows
  • Less boilerplate
  • Easier maintenance
  • Simple composition

The pipe operator makes LCEL workflows concise and expressive.


10. Type Coercion

LCEL automatically converts compatible data types between components.

Example:

Prompt


String


LLM


AI Message


Parser


String

Developers do not need to manually perform every conversion.

Advantages include:

  • Simpler code
  • Reduced errors
  • Better interoperability
  • Faster development

Automatic type handling is one of LCEL's productivity features.


11. Output Parsers

Large Language Models typically return free-form text.

Applications often require structured information instead.

Output Parsers transform model responses into usable formats.

Example:

LLM Response


Output Parser


JSON


Application

Common output formats include:

  • JSON
  • Lists
  • Tables
  • Objects
  • Structured records

Benefits include:

  • Easier automation
  • Better validation
  • Reliable downstream processing

Output parsing is essential for production AI systems.


12. Enterprise Use Cases

LCEL enables many enterprise AI applications.

Customer Support

Question


Retriever


LLM


Parser


Response

Combine:

  • Retriever
  • Vector Database
  • LLM
  • Output Parser

Report Generation

Pipeline:

Database


LLM


Formatter


PDF Generator

Document Processing

Workflow:

Document


Parser


LLM


Summary

AI Workflow Automation

Examples include:

  • Email automation
  • Knowledge assistants
  • Code generation
  • Compliance analysis
  • Financial reporting

LCEL provides a consistent, modular way to build these systems.

As AI applications continue to grow in complexity, LCEL has become one of the most important architectural patterns in the LangChain ecosystem. By treating prompts, models, tools, retrievers, and parsers as composable building blocks, developers can create scalable, maintainable, and production-ready AI workflows while significantly reducing orchestration complexity.


Part 2 — Manual Tool Calling

Part 2 — Manual Tool Calling

13. Overview

Large Language Models can determine which tool should be used, but they do not execute tools themselves.

The responsibility of executing a tool always belongs to the application hosting the AI Agent.

This execution model is known as Manual Tool Calling.

Instead of allowing an AI framework to automatically invoke tools, developers explicitly control:

  • When a tool should execute
  • Which tool should execute
  • How arguments are validated
  • How errors are handled
  • How results are returned to the LLM

This approach provides greater flexibility, security, and observability.

Workflow:

User Request
Large Language Model
Generate Tool Call
Application Logic
Execute Tool
Receive Result
Large Language Model
Final Response

Manual Tool Calling is widely used in enterprise AI applications where developers require full control over tool execution.


14. Why Manual Tool Calling?

Many AI frameworks support automatic tool execution, but enterprise systems often prefer manual execution.

Reasons include:

Security

The application decides whether a tool should actually execute.

Example:

LLM


Delete Customer Record

Application:

Permission Check


Reject

Validation

Developers can verify generated parameters before invoking the tool.

Example:

{
  "amount": -500
}

Instead of executing:

Validate


Reject Invalid Input

Logging

Every tool invocation can be recorded.

Example:

  • User
  • Timestamp
  • Tool Name
  • Parameters
  • Result
  • Duration

Compliance

Enterprise environments often require:

  • Approval workflows
  • Audit logs
  • Regulatory checks

Manual execution supports these requirements.


Error Recovery

Applications can:

  • Retry
  • Use fallback tools
  • Notify users
  • Continue workflows

rather than immediately failing.


15. Manual vs Automatic Tool Calling

Both approaches have advantages.

Manual Tool Calling Automatic Tool Calling
Application executes tools Framework executes tools
Greater control Faster development
Easier auditing Less boilerplate
Better security More abstraction
Preferred for enterprise systems Preferred for prototypes

Conceptually:

Automatic:

LLM


Framework


Tool

Manual:

LLM


Application


Validation


Tool

Enterprise AI systems frequently combine both approaches depending on business requirements.


16. Tool Invocation Workflow

Manual Tool Calling follows a structured execution pipeline.

User Request
Prompt
Large Language Model
Generate Tool Call
Validate Arguments
Execute Tool
Receive Output
Generate Final Response

Example:

User


What's the weather in Mumbai?

Workflow:

LLM


Weather Tool


API Response


LLM


Natural Language Answer

Each step is explicitly managed by the application.


17. Parsing Tool Calls

Large Language Models typically return structured information describing the tool they want to invoke.

Example:

{
    "tool":"weather",
    "city":"Mumbai"
}

The application parses this response.

Workflow:

LLM Response


Parse JSON


Identify Tool


Execute Tool

Parsing is responsible for extracting:

  • Tool name
  • Parameters
  • Required fields

before execution.


18. Structured Outputs

One of the biggest advantages of Manual Tool Calling is predictable outputs.

Instead of returning free-form text, tools return structured information.

Example:

{
    "temperature":30,
    "humidity":72,
    "condition":"Sunny"
}

Advantages:

  • Easy parsing
  • Validation
  • Automation
  • Better integration

Structured outputs reduce ambiguity between the LLM and the application.


19. JSON Schema Validation

Before executing a tool, applications validate the generated parameters.

Example schema:

Weather Tool

city

Required

String

Generated output:

{
    "city":"Mumbai"
}

Validation checks:

  • Required fields
  • Correct data types
  • Allowed values
  • Missing parameters
  • Invalid formats

Benefits include:

  • Improved reliability
  • Reduced runtime errors
  • Better security
  • Consistent execution

JSON Schema validation is a best practice in production AI systems.


20. Combining LCEL with Tool Calling

LCEL pipelines can incorporate manual tool execution.

Example:

User


Prompt Template


LLM


Generate Tool Call


Application


Execute Tool


Output Parser


Final Response

This combination enables developers to build modular, reusable AI workflows while retaining full control over external system interactions.

Examples include:

  • RAG pipelines
  • Customer support assistants
  • Data analytics agents
  • Enterprise workflow automation

21. Error Handling

External tools are not always available.

Common failures include:

  • API timeout
  • Network issues
  • Authentication failures
  • Invalid inputs
  • Database unavailable
  • Rate limits

Workflow:

Tool Failure


Retry


Fallback Tool


Notify User


Continue Workflow

Good error handling improves:

  • Reliability
  • User experience
  • Fault tolerance

Applications should never assume that tool execution will always succeed.


22. Best Practices

When implementing Manual Tool Calling:

Validate Every Input

Never trust generated arguments blindly.


Return Structured Data

Prefer JSON over free-form text.


Keep Tools Independent

Each tool should perform one responsibility.


Separate Business Logic

Tool execution should remain independent of prompt engineering.


Log Every Tool Invocation

Record:

  • Tool name
  • Parameters
  • Timestamp
  • Duration
  • Result

Secure Tool Access

Implement:

  • Authentication
  • Authorization
  • Encryption
  • Audit logging

Monitor Tool Performance

Track:

  • Success rate
  • Latency
  • Failures
  • Token usage
  • API cost

Design for Failure

Every workflow should gracefully recover from:

  • Tool failures
  • Invalid inputs
  • External service outages
  • Unexpected outputs

By combining LCEL with Manual Tool Calling, developers gain the flexibility to build modular AI pipelines while maintaining complete control over how tools are validated, executed, monitored, and secured. This approach is widely adopted in enterprise AI systems where reliability, governance, and observability are just as important as intelligent reasoning.


Part 3 — Enterprise Perspective

23. Common Mistakes

Although LCEL and Manual Tool Calling make AI applications significantly more modular and maintainable, improper implementation can lead to brittle workflows, security vulnerabilities, and difficult-to-debug systems.

Below are some of the most common mistakes made when building production AI applications.


Writing Large Monolithic Pipelines

Many developers build one massive LCEL pipeline that performs every task.

Example:

Prompt


LLM


Retriever


Parser


Tool


Database


Python


Email


Response

Problems include:

  • Difficult debugging
  • Poor readability
  • Low reusability
  • Hard maintenance

Instead, break workflows into smaller reusable pipelines.

Example:

Retrieval Pipeline

Analysis Pipeline

Reporting Pipeline

Notification Pipeline

Smaller pipelines are easier to test, reuse, and maintain.


Using LCEL for Everything

LCEL is excellent for composing AI workflows, but not every part of an application belongs inside a pipeline.

Business logic such as:

  • Authentication
  • Authorization
  • Billing
  • Transactions
  • Database updates

should remain in application code.

A good rule is:

Reasoning → LCEL

Business Logic → Application

Skipping Validation

Never assume the LLM always produces correct outputs.

Example:

{
    "customer_id": ""
}

Before executing any tool:

  • Validate required fields
  • Verify data types
  • Check ranges
  • Apply business rules

Validation prevents failures and security issues.


Blindly Executing Tool Calls

One of the biggest mistakes is immediately executing every generated tool call.

Unsafe example:

Delete Customer


Execute

Safe workflow:

Generate Tool Call


Validate


Permission Check


Execute

Enterprise applications should never trust generated actions without verification.


Ignoring Structured Outputs

Free-form text is difficult to automate.

Poor output:

It looks sunny today.

Better:

{
    "temperature":30,
    "condition":"Sunny"
}

Structured outputs make downstream processing predictable and reliable.


Poor Error Handling

Every external dependency can fail.

Examples:

  • Network timeout
  • API unavailable
  • Invalid credentials
  • Database connection failure

Instead of terminating the workflow:

Retry


Fallback


Graceful Error


Continue

Design workflows that recover from failures whenever possible.


Ignoring Monitoring

Production AI applications require observability.

Monitor:

  • Pipeline latency
  • Tool execution time
  • Success rate
  • Token consumption
  • API cost
  • Error rate

Monitoring provides visibility into workflow performance and reliability.


Exposing Sensitive Tools

Never expose high-privilege enterprise operations directly to an LLM.

Examples:

Delete Database

Approve Payment

Terminate Employee

Protect sensitive operations using:

  • Authentication
  • Authorization
  • Human Approval
  • Audit Logs

Security should always be part of workflow design.


24. Interview Questions

Beginner

  • What is LCEL?
  • Why was LCEL introduced?
  • What is a Runnable?
  • What is RunnableSequence?
  • What is RunnableParallel?
  • What is Manual Tool Calling?
  • Why are structured outputs important?

Intermediate

  • Explain the Runnable Interface.
  • What is the Pipe (|) Operator?
  • Compare RunnableSequence and RunnableParallel.
  • What is Type Coercion?
  • How does Manual Tool Calling work?
  • Why is JSON Schema Validation important?
  • How can LCEL and Tool Calling be combined?

Advanced

  • Design a production-ready LCEL workflow.
  • How would you secure Manual Tool Calling?
  • How would you validate tool arguments?
  • How would you monitor an LCEL pipeline?
  • How would you optimize latency in complex AI workflows?
  • Compare LCEL with traditional orchestration approaches.

25. 🚀 Quick Revision Sheet

LCEL Pipeline

User Input


Prompt


LLM


Parser


Response

Runnable Interface

Input


Runnable


Output

RunnableSequence

Runnable A


Runnable B


Runnable C

RunnableParallel

          Input
    ┌───────┼────────┐
    ▼       ▼        ▼
Run A    Run B    Run C
    └───────┼────────┘
        Combined Output

Manual Tool Calling

LLM


Generate Tool Call


Validate


Execute Tool


Result


LLM

Enterprise Workflow

Prompt


LLM


Tool Call


Validation


Execution


Parser


Business Logic


Response

LCEL Components

  • Prompt Template
  • Runnable
  • RunnableSequence
  • RunnableParallel
  • RunnablePassthrough
  • Output Parser
  • Tool Calling
  • Business Logic

Best Practices

  • Build modular pipelines.
  • Keep workflows reusable.
  • Validate every tool call.
  • Prefer structured outputs.
  • Separate business logic from AI workflows.
  • Monitor latency and token usage.
  • Secure enterprise integrations.
  • Design for failure.

Remember

LCEL provides a declarative way to compose AI applications using reusable pipelines, while Manual Tool Calling gives developers explicit control over how tools are validated, executed, and monitored. Together, they enable the development of modular, maintainable, secure, and production-ready AI systems that combine intelligent reasoning with reliable execution across enterprise environments.


26. Key Takeaways

  • LangChain Expression Language (LCEL) simplifies AI application development by allowing prompts, LLMs, retrievers, tools, and output parsers to be composed into modular, reusable pipelines.
  • The Runnable Interface provides a common abstraction that enables components to be chained sequentially or executed in parallel using RunnableSequence and RunnableParallel.
  • The Pipe (|) Operator makes LCEL workflows concise, readable, and easier to maintain compared to imperative orchestration code.
  • Manual Tool Calling provides developers with explicit control over tool execution, validation, security, and observability, making it well suited for enterprise applications.
  • Structured outputs and JSON Schema validation improve reliability by ensuring predictable communication between LLMs and application logic.
  • Combining LCEL with Manual Tool Calling enables flexible AI workflows that integrate prompts, reasoning, retrieval, business logic, and external systems while maintaining governance and security.
  • Production-ready AI systems should emphasize modularity, validation, monitoring, error handling, authentication, and scalability, ensuring workflows remain maintainable as applications grow in complexity.

27. References

Course

  • IBM RAG & Agentic AI Professional Certificate
  • Module: Fundamentals of Building AI Agents

Documentation

  • LangChain Expression Language (LCEL) Documentation
  • LangChain Runnable Documentation
  • LangChain Tool Calling Documentation
  • LangChain Output Parser Documentation
  • OpenAI Function Calling Documentation
  • IBM watsonx.ai Documentation

Hands-on Resources

  • 01-AI-Math-Assistant-With-Langchain-Tool-Calling
  • 02-AI-Powered-Data-Analysis-With-LCEL
  • 03-Build-Interactive-LLM-Agents-With-Tools

Repository Placement

Repository
└── ibm-rag-and-agentic-ai-journey
    └── notes
        └── ai-agents
            ├── 01-ai-agent-fundamentals.md
            ├── 02-tool-calling-and-function-calling.md
            ├── 03-building-and-orchestrating-tools.md
            ├── 04-lcel-and-manual-tool-calling.md
            ├── 05-langchain-built-in-agents.md
            ├── 06-ai-agent-design-best-practices.md
            └── 07-enterprise-ai-agent-architecture.md

🎯 Foundation for Modular AI Workflows

This note introduces the architectural principles that make modern AI applications modular, maintainable, and production-ready.

The learning progression continues as follows:

  1. AI Agent Fundamentals — Understand AI Agents, reasoning, and architecture.
  2. Tool Calling and Function Calling — Learn how AI Agents interact with external tools.
  3. Building and Orchestrating Tools — Design reusable tools and coordinate multi-step workflows.
  4. LCEL and Manual Tool Calling (this note) — Compose reusable AI pipelines and control tool execution with validation and governance.
  5. LangChain Built-in Agents — Explore pre-built agents such as DataFrame Agents and SQL Agents.
  6. AI Agent Design Best Practices — Apply engineering principles for security, observability, scalability, and reliability.
  7. Enterprise AI Agent Architecture — Combine LLMs, RAG, tools, memory, governance, and monitoring into enterprise-scale AI systems.

Together, these notes provide a complete roadmap from understanding AI Agent fundamentals to building modular, enterprise-grade AI applications that are secure, maintainable, and ready for production deployment.


Diagrams to Include

LCEL Pipeline

User Input
Prompt Template
Large Language Model
Output Parser
Final Response

RunnableSequence

Prompt
LLM
Parser
Application

RunnableParallel

                User Input
        ┌────────────┼────────────┐
        ▼            ▼            ▼
     Prompt A     Prompt B     Prompt C
        │            │            │
        ▼            ▼            ▼
      LLM A        LLM B        LLM C
        └────────────┼────────────┘
              Combined Output

Manual Tool Calling

User Request
Large Language Model
Generate Tool Call
Application Executes Tool
Tool Result
Large Language Model
Final Response

LCEL + Tool Calling

User
Prompt
LLM
Tool Call
Execute Tool
Output Parser
Response

Enterprise LCEL Workflow

User
Prompt Template
LCEL Pipeline
 ├────────► Retriever
 ├────────► Tool Calling
 ├────────► Output Parser
 ├────────► Validation
 └────────► Business Logic
Enterprise Response

Enterprise AI Engineering Handbook
Building Production-Grade Enterprise AI Systems — One Chapter at a Time.