Skip to main content
InstallationTo use Weave’s predefined scorers you need to install some additional dependencies:
LLM-evaluators Update Feb 2025: The pre-defined scorers that leverage LLMs now automatically integrate with litellm. You no longer need to pass an LLM client; just set the model_id. See the supported models here.

HallucinationFreeScorer

This scorer checks if your AI system’s output includes any hallucinations based on the input data.
Customization:
  • Customize the system_prompt and user_prompt fields of the scorer to define what “hallucination” means for you.
Notes:
  • The score method expects an input column named context. If your dataset uses a different name, use the column_map attribute to map context to the dataset column.
Here you have an example in the context of an evaluation:

SummarizationScorer

Use an LLM to compare a summary to the original text and evaluate the quality of the summary.
How It Works:This scorer evaluates summaries in two ways:
  1. Entity Density: Checks the ratio of unique entities (like names, places, or things) mentioned in the summary to the total word count in the summary in order to estimate the “information density” of the summary. Uses an LLM to extract the entities. Similar to how entity density is used in the Chain of Density paper, https://arxiv.org/abs/2309.04269
  2. Quality Grading: An LLM evaluator grades the summary as poor, ok, or excellent. These grades are then mapped to scores (0.0 for poor, 0.5 for ok, and 1.0 for excellent) for aggregate performance evaluation.
Customization:
  • Adjust summarization_evaluation_system_prompt and summarization_evaluation_prompt to tailor the evaluation process.
Notes:
  • The scorer uses litellm internally.
  • The score method expects the original text (the one being summarized) to be present in the input column. Use column_map if your dataset uses a different name.
Here you have an example usage in the context of an evaluation:

OpenAIModerationScorer

The OpenAIModerationScorer uses OpenAI’s Moderation API to check if the AI system’s output contains disallowed content, such as hate speech or explicit material.
How It Works:
  • Sends the AI’s output to the OpenAI Moderation endpoint and returns a structured response indicating if the content is flagged.
Notes: Here is an example in the context of an evaluation:

EmbeddingSimilarityScorer

The EmbeddingSimilarityScorer computes the cosine similarity between the embeddings of the AI system’s output and a target text from your dataset. It is useful for measuring how similar the AI’s output is to a reference text.
Parameters:
  • threshold (float): The minimum cosine similarity score (between -1 and 1) needed to consider the two texts similar (defaults to 0.5).
Example Usage:The following example uses EmbeddingSimilarityScorer in the context of an evaluation:

ValidJSONScorer

The ValidJSONScorer checks whether the AI system’s output is valid JSON. This scorer is useful when you expect the output to be in JSON format and need to verify its validity.
Here is an example in the context of an evaluation:

ValidXMLScorer

The ValidXMLScorer checks whether the AI system’s output is valid XML. It is useful when expecting XML-formatted outputs.
Here is an example in the context of an evaluation:

PydanticScorer

The PydanticScorer validates the AI system’s output against a Pydantic model to ensure it adheres to a specified schema or data structure.

RAGAS - ContextEntityRecallScorer

The ContextEntityRecallScorer estimates context recall by extracting entities from both the AI system’s output and the provided context, then computing the recall score. It is based on the RAGAS evaluation library.
How It Works:
  • Uses an LLM to extract unique entities from the output and context and calculates recall.
  • Recall indicates the proportion of important entities from the context that are captured in the output.
  • Returns a dictionary with the recall score.
Notes:

RAGAS - ContextRelevancyScorer

The ContextRelevancyScorer evaluates the relevancy of the provided context to the AI system’s output. It is based on the RAGAS evaluation library.
How It Works:
  • Uses an LLM to rate the relevancy of the context to the output on a scale from 0 to 1.
  • Returns a dictionary with the relevancy_score.
Notes:
  • Expects a context column in your dataset. Use the column_map attribute if the column name is different.
  • Customize the relevancy_prompt to define how relevancy is assessed.
Here is an example usage in the context of an evaluation:
Note: The built-in scorers were calibrated using OpenAI models (e.g. openai/gpt-4o, openai/text-embedding-3-small). If you wish to experiment with other providers, you can simply update the model_id. For example, to use an Anthropic model:

Use column mapping

You can use the column_map attribute to tell the scorer which dataset columns to use. The column_map attribute requires you to set the following keys:
  • output: Model prediction
  • target: Reference answer to compare with
The following example maps the output and target columns to a dataset’s model_output and answer columns, respectively: