Bird
0
0

How would you define a nested state schema where OrderState contains a field user of type UserState (defined separately)?

hard📝 Application Q9 of 15
LangChain - LangGraph for Stateful Agents
How would you define a nested state schema where OrderState contains a field user of type UserState (defined separately)?
Aclass OrderState: user: UserState
Bclass OrderState: user = UserState()
Cclass OrderState: user: dict
Dclass OrderState: user: str
Step-by-Step Solution
Solution:
  1. Step 1: Use type hint with the nested schema class

    Declaring user: UserState correctly indicates the field is of type UserState.
  2. Step 2: Check other options for errors

    Assigning an instance directly is not a type hint, dict or str are incorrect types for nested schema.
  3. Final Answer:

    class OrderState:\n user: UserState -> Option A
  4. Quick Check:

    Use type hint with nested schema class name [OK]
Quick Trick: Type hint nested schemas by class name, not instance [OK]
Common Mistakes:
MISTAKES
  • Assigning instance instead of type hint
  • Using generic dict instead of schema type
  • Using wrong type like str for nested schema

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes