Skip to content

Commit 4bbb458

Browse files
committed
fix: guardrails tests return empty now if no detections
1 parent b5a1bba commit 4bbb458

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

  • tests/model_explainability/guardrails

tests/model_explainability/guardrails/utils.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,24 +146,25 @@ def verify_builtin_detector_unsuitable_output_response(
146146

147147
unsuitable_output_warning = "UNSUITABLE_OUTPUT"
148148
warnings = response_data.get("warnings", [])
149-
if len(warnings) != 1:
150-
errors.append(f"Expected 1 warning in response, got {len(warnings)}")
151-
elif warnings[0]["type"] != unsuitable_output_warning:
152-
errors.append(f"Expected warning type {unsuitable_output_warning}, got {warnings[0]['type']}")
153-
154-
output_detections = response_data.get("detections", {}).get("output", [])
155-
156-
if len(output_detections) < 1:
157-
errors.append(f"Expected at least one output detection, but got {len(output_detections)}.")
158-
else:
159-
errors.extend(
160-
verify_detection(
161-
detections_list=output_detections,
162-
detector_id=detector_id,
163-
detection_name=detection_name,
164-
detection_type=detection_type,
149+
if warnings is not None:
150+
if len(warnings) != 1:
151+
errors.append(f"Expected 1 warning in response, got {len(warnings)}")
152+
elif warnings[0]["type"] != unsuitable_output_warning:
153+
errors.append(f"Expected warning type {unsuitable_output_warning}, got {warnings[0]['type']}")
154+
output_detections = response_data.get("detections", {})
155+
if output_detections is not None:
156+
output_detections = output_detections.get("output", [])
157+
if len(output_detections) < 1:
158+
errors.append(f"Expected at least one output detection, but got {len(output_detections)}.")
159+
else:
160+
errors.extend(
161+
verify_detection(
162+
detections_list=output_detections,
163+
detector_id=detector_id,
164+
detection_name=detection_name,
165+
detection_type=detection_type,
166+
)
165167
)
166-
)
167168

168169
assert_no_errors(errors=errors, failure_message_prefix="Unsuitable output detection verification failed")
169170

0 commit comments

Comments
 (0)