Skip to content

Commit 5afd6ec

Browse files
committed
fix: 根据修复意见修改,字段被显式设为 None 时的类型兼容,如Risks: null 的反序列化
1 parent 0214f38 commit 5afd6ec

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

volcenginesdkllmshield/api/llm_shield_sdk_v2.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ class RiskV2(BaseModel):
107107
prob: Optional[float] = Field(None, alias="Prob")
108108
matches: List[RiskMatchV2] = Field([], alias="Matches")
109109

110+
@field_validator('matches', mode="before")
111+
def convert_risk_matches_none_to_list(cls, value):
112+
return [] if value is None else value
113+
110114
class Config:
111115
populate_by_name = True
112116

@@ -130,6 +134,10 @@ class PermitV2(BaseModel):
130134
prob: Optional[float] = Field(None, alias="Prob")
131135
matches: List[PermitMatchV2] = Field([], alias="Matches")
132136

137+
@field_validator('matches', mode="before")
138+
def convert_permit_matches_none_to_list(cls, value):
139+
return [] if value is None else value
140+
133141
class Config:
134142
populate_by_name = True
135143

@@ -176,6 +184,10 @@ class DecisionV2(BaseModel):
176184
decision_strategy_id: Optional[str] = Field(None, alias="DecisionStrategyID")
177185
hit_strategy_ids: List[str] = Field([], alias="HitStrategyIDs")
178186

187+
@field_validator('hit_strategy_ids', mode="before")
188+
def convert_hit_strategies_none_to_list(cls, value):
189+
return [] if value is None else value
190+
179191
class Config:
180192
populate_by_name = True
181193

0 commit comments

Comments
 (0)