| 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:
- guardrails-ai>=0.4.0
-
Foundation model access keys:
- Include any access environment variables you need here like OPENAI_API_KEY
$ guardrails hub install hub://guardrails/sky_validatorIn 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. Ifstr, must be one ofreask,fix,filter,refrain,noop,exceptionorfix_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:
- This method should not be called directly by the user. Instead, invoke
guard.parse(...)where this method will be called internally for each associated Validator. - When invoking
guard.parse(...), ensure to pass the appropriatemetadatadictionary that includes keys and values required by this validator. Ifguardis 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.