2222
2323from guardrails_api_client import (
2424 Guard as IGuard ,
25- ValidatorReference ,
2625 ValidatePayload ,
2726 SimpleTypes ,
2827 ValidationOutcome as IValidationOutcome ,
3635from guardrails .classes .rc import RC
3736from guardrails .classes .validation .validation_result import ErrorSpan
3837from guardrails .classes .validation .validation_summary import ValidationSummary
38+ from guardrails .classes .validation .validator_reference import ValidatorReference
3939from guardrails .classes .validation_outcome import ValidationOutcome
4040from guardrails .classes .execution import GuardExecutionOptions
4141from guardrails .classes .generic import Stack
@@ -166,7 +166,7 @@ def __init__(
166166 id = id ,
167167 name = name ,
168168 description = description ,
169- validators = validators ,
169+ validators = [] ,
170170 output_schema = model_schema ,
171171 history = history , # type: ignore - pyright doesn't understand pydantic overrides
172172 )
@@ -180,6 +180,9 @@ def __init__(
180180 # self.output_schema: Optional[ModelSchema] = None
181181 # self.history = history
182182
183+ ### Overrides ###
184+ self .validators = validators
185+
183186 ### Legacy ##
184187 self ._num_reasks = None
185188 self ._rail : Optional [str ] = None
@@ -208,7 +211,10 @@ def __init__(
208211 if loaded_guard :
209212 self .id = loaded_guard .id
210213 self .description = loaded_guard .description
211- self .validators = loaded_guard .validators or []
214+ self .validators = [ # type: ignore
215+ ValidatorReference .from_interface (v )
216+ for v in loaded_guard .validators or []
217+ ]
212218
213219 loaded_output_schema = (
214220 ModelSchema .from_dict ( # trims out extra keys
@@ -1264,7 +1270,7 @@ def to_dict(self) -> Dict[str, Any]:
12641270 id = self .id ,
12651271 name = self .name ,
12661272 description = self .description ,
1267- validators = self .validators ,
1273+ validators = self .validators , # type: ignore
12681274 output_schema = self .output_schema ,
12691275 history = [c .to_interface () for c in self .history ], # type: ignore
12701276 )
@@ -1304,7 +1310,10 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional["Guard"]:
13041310 id = i_guard .id ,
13051311 name = i_guard .name ,
13061312 description = i_guard .description ,
1307- validators = i_guard .validators ,
1313+ validators = [
1314+ ValidatorReference .from_interface (i_val )
1315+ for i_val in i_guard .validators or []
1316+ ],
13081317 output_schema = output_schema ,
13091318 )
13101319
0 commit comments