Skip to course content
Free FastAPI backend course

FastAPI for AI Backend Development

Module 05 Activity

Scenario

Turn the contract into models that enforce it.

What you build

Request and response models carrying types, policy limits and cross-field rules, separate from internal shapes.

Steps

  1. Write the request and response models and generate the schema. Check it against the contract from Module 1.
  2. Confirm invalid requests never reach the handler by counting handler invocations.
  3. Add the policy limits - ceilings, allowed sets, minimum lengths - to the model rather than the service.
  4. Model any nested structure as a nested model and check the error names the nested path.
  5. Add one cross-field rule using a model validator.
  6. Confirm internal shapes are separate types from the published models.

Evidence to hand in

Review checklist