@@ -420,12 +420,14 @@ def validate_value_type(cls, value, info: ValidationInfo):
420
420
return int (value )
421
421
if type_ == DataType .DATETIME :
422
422
return value
423
+ # allows list
423
424
if type_ == DataType .ARRAY :
424
425
if isinstance (value , list ):
425
426
return value
426
427
raise TypeError (f"{ type (value )} does not match "
427
428
f"{ DataType .ARRAY } " )
428
- if type_ == DataType .STRUCTUREDVALUE :
429
+ # allows dict and BaseModel as object
430
+ if type_ == DataType .OBJECT :
429
431
if isinstance (value , dict ):
430
432
value = json .dumps (value )
431
433
return json .loads (value )
@@ -435,11 +437,25 @@ def validate_value_type(cls, value, info: ValidationInfo):
435
437
raise TypeError (
436
438
f"{ type (value )} does not match " f"{ DataType .STRUCTUREDVALUE } "
437
439
)
440
+ # allows list, dict and BaseModel as structured value
441
+ if type_ == DataType .STRUCTUREDVALUE :
442
+ if isinstance (value , (dict , list )):
443
+ value = json .dumps (value )
444
+ return json .loads (value )
445
+ elif isinstance (value , BaseModel ):
446
+ value .model_dump_json ()
447
+ return value
448
+ raise TypeError (
449
+ f"{ type (value )} does not match " f"{ DataType .STRUCTUREDVALUE } "
450
+ )
438
451
452
+ # if none of the above, check if it is a pydantic model
439
453
if isinstance (value , BaseModel ):
440
454
value .model_dump_json ()
441
455
return value
442
456
457
+ # if none of the above, check if serializable. Hence, no further
458
+ # type check is performed
443
459
value = json .dumps (value )
444
460
return json .loads (value )
445
461
0 commit comments