Harrison
Relevancy Evaluator
Validates that the reference text contains information relevant to answering the original question.
en
string
ML
Brand risk
Chatbots
Customer Support

Overview

updated 2 years
Developed by:
harrison@arize.com
Date of development:
Jul 12, 2024
Validator type:
Format
License:
Apache 2
Input/Output:
Output

Playground

Description
Intended Use

This validator checks the relevancy of a reference text to an original question by prompting a LiteLLM (LLM) model to evaluate the output.

Requirements
  • Dependencies:

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

    • OPENAI_API_KEY
Installation
$ guardrails hub install hub://arize-ai/relevancy_evaluator
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
from guardrails.hub import RelevancyEvaluator
from guardrails import Guard

# Setup Guard
guard = Guard().use(
    RelevancyEvaluator(llm_callable="gpt-3.5-turbo")
)

# Example values
value = {
    "original_prompt": "What is the capital of France?",
    "reference_text": "The capital of France is Paris."
}

guard.validate(value)  # Validator passes if the text is relevant
API Reference

__init__(self, llm_callable="gpt-3.5-turbo", on_fail=None)

Initializes a new instance of the RelevancyEvaluator class.

Parameters

  • llm_callable (str): The name of the LiteLLM model to use for validation. Defaults to "gpt-3.5-turbo".
  • on_fail (Callable, optional): A function to be called when validation fails. Defaults to None.

validate(self, value, metadata) -> ValidationResult

Validates the given value using the rules defined in this validator, relying on the metadata provided to customize the validation process.

Note:

  • This method should not be called directly by the user. Instead, invoke guard.validate(...) where this method will be called internally for each associated Validator.
  • When invoking guard.validate(...), ensure to pass the appropriate metadata dictionary that includes keys and values required by this validator.

Parameters

  • value (Any): The input value to validate. It must contain 'original_prompt' and 'reference_text' keys.

  • metadata (dict): A dictionary containing metadata required for validation. Keys and values must match the expectations of this validator.

    KeyTypeDescriptionDefault
    original_promptStringThe original question or prompt.N/A
    reference_textStringThe reference text to evaluate for relevancy.N/A