Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a conditional routing node that directs based on input.
LangChain
from langchain.graphs import ConditionalRouter router = ConditionalRouter(condition=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a condition that does not return a boolean.
Forgetting to use a lambda function.
✗ Incorrect
The condition lambda x: x == 5 correctly defines a condition for routing when input equals 5.
2fill in blank
mediumComplete the code to add two branches to the conditional router.
LangChain
router.add_branch('yes', [1]) router.add_branch('no', lambda x: False)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a condition that conflicts with the router's main condition.
Not using a lambda function.
✗ Incorrect
The 'yes' branch uses the condition lambda x: x == 5 to route inputs equal to 5.
3fill in blank
hardFix the error in the conditional routing function to correctly route inputs.
LangChain
def route_input(input_value): if input_value [1] 5: return 'yes' else: return 'no'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' causes syntax errors.
Using '=>' is invalid syntax in Python.
✗ Incorrect
The '==' operator correctly compares input_value to 5 for routing decisions.
4fill in blank
hardFill both blanks to define a conditional router with two branches for positive and negative inputs.
LangChain
router = ConditionalRouter(condition=[1]) router.add_branch('positive', [2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing >= and > operators.
Using the same condition for both router and branch.
✗ Incorrect
The router condition checks for non-negative inputs, and the 'positive' branch routes inputs greater than zero.
5fill in blank
hardFill all three blanks to create a conditional router with branches for even, odd, and zero inputs.
LangChain
router = ConditionalRouter(condition=[1]) router.add_branch('even', [2]) router.add_branch('odd', [3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not excluding zero in the router condition.
Mixing up even and odd conditions.
✗ Incorrect
The router condition excludes zero; 'even' branch handles non-zero even numbers; 'odd' branch handles odd numbers.