diff --git a/guardrails/guard.py b/guardrails/guard.py index 21b82721c..70e3a9d61 100644 --- a/guardrails/guard.py +++ b/guardrails/guard.py @@ -1013,6 +1013,21 @@ def use( validator: The validator to use. Either the class or an instance. on: The part of the LLM request to validate. Defaults to "output". """ + # check if args has any validators hiding in it + # throw error to user so they can update + if args: + for arg in args: + if ( + isinstance(arg, type) + and issubclass(arg, Validator) + or isinstance(arg, Validator) + ): + raise ValueError( + "Validator is an argument besides the first." + "Please pass it as the first or use the 'use_many' method for" + " multiple validators." + ) + hydrated_validator = get_validator(validator, *args, **kwargs) self.__add_validator(hydrated_validator, on=on) self._save() diff --git a/tests/integration_tests/test_validator_base.py b/tests/integration_tests/test_validator_base.py index 5240e8a20..3a8f5bda5 100644 --- a/tests/integration_tests/test_validator_base.py +++ b/tests/integration_tests/test_validator_base.py @@ -37,6 +37,12 @@ def test_default_noop(): assert not res.validation_passed +def test_multiple_validators(): + # throws value error for multiple validators + with pytest.raises(ValueError): + Guard().use(FailureValidator, FailureValidator) + + def test_filter(): guard = Guard().use(FailureValidator, on_fail="filter") res = guard.parse("hi")