/sky_validator

Primary LanguagePythonApache License 2.0Apache-2.0

Overview

Developed by Sky Electric
Date of development May 21, 2024
Validator type Format
Blog
License Apache 2
Input/Output Output

Description

Intended Use

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.

Requirements

  • Dependencies:

    • guardrails-ai>=0.4.0
  • Foundation model access keys:

    • Include any access environment variables you need here like OPENAI_API_KEY

Installation

$ guardrails hub install hub://guardrails/sky_validator

Usage Examples

Validating string output via Python

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

API Reference

__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:

  1. 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.
  2. When invoking 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.