Bird
0
0

Why does this routing code cause a runtime error?

medium📝 Debug Q7 of 15
LangChain - LangGraph for Stateful Agents
Why does this routing code cause a runtime error?
conditions = [lambda ctx: ctx['value'] > 0, lambda ctx: ctx['value'] <= 0]
ctx = {}
Actx should be a list, not a dictionary
BLambda functions are not defined properly
CConditions overlap causing infinite loop
Dctx dictionary lacks 'value' key causing KeyError
Step-by-Step Solution
Solution:
  1. Step 1: Identify cause of runtime error

    ctx is empty dictionary, so ctx['value'] access raises KeyError.
  2. Step 2: Verify other options

    Lambdas are correct, no infinite loop, and ctx type is correct as dict.
  3. Final Answer:

    ctx dictionary lacks 'value' key causing KeyError -> Option D
  4. Quick Check:

    Missing key in ctx causes KeyError [OK]
Quick Trick: Ensure context keys exist before access [OK]
Common Mistakes:
MISTAKES
  • Blaming lambda syntax
  • Thinking conditions cause loops
  • Confusing data types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes