Skip to content

Instantly share code, notes, and snippets.

@gurmeetsaran
Created March 26, 2025 23:06
Show Gist options
  • Save gurmeetsaran/e6de9da80ade2043613077e84e9f60cf to your computer and use it in GitHub Desktop.
Save gurmeetsaran/e6de9da80ade2043613077e84e9f60cf to your computer and use it in GitHub Desktop.
Sample Customer Data Model
from typing import Literal
from pydantic import ConfigDict
from wf_avro_base_model.base import WfBaseModel
from wf_avro_base_model.custom import WfDateStr
import wealthfront.wf_types as wt
class SampleCustomer(WfBaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
first_name: wt.FIRST_NAME()()
favourite_hobby: Literal["music", "chess"]
age: wt.SMALLINT(min_value=20, max_value=70)()
dob: WfDateStr
print(SampleCustomer.fake()) # returns random instance of SampleCustomer with first_name='Scott' favourite_hobby='music' age=60 dob='2015-09-18'
print(SampleCustomer.fake(dob="xyz", age=71, favourite_hobby="piano")) # fails with validation error
# pydantic_core._pydantic_core.ValidationError: 3 validation errors for SampleCustomer
# favourite_hobby
# Input should be 'music' or 'chess' [type=literal_error, input_value='piano', input_type=str]
# For further information visit https://errors.pydantic.dev/2.4/v/literal_error
# age
# Input should be less than or equal to 70 [type=less_than_equal, input_value=71, input_type=int]
# For further information visit https://errors.pydantic.dev/2.4/v/less_than_equal
# dob
# invalid date not in YYYY-MM-DD [type=invalid_date, input_value='xyz', input_type=str]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment