All quizzes
Free quiz · 20 questions in the bank

Pydantic quiz

Test your Pydantic knowledge with a free interactive quiz — 20 questions with answers and explanations. No signup needed to play.

Question 1/5Score 0

What is a discriminated union (or "tagged union") pattern in Pydantic, and what problem does it solve?

Questions in this quiz
  1. What is a discriminated union (or "tagged union") pattern in Pydantic, and what problem does it solve?
  2. How does Pydantic use standard Python type hints, e.g. `age: int`, differently from how type hints are normally used in Python?
  3. What does Pydantic's BaseSettings (in the separate `pydantic-settings` package for v2) provide?
  4. What is the purpose of Pydantic's `alias` feature on a field, e.g. `user_id: int = Field(alias="userId")`?
  5. What is a major architectural/performance change introduced in Pydantic v2 compared to v1?
  6. What is Pydantic?
  7. What is the purpose of `Optional[X]` (or `X | None` in modern Python) combined with a default value in a Pydantic field definition?
  8. What does the `.model_dump()` method (v2) or `.dict()` method (v1) do on a Pydantic model instance?
  9. What is a common reason to use separate Pydantic models for a request body versus a response body in a FastAPI endpoint (e.g. `UserCreate` vs. `UserOut`)?
  10. What is the purpose of a Pydantic `model_config` (v2) setting like `frozen=True` on a model?
  11. Why might validating configuration and environment variables with Pydantic (via BaseSettings) at application startup be preferable to reading raw environment variables ad hoc throughout the codebase?
  12. What is a Pydantic "validator" (e.g. via `@field_validator` in Pydantic v2, or `@validator` in v1) used for?
Gaps to close?
Read the curated Pydantic notes — core concepts, patterns, interview prep.
Pydantic notes

More quizzes

.NET.NET MAUIAbsintheAccessibilityActixActix Web