1. Learn
  2. /
  3. Courses
  4. /
  5. Deploying AI into Production with FastAPI

Connected

Exercise

Custom model validator

You have an API to update inventory and have been asked to surface a user-friendly error message when negative quantities are input.

The RequestValidationError exception has been pre-loaded for you.

Instructions

100 XP
  • Import the annotation for custom model validation.
  • Implement a custom model validation that runs "after" the default model validations.
  • Raise a RequestValidationError exception to surface validation errors to the API user.