Skip to content
Sharp

FastAPI · interview question

What does a strong engineer do when reasoning through validation code?

Multiple choiceMediumchapter-13-curatedpremiumfastapivalidation
python
class CreateOrderRequest(BaseModel):
    sku: str
    quantity: int

    @field_validator("quantity")
    @classmethod
    def quantity_must_be_positive(cls, value: int) -> int:
        if value <= 0:
            raise ValueError("quantity must be positive")
        return value
Choose one answer
Answer and explanation

Correct answer

D. Narrate the data shape, the state changes, and the exact rule order step by step.

Why

Interviewers often use simple code to test whether you can reason through execution without bluffing.

Test yourself on FastAPI

A free test with instant, explained results. No account needed.

Start free test
All FastAPI questions →