From 3e094dede7cfdf07e4589e94b2ef78e3fe7fd40c Mon Sep 17 00:00:00 2001 From: Nicholas Chen Date: Tue, 16 Jul 2024 14:59:13 -0400 Subject: [PATCH 1/2] throw error if streaming used with forbidden onfail strategy --- guardrails/validator_service.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/guardrails/validator_service.py b/guardrails/validator_service.py index ba5c0a29d..fdfcbecec 100644 --- a/guardrails/validator_service.py +++ b/guardrails/validator_service.py @@ -239,6 +239,23 @@ def run_validators( # Validate the field validators = validator_map.get(reference_property_path, []) for validator in validators: + if stream: + if validator.on_fail_descriptor is OnFailAction.REASK: + raise ValueError("Reask is not supported for stream validation") + if validator.on_fail_descriptor is OnFailAction.FIX: + raise ValueError( + "Fix on fail is not supported for stream validation" + ) + if validator.on_fail_descriptor is OnFailAction.FIX_REASK: + raise ValueError("Fix Reask is not supported for stream validation") + if validator.on_fail_descriptor is OnFailAction.FILTER: + raise ValueError( + "Filter on fail is not supported for stream validation" + ) + if validator.on_fail_descriptor is OnFailAction.REFRAIN: + raise ValueError( + "Refrain on fail is not supported for stream validation" + ) validator_logs = self.run_validator( iteration, validator, From c7ac77be780072875a8caacfedecb432eae968a0 Mon Sep 17 00:00:00 2001 From: Nicholas Chen Date: Tue, 16 Jul 2024 16:48:28 -0400 Subject: [PATCH 2/2] add info about supported onfail actions --- guardrails/validator_service.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/guardrails/validator_service.py b/guardrails/validator_service.py index fdfcbecec..8b0ebbb66 100644 --- a/guardrails/validator_service.py +++ b/guardrails/validator_service.py @@ -241,20 +241,29 @@ def run_validators( for validator in validators: if stream: if validator.on_fail_descriptor is OnFailAction.REASK: - raise ValueError("Reask is not supported for stream validation") + raise ValueError( + """Reask is not supported for stream validation, + only noop and exception are supported.""" + ) if validator.on_fail_descriptor is OnFailAction.FIX: raise ValueError( - "Fix on fail is not supported for stream validation" + """Fix is not supported for stream validation, + only noop and exception are supported.""" ) if validator.on_fail_descriptor is OnFailAction.FIX_REASK: - raise ValueError("Fix Reask is not supported for stream validation") + raise ValueError( + """Fix reask is not supported for stream validation, + only noop and exception are supported.""" + ) if validator.on_fail_descriptor is OnFailAction.FILTER: raise ValueError( - "Filter on fail is not supported for stream validation" + """Filter is not supported for stream validation, + only noop and exception are supported.""" ) if validator.on_fail_descriptor is OnFailAction.REFRAIN: raise ValueError( - "Refrain on fail is not supported for stream validation" + """Refrain is not supported for stream validation, + only noop and exception are supported.""" ) validator_logs = self.run_validator( iteration,