0
0
LangChainframework~20 mins

State schema definition in LangChain - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Langchain State Schema Master
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 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()
A{"name": "Alice"}
B{}
C{"age": null}
D{"name": "Alice", "age": null}
Attempts:
2 left
💡 Hint
Remember that optional fields with default None are included with null in the dict output.
📝 Syntax
intermediate
2: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?
A
class TagState(State):
    tags: [str]
B
class TagState(State):
    tags: List[str]
C
class TagState(State):
    tags: list[str]
D
class TagState(State):
    tags: str[]
Attempts:
2 left
💡 Hint
Use Python 3.9+ native generic types for lists.
🔧 Debug
advanced
2: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()
ASyntaxError: invalid assignment
BTypeError: invalid default value for field 'count'
CNo error, state created with count='zero'
DValueError: cannot assign string to int field
Attempts:
2 left
💡 Hint
Default values must match the declared type in dataclasses.
state_output
advanced
2: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()
A{"name": "Bob", "address": {"city": "NYC", "zip_code": "10001"}}
B{"name": "Bob", "address": "Address(city='NYC', zip_code='10001')"}
C{"name": "Bob", "address": {"city": "NYC"}}
D{"name": "Bob"}
Attempts:
2 left
💡 Hint
Nested states convert to nested dicts when calling dict().
🧠 Conceptual
expert
2:00remaining
Which option best describes the purpose of a Langchain state schema?
What is the main role of a state schema in Langchain?
ATo define structured data models that represent the state of a Langchain component with type safety and validation.
BTo execute asynchronous tasks within Langchain workflows.
CTo style Langchain UI components with CSS variables.
DTo manage database connections and queries in Langchain.
Attempts:
2 left
💡 Hint
Think about how state schemas help organize data in Langchain.