Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Additional validation for the PredictRequest model
from pydantic import BaseModel, ValidationError, validator
from .ml.model import n_features
class PredictRequest(BaseModel):
data: List[List[float]]
@validator("data")
def check_dimensionality(cls, v):
for point in v:
if len(point) != n_features:
raise ValueError(f"Each data point must contain {n_features} features")
return v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment