0
0
LangChainframework~20 mins

Parallel execution with RunnableParallel in LangChain - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
RunnableParallel Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this RunnableParallel execution?

Consider two simple runnables that return strings. They are run in parallel using RunnableParallel. What will be the combined output?

LangChain
from langchain.schema.runnable import Runnable
from langchain.schema.runnable.parallel import RunnableParallel

class RunnableA(Runnable):
    def invoke(self, input):
        return f"A received {input}"

class RunnableB(Runnable):
    def invoke(self, input):
        return f"B received {input}"

parallel = RunnableParallel(A=RunnableA(), B=RunnableB())
result = parallel.invoke("test")
print(result)
A['A received test', 'B received test']
B('A received test', 'B received test')
C{'A': 'A received test', 'B': 'B received test'}
D['test', 'test']
Attempts:
2 left
💡 Hint

RunnableParallel returns a dict of results keyed by the branch names.

state_output
intermediate
1:30remaining
What is the output type of RunnableParallel.invoke()?

When you run RunnableParallel.invoke() with multiple runnables, what type of data structure do you get back?

LangChain
from langchain.schema.runnable.parallel import RunnableParallel

parallel = RunnableParallel(a=runnable1, b=runnable2)
result = parallel.invoke("input")
print(type(result))
A<class 'tuple'>
B<class 'str'>
C<class 'list'>
D<class 'dict'>
Attempts:
2 left
💡 Hint

Think about how multiple results are collected from parallel runnables.

📝 Syntax
advanced
2:00remaining
Which option correctly creates a RunnableParallel with three runnables?

You want to run three runnables in parallel. Which code snippet correctly creates a RunnableParallel instance with them?

ARunnableParallel(r1=r1, r2=r2, r3=r3)
BRunnableParallel(r1, r2, r3)
CRunnableParallel({r1, r2, r3})
DRunnableParallel(runnables=[r1, r2, r3])
Attempts:
2 left
💡 Hint

Check the constructor signature for RunnableParallel.

🔧 Debug
advanced
2:30remaining
Why does this RunnableParallel code raise a TypeError?

Given the code below, why does it raise a TypeError when invoking?

LangChain
from langchain.schema.runnable import Runnable
from langchain.schema.runnable.parallel import RunnableParallel

class RunnableX(Runnable):
    def invoke(self, input):
        return input * 2

parallel = RunnableParallel(x=RunnableX(), bad="not a runnable")
result = parallel.invoke(5)
ABecause one branch is not a Runnable instance
BBecause input 5 is not a string
CBecause RunnableX.invoke returns an int, not a string
DBecause RunnableParallel requires exactly one runnable
Attempts:
2 left
💡 Hint

Check the types of elements passed to RunnableParallel.

🧠 Conceptual
expert
3:00remaining
How does RunnableParallel handle exceptions from individual runnables?

If one runnable in a RunnableParallel raises an exception during invoke, what happens to the overall RunnableParallel invocation?

ARunnableParallel retries the failing runnable until it succeeds
BThe exception is propagated immediately and the entire RunnableParallel invocation fails
CThe exception is caught and replaced with None in the results list
DRunnableParallel skips the failing runnable and returns results from others
Attempts:
2 left
💡 Hint

Think about error handling in parallel execution.