@@ -102,6 +102,7 @@ def validate_output_keys(
102102 output : dict [str , Any ],
103103 expected_keys : list [str ],
104104 allow_empty : bool = False ,
105+ nullable_keys : list [str ] | None = None ,
105106 ) -> ValidationResult :
106107 """
107108 Validate that all expected keys are present and non-empty.
@@ -110,11 +111,13 @@ def validate_output_keys(
110111 output: The output dict to validate
111112 expected_keys: Keys that must be present
112113 allow_empty: If True, allow empty string values
114+ nullable_keys: Keys that are allowed to be None
113115
114116 Returns:
115117 ValidationResult with success status and any errors
116118 """
117119 errors = []
120+ nullable_keys = nullable_keys or []
118121
119122 if not isinstance (output , dict ):
120123 return ValidationResult (
@@ -127,7 +130,8 @@ def validate_output_keys(
127130 elif not allow_empty :
128131 value = output [key ]
129132 if value is None :
130- errors .append (f"Output key '{ key } ' is None" )
133+ if key not in nullable_keys :
134+ errors .append (f"Output key '{ key } ' is None" )
131135 elif isinstance (value , str ) and len (value .strip ()) == 0 :
132136 errors .append (f"Output key '{ key } ' is empty string" )
133137
@@ -273,6 +277,7 @@ def validate_all(
273277 expected_keys : list [str ] | None = None ,
274278 schema : dict [str , Any ] | None = None ,
275279 check_hallucination : bool = True ,
280+ nullable_keys : list [str ] | None = None ,
276281 ) -> ValidationResult :
277282 """
278283 Run all applicable validations on output.
@@ -282,6 +287,7 @@ def validate_all(
282287 expected_keys: Optional list of required keys
283288 schema: Optional JSON schema
284289 check_hallucination: Whether to check for hallucination patterns
290+ nullable_keys: Keys that are allowed to be None
285291
286292 Returns:
287293 Combined ValidationResult
@@ -290,7 +296,7 @@ def validate_all(
290296
291297 # Validate keys if provided
292298 if expected_keys :
293- result = self .validate_output_keys (output , expected_keys )
299+ result = self .validate_output_keys (output , expected_keys , nullable_keys = nullable_keys )
294300 all_errors .extend (result .errors )
295301
296302 # Validate schema if provided
0 commit comments