Pydantic model định nghĩa schema cho request body, response, settings hoặc object trung gian. FastAPI dùng model để validate input, serialize output và sinh OpenAPI schema.
Model nên tách theo use-case: UserCreate cho input tạo mới, UserRead cho response, UserUpdate cho partial update. Không nên expose trực tiếp database model nếu nó có field nhạy cảm như password hash hoặc internal flags.
Pydantic models define schemas for request bodies, responses, settings or intermediate objects. FastAPI uses them to validate input, serialize output and generate OpenAPI schemas.
Models should be split by use case: UserCreate for create input, UserRead for responses and UserUpdate for partial updates. Do not expose database models directly if they contain sensitive fields such as password hashes or internal flags.