Performance: Numeric validation (gt, lt, ge, le)
LOW IMPACT
This affects server-side request validation speed and response time by how quickly numeric constraints are checked before processing.
from fastapi import FastAPI from pydantic import BaseModel, Field app = FastAPI() class Item(BaseModel): price: float = Field(..., gt=0) @app.post('/items/') async def create_item(item: Item): return item
from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() class Item(BaseModel): price: float @app.post('/items/') async def create_item(item: Item): if item.price <= 0: return {'error': 'Price must be greater than 0'} return item
| Pattern | Server CPU Cost | Validation Speed | Frontend Impact | Verdict |
|---|---|---|---|---|
| Manual numeric validation in endpoint | Higher due to extra code | Slower, runs after parsing | None | [!] OK |
| Pydantic gt/lt/ge/le validation | Minimal CPU overhead | Fast, during parsing | None | [OK] Good |