0
0
LangChainframework~15 mins

RunnablePassthrough and RunnableLambda in LangChain - Mini Project: Build & Apply

Choose your learning style9 modes available
Using RunnablePassthrough and RunnableLambda in Langchain
📖 Scenario: You are building a simple text processing pipeline using Langchain. You want to pass data through unchanged in one step, and then transform it with a custom function in the next step.
🎯 Goal: Create a Langchain pipeline that first uses RunnablePassthrough to pass input text unchanged, then uses RunnableLambda to convert the text to uppercase.
📋 What You'll Learn
Import RunnablePassthrough and RunnableLambda from langchain_core.runnables
Create a RunnablePassthrough instance named passthrough
Create a RunnableLambda instance named to_upper that converts input text to uppercase
Call invoke on passthrough with the string 'hello world'
Call invoke on to_upper with the output from passthrough
💡 Why This Matters
🌍 Real World
RunnablePassthrough and RunnableLambda help build flexible data pipelines where some steps pass data unchanged and others apply custom transformations.
💼 Career
Understanding these runnables is useful for building modular, reusable components in Langchain workflows, common in AI and automation jobs.
Progress0 / 4 steps
1
Import RunnablePassthrough and RunnableLambda
Import RunnablePassthrough and RunnableLambda from langchain_core.runnables.
LangChain
Need a hint?

Use a single import statement to import both classes from langchain_core.runnables.

2
Create RunnablePassthrough instance
Create a RunnablePassthrough instance named passthrough.
LangChain
Need a hint?

Create the instance by calling RunnablePassthrough() and assign it to passthrough.

3
Create RunnableLambda instance to uppercase text
Create a RunnableLambda instance named to_upper that converts input text to uppercase using a lambda function.
LangChain
Need a hint?

Use RunnableLambda with a lambda that calls upper() on the input string.

4
Invoke passthrough and then to_upper
Call invoke on passthrough with the string 'hello world' and assign the result to passed_text. Then call invoke on to_upper with passed_text and assign the result to upper_text.
LangChain
Need a hint?

Use invoke method on both instances and assign their outputs to variables as instructed.