Skip to content

Instantly share code, notes, and snippets.

@cosmic-cortex
Created January 27, 2020 16:26
Show Gist options
  • Save cosmic-cortex/928f746e9d895889ce19f6a3dbe5a856 to your computer and use it in GitHub Desktop.
Save cosmic-cortex/928f746e9d895889ce19f6a3dbe5a856 to your computer and use it in GitHub Desktop.
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