Bird
Raised Fist0
LangChainframework~20 mins

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

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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.

Practice

(1/5)
1. What is the main purpose of using RunnableParallel in langchain?
easy
A. To run multiple tasks at the same time to save time
B. To run tasks one after another in a fixed order
C. To stop tasks from running automatically
D. To run only one task repeatedly

Solution

  1. Step 1: Understand RunnableParallel's role

    RunnableParallel is designed to run tasks together, not sequentially.
  2. Step 2: Identify the benefit

    Running tasks in parallel saves time by doing them simultaneously.
  3. Final Answer:

    To run multiple tasks at the same time to save time -> Option A
  4. Quick Check:

    Parallel execution = run tasks together [OK]
Hint: RunnableParallel means tasks run together, not one by one [OK]
Common Mistakes:
  • Thinking RunnableParallel runs tasks one after another
  • Confusing parallel with repeated single task
  • Assuming it stops tasks automatically
2. Which of the following is the correct way to create a RunnableParallel with two tasks named task1 and task2?
easy
A. RunnableParallel{task1, task2}
B. RunnableParallel(task1, task2)
C. RunnableParallel({"task1": task1, "task2": task2})
D. RunnableParallel(task1 + task2)

Solution

  1. Step 1: Recall RunnableParallel syntax

    RunnableParallel expects a dictionary {"name": task} as its argument.
  2. Step 2: Match options to syntax

    Only RunnableParallel({"task1": task1, "task2": task2}) passes a dict {"task1": task1, "task2": task2}, others use wrong syntax.
  3. Final Answer:

    RunnableParallel({"task1": task1, "task2": task2}) -> Option C
  4. Quick Check:

    Dict of tasks = {"task1": task1, "task2": task2} [OK]
Hint: Use curly braces {} to pass {"name": task} dictionary [OK]
Common Mistakes:
  • Passing tasks as separate positional arguments
  • Using invalid set syntax {}
  • Trying to add tasks with + operator
3. Given the code:
parallel = RunnableParallel({"taskA": taskA, "taskB": taskB})
results = parallel.invoke()
print(results)

If taskA returns 'Hello' and taskB returns 'World', what will be printed?
medium
A. {'taskB': 'World', 'taskA': 'Hello'}
B. ['HelloWorld']
C. 'Hello World'
D. {'taskA': 'Hello', 'taskB': 'World'}

Solution

  1. Step 1: Understand RunnableParallel output order

    RunnableParallel returns a dict with results in the order keys are defined.
  2. Step 2: Match task results to output dict

    taskA under 'taskA' returns 'Hello' first, taskB under 'taskB' returns 'World' second, so {'taskA': 'Hello', 'taskB': 'World'}.
  3. Final Answer:

    {'taskA': 'Hello', 'taskB': 'World'} -> Option D
  4. Quick Check:

    Order of results matches dict definition order [OK]
Hint: Results dict order matches task definition order [OK]
Common Mistakes:
  • Reversing the order of task results
  • Thinking results are combined into one string
  • Expecting a list instead of dict output
4. What is wrong with this code snippet?
parallel = RunnableParallel(task1, task2)
results = parallel.invoke()
medium
A. RunnableParallel requires tasks inside a dictionary, not separate arguments
B. invoke() method does not exist on RunnableParallel
C. You must call run() instead of invoke()
D. RunnableParallel cannot run more than one task

Solution

  1. Step 1: Check RunnableParallel constructor usage

    RunnableParallel expects a dictionary of tasks, not separate positional arguments.
  2. Step 2: Identify the error in code

    Passing task1, task2 as separate positional arguments causes a TypeError.
  3. Final Answer:

    RunnableParallel requires tasks inside a dictionary, not separate arguments -> Option A
  4. Quick Check:

    Tasks must be in a dictionary [OK]
Hint: Always use a dictionary or named kwargs for RunnableParallel tasks [OK]
Common Mistakes:
  • Passing tasks as separate positional arguments
  • Using wrong method name instead of invoke()
  • Thinking RunnableParallel runs only one task
5. You want to run three independent tasks taskX, taskY, and taskZ in parallel and combine their results into a single string separated by commas. Which code correctly does this?
hard
A. parallel = RunnableParallel(taskX, taskY, taskZ) results = parallel.invoke() combined = ','.join(results) print(combined)
B. parallel = RunnableParallel({"taskX": taskX, "taskY": taskY, "taskZ": taskZ}) results = parallel.invoke() combined = ','.join(results.values()) print(combined)
C. results = [taskX(), taskY(), taskZ()] combined = ','.join(results) print(combined)
D. parallel = RunnableParallel([taskX, taskY, taskZ]) combined = parallel.invoke().join(',') print(combined)

Solution

  1. Step 1: Create RunnableParallel with dictionary of tasks

    parallel = RunnableParallel({"taskX": taskX, "taskY": taskY, "taskZ": taskZ}) results = parallel.invoke() combined = ','.join(results.values()) print(combined) correctly passes tasks as a dictionary to RunnableParallel.
  2. Step 2: Invoke and join results properly

    This calls invoke() to get dict results, then joins the values with commas correctly.
  3. Step 3: Check other options for errors

    parallel = RunnableParallel(taskX, taskY, taskZ) results = parallel.invoke() combined = ','.join(results) print(combined) passes tasks incorrectly as positional; C runs tasks sequentially; D uses invalid list and misuses join.
  4. Final Answer:

    Using RunnableParallel({"taskX": taskX, "taskY": taskY, "taskZ": taskZ}) and ','.join(results.values()) -> Option B
  5. Quick Check:

    Dict tasks + invoke + join values = correct [OK]
Hint: Pass tasks as dict, invoke, then ','.join(results.values()) [OK]
Common Mistakes:
  • Passing tasks without dictionary syntax
  • Calling join() on the wrong object
  • Running tasks sequentially instead of parallel