Challenge - 5 Problems
Langchain State Schema Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Langchain state schema code?
Consider this Langchain state schema snippet defining a state with a required string and an optional number. What will be the value of
stateData after running the code?LangChain
from langchain.schema import State class MyState(State): name: str age: int | None = None state = MyState(name="Alice") stateData = state.dict()
Attempts:
2 left
💡 Hint
Remember that optional fields with default None are included with null in the dict output.
✗ Incorrect
The state schema includes 'name' as a required string and 'age' as an optional integer defaulting to None. When converted to dict, both fields appear, with 'age' as null.
📝 Syntax
intermediate2:00remaining
Which option correctly defines a Langchain state schema with a list of strings?
You want to define a Langchain state schema with a field
tags that holds a list of strings. Which option is syntactically correct?Attempts:
2 left
💡 Hint
Use Python 3.9+ native generic types for lists.
✗ Incorrect
In Python 3.9+, you can use list[str] directly. List[str] requires importing List from typing. The other options are invalid syntax.
🔧 Debug
advanced2:00remaining
What error does this Langchain state schema code raise?
This code tries to define a state schema with a field
count defaulting to a string instead of an int. What error occurs?LangChain
from langchain.schema import State class CountState(State): count: int = "zero" state = CountState()
Attempts:
2 left
💡 Hint
Default values must match the declared type in dataclasses.
✗ Incorrect
Langchain State uses dataclasses. Assigning a string default to an int field causes a TypeError at class creation.
❓ state_output
advanced2:00remaining
What is the output of this nested Langchain state schema?
Given this nested state schema, what does
user.dict() output?LangChain
from langchain.schema import State class Address(State): city: str zip_code: str class User(State): name: str address: Address user = User(name="Bob", address=Address(city="NYC", zip_code="10001")) output = user.dict()
Attempts:
2 left
💡 Hint
Nested states convert to nested dicts when calling dict().
✗ Incorrect
The nested Address state is converted to a dict inside the User dict output.
🧠 Conceptual
expert2:00remaining
Which option best describes the purpose of a Langchain state schema?
What is the main role of a state schema in Langchain?
Attempts:
2 left
💡 Hint
Think about how state schemas help organize data in Langchain.
✗ Incorrect
State schemas define data structures with types and validation, ensuring consistent state management in Langchain.