PythiloLesson 1 of 20 · progress kept in this browser

Parse a boundary with BaseModel

Type hints describe a Python function, but they do not validate a dictionary received from JSON. A Pydantic model turns that boundary into executable rules. Constructing the model converts supported input values and rejects values that cannot satisfy the field types.

The result is a model instance with typed attributes. Use model_dump() to produce a dictionary for the next layer. Keep the original input available when diagnosing bad data; validation should not mutate the caller's dictionary.

from pydantic import BaseModel

class Count(BaseModel):
    value: int

item = Count(value="12")
print(item.value, type(item.value).__name__)
print(item.model_dump())
Your task

Define User with integer id and string name. Implement load_user(raw) returning its validated dictionary. Accept integer strings for id, ignore unknown fields, and reject missing or invalid fields.

The first run loads pydantic into this browser.