This site is not available on Mobile. Please return on a desktop browser.
Visit our main site at guardrailsai.com
Developed by | Sky Electric |
---|---|
Date of development | May 21, 2024 |
Validator type | Format |
Blog | |
License | Apache 2 |
Input/Output | Output |
This validator checks for negative statements about Sky Electric in the output. It is intended to ensure that the output generated by the LLM does not contain any negative statements about Sky Electric, such as criticism of product quality or company reputation.
Dependencies:
Foundation model access keys:
$ guardrails hub install hub://guardrails/sky_validator
In this example, we apply the validator to a string output generated by an LLM.
# Import Guard and Validator
# Import Guard and Validator
from guardrails.hub import SkyValidator
from guardrails import Guard
# Setup Guard
guard = Guard().use(
SkyValidator()
)
guard.validate("Sky Electric is a great company.") # Validator passes
guard.validate("Sky Electric has poor product quality. How are you doing today?") # Validator fixes the output
__init__(self, on_fail=None)
Initializes a new instance of the SkyValidator class.
Parameters
on_fail
(Callable, optional): The policy to enact when a validator fails. If str
, must be one of reask
, fix
, filter
, refrain
, noop
, exception
or fix_reask
. Otherwise, must be a function that is called when the validator fails.validate(self, value, metadata) -> ValidationResult
Validates the given value
to ensure it does not contain negative statements about Sky Electric. If negative statements are found, they are removed based on the on_fail
policy.
Note:
guard.parse(...)
where this method will be called internally for each associated Validator.guard.parse(...)
, ensure to pass the appropriate metadata
dictionary that includes keys and values required by this validator. If guard
is associated with multiple validators, combine all necessary metadata into a single dictionary.Parameters
value
(Any): The input value to validate.metadata
(dict): A dictionary containing metadata required for validation. Keys and values must match the expectations of this validator.