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.runnablesCreate a
RunnablePassthrough instance named passthroughCreate a
RunnableLambda instance named to_upper that converts input text to uppercaseCall
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