@@ -116,10 +116,18 @@ def get_function_definition(self):
116116 },
117117 "validCheckItem" : {
118118 "type" : "object" ,
119- "required" : ["attribute" , "count_as_valid" ],
119+ "required" : ["attribute" ],
120120 "properties" : {
121121 "attribute" : {"type" : "string" , "description" : "Attribute name to validate" },
122122 "count_as_valid" : {"anyOf" : [{"type" : "string" }, {"type" : "array" , "items" : {"type" : "string" }}]},
123+ "in_range" : {
124+ "type" : "object" ,
125+ "required" : ["min" , "max" ],
126+ "properties" : {
127+ "min" : {"type" : "number" },
128+ "max" : {"type" : "number" },
129+ }
130+ }
123131 },
124132 "additionalProperties" : False ,
125133 },
@@ -209,23 +217,43 @@ def _run_valid_checks(self, entity: object, checks: list):
209217 results = []
210218 for check in checks :
211219 attr = check ["attribute" ]
212- valid_values = check ["count_as_valid" ]
213- valid_list = valid_values if isinstance (valid_values , list ) else [valid_values ]
214-
215220 value = utils .get_attr_or_ref_attr (entity , attr )
216221
217222 if value == self .NOT_FOUND :
218223 raise ValueError (f"Attribute [{ attr } ] not found." )
224+
225+ # Valid values check
226+ valid_values = check .get ("count_as_valid" )
227+ if valid_values :
228+ valid_list = valid_values if isinstance (valid_values , list ) else [valid_values ]
219229
220- if value == self .UNSET :
221- if self .UNSET not in valid_list :
230+ if value == self .UNSET :
231+ if self .UNSET not in valid_list :
232+ results .append (
233+ f"[{ attr } ] should be { 'one of ' if len (valid_list ) > 1 else '' } [{ ', ' .join (valid_list )} ], but is unset."
234+ )
235+ else :
236+ value_str = getattr (value , "name" , str (value )).lower ()
237+ if value_str not in [v .lower () for v in valid_list ]:
238+ results .append (
239+ f"[{ attr } ] should be { 'one of ' if len (valid_list ) > 1 else '' } [{ ', ' .join (valid_list )} ], but found [{ value_str } ]."
240+ )
241+
242+ # Range check
243+ in_range = check .get ("in_range" )
244+ if in_range :
245+ min = in_range ["min" ]
246+ max = in_range ["max" ]
247+
248+ if value == self .UNSET :
222249 results .append (
223- f"[{ attr } ] should be { 'one of ' if len ( valid_list ) > 1 else '' } [ { ', ' . join ( valid_list ) } ], but is unset."
250+ f"[{ attr } ] should be in range [ { min } , { max } ], but is unset."
224251 )
225- else :
226- value_str = getattr ( value , "name" , str ( value )). lower ()
227- if value_str not in [ v . lower () for v in valid_list ] :
252+ break
253+
254+ if not ( min <= value <= max ) :
228255 results .append (
229- f"[{ attr } ] should be { 'one of ' if len ( valid_list ) > 1 else '' } [ { ', ' . join ( valid_list ) } ], but found [{ value_str } ]."
256+ f"[{ attr } ] should be in range [ { min } , { max } ], but found [{ value } ]."
230257 )
258+
231259 return results
0 commit comments