tezvyn:

Model an Order with a nested Product list in Pydantic

Source: pydantic.devintermediate

It tests Pydantic nested model composition. Define Product as BaseModel, then Order with products: list[Product]; Pydantic recursively coerces each dict and raises ValidationError on failure. A red flag is insisting on manual iteration.

It tests declarative schema composition and Pydantic's recursive validation. A strong answer defines Product with name: str and price: float, then Order with products: list[Product]. When Order receives a dict with product dicts, Pydantic instantiates each inner dict as a Product, running type coercion recursively. If any product dict is invalid, Pydantic aggregates errors into a single ValidationError with location details. A red flag is suggesting you need a for-loop or pre-validation function to handle the list manually.

Read the original → pydantic.dev

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Model an Order with a nested Product list in Pydantic · Tezvyn