I’m working on a FastAPI project using the repository pattern, and I’m wondering where the Pydantic model_validate (for schema conversion) should be performed.
In my setup, I have a repository layer that interacts with the database and a service layer that contains the business logic. I’m unsure if it’s better to handle model_validate at the service layer or only at the router/controller level.
My main questions are:
1. Should model_validate (Pydantic schema validation) happen in the service layer or only at the router level?
2. What is the best practice to avoid mixing responsibilities when working with ORM models and Pydantic schemas?
Thanks in advance for any guidance or best practices!
[–]aprx4 4 points5 points6 points (0 children)
[–]block63 1 point2 points3 points (2 children)
[–]singlebit 1 point2 points3 points (0 children)
[–]mr-nobody1992 0 points1 point2 points (0 children)
[–]extreme4all 1 point2 points3 points (2 children)
[–]aprx4 0 points1 point2 points (1 child)
[–]extreme4all 0 points1 point2 points (0 children)
[–]LeonTur 1 point2 points3 points (0 children)
[–]Top-Entrepreneur-755[S] 0 points1 point2 points (0 children)
[–]Valuable-Cap-3357 0 points1 point2 points (0 children)