Metrics
Metrics module for evaluating AI model outputs.
This module provides a comprehensive collection of evaluation metrics for assessing the quality of generated content, retrieval systems, and AI agent tool use. It includes both traditional metrics and LLM-based metrics, as well as integrations with popular evaluation frameworks.
Metric categories: - Generation metrics: Evaluate quality of generated text (completeness, groundedness, redundancy, language consistency, refusal alignment) - Retrieval metrics: Assess retrieval system performance (precision, recall, accuracy) - Tool use metrics: Evaluate AI agent tool calling and trajectory accuracy - Open-source integrations: Wrappers for DeepEval evaluators
BaseMetric
Bases: ABC
Abstract class for metrics.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the metric. |
required_fields |
set[str]
|
The required fields for this metric to evaluate data. |
input_type |
type | None
|
The type of the input data. |
higher_is_better |
bool
|
Whether a higher score indicates better quality. Defaults to True. |
strict_mode |
bool
|
If True, binarizes score to 1.0 or 0.0 before thresholding. Defaults to False. |
threshold |
float
|
Pass/fail threshold in [0, 1]. Defaults to 0.5. |
models |
list[BaseLMInvoker]
|
Judge models for single-judge/multi-judge evaluation.
|
aggregation_method |
AggregationSelector
|
Strategy for aggregating judge scores (majority_vote, median, average). Defaults to majority_vote. |
num_judges |
int
|
Read-only. Returns |
max_concurrent_judges |
int | None
|
Cap on concurrent judge tasks. |
Every MetricResult carries per-model token_usage drained from the adapter
wrapper that served the judge call.
Single-judge::
metric = GEvalCompletenessMetric(models=my_invoker)
Homogeneous multi-judge (same model, 3 repetitions)::
metric = GEvalCompletenessMetric(models=[my_invoker] * 3)
metric.aggregation_method = AggregationMethod.MEDIAN
Heterogeneous multi-judge (different models)::
metric = GEvalCompletenessMetric(models=[invoker_a, invoker_b, invoker_c])
metric.aggregation_method = AggregationMethod.MAJORITY_VOTE
aggregation_method
property
writable
Return the configured aggregation method.
Returns:
| Name | Type | Description |
|---|---|---|
AggregationSelector |
AggregationSelector
|
The aggregation method configured for this metric. |
fallback_models
property
writable
Return the ordered fallback judge invokers tried when the primary judge fails.
models
property
writable
Return configured judge model invokers.
- Empty list (default): single-judge mode.
- One invoker: runs that invoker once.
[invoker] * N: homogeneous — same model N times.[invoker_a, invoker_b, ...]: heterogeneous — distinct models.
num_judges
property
Return the number of judge models.
Read-only convenience: len(models) when models is non-empty, else 1.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of judges configured for this metric. |
result_names
property
The names under which an evaluator publishes this metric's scores, skips and failures.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The metric's own name. A metric that scores several sub-metrics lists one name for each. |
__deepcopy__(memo)
Copy this metric without copying the judge client it talks through.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
memo
|
dict
|
The deepcopy memo dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
BaseMetric |
BaseMetric
|
The copy, sharing this metric's judge and its locks. |
can_evaluate(data)
Check if this metric can evaluate the given data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
LLMTestCase
|
The input data to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the metric can evaluate the data, False otherwise. |
describe_missing_fields(data)
Name the fields whose absence made can_evaluate return False.
A hook so an evaluator can report why it skipped a metric without assuming the
requirement is expressed as flat required_fields. The default is exactly the
inverse of can_evaluate above; families whose requirements depend on the row
type override both together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
LLMTestCase
|
The row that was declined. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: Sorted names of the missing fields. |
drain_token_usage()
Drain this metric's accumulated usage on behalf of a caller outside the metric.
Evaluators need this when a metric raises: the tokens are already billed, but the failure result is built by the evaluator rather than by the metric itself.
Returns:
| Type | Description |
|---|---|
dict[str, TokenUsage] | None
|
dict[str, TokenUsage] | None: Usage per model_id, or None when nothing was recorded. |
evaluate(data)
async
Evaluate one row, or each row of a list with the same validation and failure policy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
LLMTestCase | list[LLMTestCase]
|
The data to evaluate the metric on. Can be a single item or a list. |
required |
Returns:
| Type | Description |
|---|---|
MetricResult | list[MetricResult]
|
MetricResult | list[MetricResult]: The evaluation result(s). Returns a list, one result per row, if
input is a list. A score that a fallback judge gave lists the replaced judges in |
Raises:
| Type | Description |
|---|---|
EvalInputError
|
If a test case has the wrong type or lacks required fields. |
EvalResultContractError
|
If the metric returns a result of the wrong shape. |
get_input_fields()
classmethod
Return declared input field names if input_type is provided; otherwise None.
Returns:
| Type | Description |
|---|---|
list[str] | None
|
list[str] | None: The input fields. |
get_input_spec()
classmethod
Return structured spec for input fields if input_type is provided; otherwise None.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | None
|
list[dict[str, Any]] | None: The input spec. |
is_success(score)
Determine if the score indicates success based on threshold and polarity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
score
|
float
|
The score to evaluate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the score meets the success criteria, False otherwise. |
DeepEvalAnswerRelevancyMetric(models=None, fallback_models=None, threshold=0.5, aggregation_method=AggregationMethod.AVERAGE, max_concurrent_judges=None)
Bases: DeepEvalMetricFactory
DeepEval Answer Relevancy Metric Integration.
This metric uses LLM-as-a-judge to assess whether the output is relevant to the given input. A decision-model
judge (BaseDMInvoker, such as TypeSafe Jev) scores it through DeepEval's native system_one path instead:
DeepEval asks the questions and computes the score, and no LLM call is made. A chain that mixes both kinds of
judge tries each judge in order, each as one complete measurement, so one run can hold rows scored by either kind.
Available Fields
- input (str): The query to evaluate the metric.
- actual_output (str): The generated response to evaluate the metric.
Scoring
- 0.0-1.0 (Continuous): A higher score indicates better answer relevancy.
Cookbook Example
Please refer to example_deepeval_answer_relevancy.py in the gen-ai-sdk-cookbook repository.
Initializes the DeepEvalAnswerRelevancyMetric class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
The threshold to use for the metric. Defaults to 0.5. |
0.5
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
The judge invoker(s) to use for multi-judge evaluation. Each is an LM invoker or a decision-model invoker. Defaults to None, which uses the default LM judge. |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered list of fallback invokers, LM or decision model, tried in sequence when the primary judge fails. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
The aggregation method to use for the metric. Defaults to AggregationMethod.AVERAGE. |
AVERAGE
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
DeepEvalContextualPrecisionMetric(threshold=DefaultValues.CONTEXTUAL_PRECISION_THRESHOLD, evaluation_template=ContextualPrecisionTemplate, models=None, fallback_models=None, aggregation_method=AggregationMethod.AVERAGE, max_concurrent_judges=None)
Bases: DeepEvalMetricFactory
DeepEval Contextual Precision Metric.
Evaluates whether the retrieval context that is relevant to the given query are ranked higher than irrelevant ones.
A higher score indicates better contextual precision, meaning relevant context chunks appear earlier in the retrieved results.
A decision-model judge (BaseDMInvoker, such as TypeSafe Jev) scores it through DeepEval's native
system_one path: DeepEval asks the questions and computes the score, and no LLM call is made. A chain that
mixes both kinds of judge tries each judge in order, each as one complete measurement, so one run can hold rows
scored by either kind.
Available Fields
- input (str): The query to evaluate the metric.
- expected_output (str): The expected response to evaluate the metric.
- retrieved_context (str | list[str]): The list of retrieved contexts to evaluate the metric. If a str, it will be converted into a list with a single element.
Scoring
- 0.0-1.0 (Continuous): A higher score indicates better contextual precision.
Cookbook Example
Please refer to example_deepeval_contextual_precision.py in the gen-ai-sdk-cookbook repository.
Initializes the DeepEvalContextualPrecisionMetric class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
Pass/fail cutoff. Set to 0.4 to accommodate the ranking-based nature of precision scores which are typically lower than recall scores. Defaults to 0.4. |
CONTEXTUAL_PRECISION_THRESHOLD
|
evaluation_template
|
Type[ContextualPrecisionTemplate]
|
The evaluation template to use for the
metric. Defaults to ContextualPrecisionTemplate. It is used to generate the reason for the metric.
With a decision-model judge the LM prompts and reason template are not used; DeepEval's default
native questions apply. Customizing native questions relies on DeepEval's experimental
|
ContextualPrecisionTemplate
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
The judge invoker(s) to use for multi-judge evaluation. Each is an LM invoker or a decision-model invoker. Defaults to None, which uses the default LM judge. |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered list of fallback invokers, LM or decision model, tried in sequence when the primary judge fails. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
The aggregation method to use for the metric. Defaults to AggregationMethod.AVERAGE. |
AVERAGE
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
DeepEvalContextualRecallMetric(threshold=DefaultValues.CONTEXTUAL_RECALL_THRESHOLD, evaluation_template=ContextualRecallTemplate, models=None, fallback_models=None, aggregation_method=AggregationMethod.AVERAGE, max_concurrent_judges=None)
Bases: DeepEvalMetricFactory
DeepEval Contextual Recall Metric.
Evaluates the extent to which the retrieved context aligns with the expected output.
A higher score indicates better contextual recall, meaning the retrieval system successfully found the information needed to generate the expected response.
A decision-model judge (BaseDMInvoker, such as TypeSafe Jev) scores it through DeepEval's native
system_one path: DeepEval asks the questions and computes the score, and no LLM call is made. A chain that
mixes both kinds of judge tries each judge in order, each as one complete measurement, so one run can hold rows
scored by either kind.
Available Fields
- input (str): The query to evaluate the metric.
- expected_output (str): The expected response to evaluate the metric.
- retrieved_context (str | list[str]): The list of retrieved contexts to evaluate the metric. If a str, it will be converted into a list with a single element.
Scoring
- 0.0-1.0 (Continuous): A higher score indicates better contextual recall.
Cookbook Example
Please refer to example_deepeval_contextual_recall.py in the gen-ai-sdk-cookbook repository.
Initializes the DeepEvalContextualRecallMetric class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
Pass/fail cutoff. Set to 0.6 as recall scores are typically higher than precision scores due to their coverage-based nature. Defaults to 0.6. |
CONTEXTUAL_RECALL_THRESHOLD
|
evaluation_template
|
Type[ContextualRecallTemplate]
|
The evaluation template to use for the
metric. Defaults to ContextualRecallTemplate.
With a decision-model judge the LM prompts and reason template are not used; DeepEval's default
native questions apply. Customizing native questions relies on DeepEval's experimental
|
ContextualRecallTemplate
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
The judge invoker(s) to use for multi-judge evaluation. Each is an LM invoker or a decision-model invoker. Defaults to None, which uses the default LM judge. |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered list of fallback invokers, LM or decision model, tried in sequence when the primary judge fails. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
The aggregation method to use for the metric. Defaults to AggregationMethod.AVERAGE. |
AVERAGE
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
DeepEvalContextualRelevancyMetric(models=None, fallback_models=None, threshold=0.5, aggregation_method=AggregationMethod.AVERAGE, max_concurrent_judges=None)
Bases: DeepEvalMetricFactory
DeepEval Contextual Relevancy Metric.
Evaluates the overall relevance of the information presented in the retrieved context for a given query.
A higher score indicates better contextual relevancy, meaning the retrieved context chunks contain less irrelevant or tangential information.
A decision-model judge (BaseDMInvoker, such as TypeSafe Jev) scores it through DeepEval's native
system_one path: DeepEval asks the questions and computes the score, and no LLM call is made. A chain that
mixes both kinds of judge tries each judge in order, each as one complete measurement, so one run can hold rows
scored by either kind.
Available Fields
- input (str): The query to evaluate the metric.
- actual_output (str): The generated response to evaluate the metric.
- retrieved_context (str | list[str]): The list of retrieved contexts to evaluate the metric. If a str, it will be converted into a list with a single element.
Scoring
- 0.0-1.0 (Continuous): A higher score indicates better contextual relevancy.
Cookbook Example
Please refer to example_deepeval_contextual_relevancy.py in the gen-ai-sdk-cookbook repository.
Initializes the DeepEvalContextualRelevancyMetric class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
The threshold to use for the metric. Defaults to 0.5. |
0.5
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
The judge invoker(s) to use for multi-judge evaluation. Each is an LM invoker or a decision-model invoker. Defaults to None, which uses the default LM judge. |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered list of fallback invokers, LM or decision model, tried in sequence when the primary judge fails. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
The aggregation method to use for the metric. Defaults to AggregationMethod.AVERAGE. |
AVERAGE
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
DeepEvalConversationCompletenessMetric(name='deepeval_conversation_completeness', threshold=0.5, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, skip_multimodal_check=False, max_concurrent_judges=None)
Bases: ConvDeepEvalMetricFactory
Whether the assistant fully addressed the user's intentions across the conversation.
Conversation-level: scores the whole transcript in one judge call.
A decision-model judge scores the whole conversation in DeepEval's native system_one mode.
Initialize the metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric name used in scoring output. Defaults to "deepeval_conversation_completeness". |
'deepeval_conversation_completeness'
|
threshold
|
float
|
Pass/fail threshold in [0, 1]. Defaults to 0.5. |
0.5
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
Judge model(s). None uses the SDK default; a list runs multi-judge. A decision model judges in
DeepEval's native |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered fallback invokers. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
Strategy used when
|
AGGREGATION_METHOD
|
skip_multimodal_check
|
bool
|
When True, the caller asserts the judge supports image input. Defaults to False. |
False
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
DeepEvalConversationalGEvalMetric(name, criteria=None, evaluation_steps=None, additional_info=None, fewshot=None, evaluation_params=None, rubric=None, threshold=0.5, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, skip_multimodal_check=False, max_concurrent_judges=None)
Bases: ConvDeepEvalMetricFactory
User-configurable holistic conversation quality metric.
Evaluates the full conversation against caller-provided criteria. LM judges use
DeepEval's ConversationalGEval, and decision models answer one Choice question.
Per-row temp_fewshot_{name}, temp_info_{name} and evaluation_step_{name}
columns behave as on DeepEvalGEvalMetric, with any geval_ prefix dropped from name, and so do
the runtime evaluate(temp_fewshot=..., temp_info=..., fewshot_mode=...) arguments.
Initialize the conversational GEval metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric name used in scoring output. |
required |
criteria
|
str | None
|
Plain-text evaluation criteria. One of
|
None
|
evaluation_steps
|
list[str] | None
|
Step-by-step rubric. Defaults to None. |
None
|
additional_info
|
str | None
|
Domain knowledge and scoring rules for
the judge, ordered before |
None
|
fewshot
|
str | None
|
Few-shot examples for the judge, ordered last. Defaults to None. |
None
|
evaluation_params
|
list[str] | None
|
Which fields the judge sees, by SDK field name: content, role, expected_output, scenario, retrieved_context, tools_called. None derives the list per row from the fields the converted case actually has. Pass a non-empty list to pin it. Defaults to None. |
None
|
rubric
|
list[Rubric] | None
|
Score-band guidance passed straight to
|
None
|
threshold
|
float
|
Pass/fail threshold in [0, 1]. Defaults to 0.5. |
0.5
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
Primary judge or panel of judges. Defaults to None. |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered fallback judges. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
Strategy used when |
AGGREGATION_METHOD
|
skip_multimodal_check
|
bool
|
When True, asserts LM judges support image input so multimodal capability resolution skips the probe for unlisted LMs. Decision-model judges are still checked against the blessed list or probed. Defaults to False. |
False
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
EvalConfigurationError
|
If neither |
evaluate(data, temp_fewshot=None, temp_info=None, fewshot_mode='append')
async
Evaluate, optionally with runtime fewshot and info that take priority over per-row columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ConversationalTestCase | list[ConversationalTestCase]
|
The row or rows to evaluate. |
required |
temp_fewshot
|
str | None
|
Runtime fewshot examples. Defaults to None. |
None
|
temp_info
|
str | None
|
Runtime additional info. Defaults to None. |
None
|
fewshot_mode
|
Literal['append', 'replace']
|
How to merge fewshot. Defaults to "append". |
'append'
|
Returns:
| Type | Description |
|---|---|
MetricResult | list[MetricResult]
|
MetricResult | list[MetricResult]: Evaluation results. |
get_custom_prompt_base_name()
Get the name used in per-row column names.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The metric name without a |
DeepEvalFaithfulnessMetric(models=None, fallback_models=None, threshold=0.5, aggregation_method=AggregationMethod.AVERAGE, max_concurrent_judges=None)
Bases: DeepEvalMetricFactory
DeepEval Faithfulness Metric Integration.
This metric uses LLM-as-a-judge to assess whether the answers rely solely on the retrieved context, without
hallucinating or providing misinformation. A decision-model judge (BaseDMInvoker, such as TypeSafe Jev) scores
it through DeepEval's native system_one path instead: DeepEval asks the questions and computes the score, and
no LLM call is made. A chain that mixes both kinds of judge tries each judge in order, each as one complete
measurement, so one run can hold rows scored by either kind.
Available Fields
- input (str): The query to evaluate the metric.
- actual_output (str): The generated response to evaluate the metric.
- retrieved_context (str | list[str]): The list of retrieved contexts to evaluate the metric. If a str, it will be converted into a list with a single element.
Scoring
- 0.0-1.0 (Continuous): A higher score indicates better faithfulness.
Cookbook Example
Please refer to example_deepeval_faithfulness.py in the gen-ai-sdk-cookbook repository.
Initializes the DeepEvalFaithfulnessMetric class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
The threshold to use for the metric. Defaults to 0.5. |
0.5
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
The judge invoker(s) to use for multi-judge evaluation. Each is an LM invoker or a decision-model invoker. Defaults to None, which uses the default LM judge. |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered list of fallback invokers, LM or decision model, tried in sequence when the primary judge fails. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
The aggregation method to use for the metric. Defaults to AggregationMethod.AVERAGE. |
AVERAGE
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
DeepEvalGEvalMetric(name=None, evaluation_params=None, criteria=None, evaluation_steps=None, rubric=None, threshold=0.5, additional_info=None, fewshot=None, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, max_concurrent_judges=None, strict_mode=False, multimodal=None, multimodal_rules=None, skip_multimodal_check=False)
Bases: DeepEvalMetricFactory, PromptExtractionMixin
DeepEval GEval Metric Integration.
This class is a wrapper for the DeepEvalGEval class. It is used to wrap the GEval class and provide a unified interface for the DeepEval library.
GEval is a versatile evaluation metric framework that can be used to create custom evaluation metrics.
Available Fields
- input (str, optional): The query to evaluate the metric.
- actual_output (str, optional): The generated response to evaluate the metric.
- expected_output (str, optional): The expected response to evaluate the metric.
- expected_context (str | list[str], optional): The expected retrieved context to evaluate the metric. If a str, it will be converted to a list with a single element.
- retrieved_context (str | list[str], optional): The list of retrieved contexts to evaluate the metric. If a str, it will be converted into a list with a single element.
Scoring
- 0.0-1.0 (Continuous): Or Boolean depending on the DeepEval GEval configuration.
Initializes the DeepEvalGEvalMetric class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
The name of the metric. Defaults to None. Required if not provided via _defaults. |
None
|
evaluation_params
|
list[SingleTurnParams] | None
|
The evaluation parameters. Defaults to None. Required if not provided via _defaults. |
None
|
criteria
|
str | None
|
The criteria to use for the metric. Defaults to None. |
None
|
evaluation_steps
|
list[str] | None
|
The evaluation steps to use for the metric. Defaults to None. |
None
|
rubric
|
list[Rubric] | None
|
The rubric to use for the metric. Defaults to None. |
None
|
threshold
|
float
|
The threshold to use for the metric. Defaults to 0.5. Must be between 0.0 and 1.0 inclusive. |
0.5
|
additional_info
|
str | None
|
Domain knowledge and scoring rules. Defaults to None. |
None
|
fewshot
|
str | None
|
Few-shot examples for this metric. Defaults to None. |
None
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
The judge invoker(s) to use for
multi-judge evaluation. Each is a
|
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered list of fallback invokers (LM or decisions model) tried in sequence when the primary judge fails. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
The aggregation method to use for the metric. Defaults to DefaultValues.AGGREGATION_METHOD. |
AGGREGATION_METHOD
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
strict_mode
|
bool
|
If True, binarizes score to 1.0 or 0.0. Defaults to False. |
False
|
multimodal
|
bool | None
|
Controls multimodal judge rule injection. |
None
|
multimodal_rules
|
str | None
|
Custom multimodal rules used when rule injection is enabled. Defaults to the SDK-wide multimodal judge rules. |
None
|
skip_multimodal_check
|
bool
|
When True, asserts the LM judges support image input so multimodal capability resolution skips the probe for LMs not in the blessed list. Decisions-model judges are always probed. Defaults to False. |
False
|
evaluate(data, temp_fewshot=None, temp_info=None, fewshot_mode='append')
async
Evaluate with custom prompt lifecycle support and heterogeneous judges.
Handles two concerns: 1. Runtime prompt parameters (temp_fewshot, temp_info) 2. Heterogeneous judges (judge parameter with different models)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
LLMTestCase | list[LLMTestCase]
|
Single data item or list of data items to evaluate. |
required |
temp_fewshot
|
str | None
|
Runtime fewshot examples. Defaults to None. |
None
|
temp_info
|
str | None
|
Additional context information. Defaults to None. |
None
|
fewshot_mode
|
Literal['append', 'replace']
|
How to merge fewshot. Defaults to "append". |
'append'
|
Returns:
| Type | Description |
|---|---|
MetricResult | list[MetricResult]
|
MetricResult | list[MetricResult]: Evaluation results. |
Raises:
| Type | Description |
|---|---|
EvalInputError
|
If a test case has the wrong type or lacks required fields. |
EvalResultContractError
|
If a single-item evaluation returns a list. |
get_custom_prompt_base_name()
Get the base name for custom prompt column lookup.
For GEval metrics, removes the 'geval_' prefix to align with CSV column conventions. This fixes Issue #3 by providing polymorphic naming for GEval metrics.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The base name without 'geval_' prefix (e.g., "completeness" instead of "geval_completeness"). |
Example
metric.name = "geval_completeness" metric.get_custom_prompt_base_name() -> "completeness"
CSV columns expected: - temp_fewshot_completeness - temp_fewshot_completeness_mode - evaluation_step_completeness
get_full_prompt(data)
Get the full prompt that DeepEval generates for this metric.
For a decisions-model primary, this is the JSON request instead. The preview is the configured primary's
request, also for a media row where execution would skip that judge. It is partial: the invoker's own
hyperparameters and trace attributes are added only at invoke time, and for a media row the preview keeps
the image placeholders instead of the attachments and omits the multimodal rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
LLMTestCase
|
The metric input. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The complete prompt (system + user) as a string, or the decisions-model request JSON. |
DeepEvalGoalAccuracyMetric(name='deepeval_goal_accuracy', threshold=0.5, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, skip_multimodal_check=False, max_concurrent_judges=None)
Bases: ConvDeepEvalMetricFactory
Whether the assistant helped the user achieve their goal across the conversation.
Conversation-level: scores the whole transcript in one judge call.
A decision-model judge scores the whole conversation in DeepEval's native system_one mode.
Initialize the metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric name used in scoring output. Defaults to "deepeval_goal_accuracy". |
'deepeval_goal_accuracy'
|
threshold
|
float
|
Pass/fail threshold in [0, 1]. Defaults to 0.5. |
0.5
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
Judge model(s). None uses the SDK default; a list runs multi-judge. A decision model judges in
DeepEval's native |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered fallback invokers. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
Strategy used when
|
AGGREGATION_METHOD
|
skip_multimodal_check
|
bool
|
When True, the caller asserts the judge supports image input. Defaults to False. |
False
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
DeepEvalHallucinationMetric(models=None, fallback_models=None, threshold=0.5, aggregation_method=AggregationMethod.AVERAGE, max_concurrent_judges=None)
Bases: DeepEvalMetricFactory
DeepEval Hallucination Metric Integration.
This metric uses LLM-as-a-judge to determine whether the output contains hallucinated or
incorrect information based on the retrieved context. A decision-model judge (BaseDMInvoker, such as
TypeSafe Jev) scores it through DeepEval's native system_one path instead: DeepEval asks the questions and
computes the score, and no LLM call is made. A chain that mixes both kinds of judge tries each judge in order, each
as one complete measurement, so one run can hold rows scored by either kind. A row a decision model scored explains
the SDK's lower-is-better score first, then DeepEval's own higher-is-better reason.
Available Fields
- input (str): The query to evaluate the metric.
- actual_output (str): The generated response to evaluate the metric.
- expected_context (str | list[str]): The expected context to evaluate the metric.
Scoring
- 0.0-1.0 (Continuous): Scale where closer to 1.0 means more hallucinated, closer to 0.0 means less hallucinated. deepeval>=4.2.0 reports a higher-is-better consistency score; this metric reports one minus it, so thresholds keep their meaning.
- LM judges: the score is the share of expected contexts the output contradicts.
- Decision-model judges: the score is one minus DeepEval's weighted consistency score for the row, so it can be fractional even with a single context.
Cookbook Example
Please refer to example_deepeval_hallucination.py in the gen-ai-sdk-cookbook repository.
Initializes the DeepEvalHallucinationMetric class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
The threshold to use for the metric. Defaults to 0.5. |
0.5
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
The judge invoker(s) to use for multi-judge evaluation. Each is an LM invoker or a decision-model invoker. Defaults to None, which uses the default LM judge. |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered list of fallback invokers, LM or decision model, tried in sequence when the primary judge fails. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
The aggregation method to use for the metric. Defaults to AggregationMethod.AVERAGE. |
AVERAGE
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
DeepEvalImageCoherenceMetric(models=None, fallback_models=None, threshold=0.5, aggregation_method=AggregationMethod.AVERAGE, max_concurrent_judges=None, skip_multimodal_check=False)
Bases: BaseDeepEvalImageMetric
DeepEval Image Coherence Metric.
Native DeepEval multimodal metric that judges how coherently each image in a
multimodal actual_output fits the surrounding text. Place the images in
actual_output with [ATTACHMENT:...] placeholders.
Available Fields
- actual_output (str): Generated multimodal output interleaving text and image placeholders.
Scoring
- 0.0-1.0 (Continuous): Higher means images are more coherent with the surrounding text.
Initialize the DeepEvalImageCoherenceMetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models
|
BaseLMInvoker | list[BaseLMInvoker] | None
|
Judge model invoker(s). Defaults to None. |
None
|
fallback_models
|
list[BaseLMInvoker] | None
|
Ordered fallback invokers. Defaults to None. |
None
|
threshold
|
float
|
Success threshold. Defaults to 0.5. |
0.5
|
aggregation_method
|
AggregationSelector
|
Multi-judge aggregation. Defaults to AVERAGE. |
AVERAGE
|
max_concurrent_judges
|
int | None
|
Concurrency limit. Defaults to None. |
None
|
skip_multimodal_check
|
bool
|
By default, the SDK checks whether the judge model supports image input. Set to True only when the judge model supports image input but is not in the SDK's built-in supported-model list. Defaults to False. |
False
|
DeepEvalImageEditingMetric(models=None, fallback_models=None, threshold=0.5, aggregation_method=AggregationMethod.AVERAGE, max_concurrent_judges=None, skip_multimodal_check=False)
Bases: BaseDeepEvalImageMetric
DeepEval Image Editing Metric.
Native DeepEval multimodal metric that judges an edited image against an
original image plus an edit instruction. Put the original image and the edit
instruction in input and the edited image in actual_output, each with
[ATTACHMENT:...] placeholders.
Available Fields
- input (str): The original image placeholder plus the edit instruction text.
- actual_output (str): The edited image placeholder.
Scoring
- 0.0-1.0 (Continuous): Higher means the edit better matches the instruction.
Initialize the DeepEvalImageEditingMetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models
|
BaseLMInvoker | list[BaseLMInvoker] | None
|
Judge model invoker(s). Defaults to None. |
None
|
fallback_models
|
list[BaseLMInvoker] | None
|
Ordered fallback invokers. Defaults to None. |
None
|
threshold
|
float
|
Success threshold. Defaults to 0.5. |
0.5
|
aggregation_method
|
AggregationSelector
|
Multi-judge aggregation. Defaults to AVERAGE. |
AVERAGE
|
max_concurrent_judges
|
int | None
|
Concurrency limit. Defaults to None. |
None
|
skip_multimodal_check
|
bool
|
By default, the SDK checks whether the judge model supports image input. Set to True only when the judge model supports image input but is not in the SDK's built-in supported-model list. Defaults to False. |
False
|
DeepEvalImageHelpfulnessMetric(models=None, fallback_models=None, threshold=0.5, aggregation_method=AggregationMethod.AVERAGE, max_concurrent_judges=None, skip_multimodal_check=False)
Bases: BaseDeepEvalImageMetric
DeepEval Image Helpfulness Metric.
Native DeepEval multimodal metric that judges how helpful each image in a
multimodal actual_output is to the surrounding text. Place the images in
actual_output with [ATTACHMENT:...] placeholders.
Available Fields
- actual_output (str): Generated multimodal output interleaving text and image placeholders.
Scoring
- 0.0-1.0 (Continuous): Higher means images are more helpful to the surrounding text.
Initialize the DeepEvalImageHelpfulnessMetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models
|
BaseLMInvoker | list[BaseLMInvoker] | None
|
Judge model invoker(s). Defaults to None. |
None
|
fallback_models
|
list[BaseLMInvoker] | None
|
Ordered fallback invokers. Defaults to None. |
None
|
threshold
|
float
|
Success threshold. Defaults to 0.5. |
0.5
|
aggregation_method
|
AggregationSelector
|
Multi-judge aggregation. Defaults to AVERAGE. |
AVERAGE
|
max_concurrent_judges
|
int | None
|
Concurrency limit. Defaults to None. |
None
|
skip_multimodal_check
|
bool
|
By default, the SDK checks whether the judge model supports image input. Set to True only when the judge model supports image input but is not in the SDK's built-in supported-model list. Defaults to False. |
False
|
DeepEvalImageReferenceMetric(models=None, fallback_models=None, threshold=0.5, aggregation_method=AggregationMethod.AVERAGE, max_concurrent_judges=None, skip_multimodal_check=False)
Bases: BaseDeepEvalImageMetric
DeepEval Image Reference Metric.
Native DeepEval multimodal metric that judges whether the surrounding text
correctly references each image in a multimodal actual_output. Place the
images in actual_output with [ATTACHMENT:...] placeholders.
Available Fields
- actual_output (str): Generated multimodal output interleaving text and image placeholders.
Scoring
- 0.0-1.0 (Continuous): Higher means the text references its images more accurately.
Initialize the DeepEvalImageReferenceMetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models
|
BaseLMInvoker | list[BaseLMInvoker] | None
|
Judge model invoker(s). Defaults to None. |
None
|
fallback_models
|
list[BaseLMInvoker] | None
|
Ordered fallback invokers. Defaults to None. |
None
|
threshold
|
float
|
Success threshold. Defaults to 0.5. |
0.5
|
aggregation_method
|
AggregationSelector
|
Multi-judge aggregation. Defaults to AVERAGE. |
AVERAGE
|
max_concurrent_judges
|
int | None
|
Concurrency limit. Defaults to None. |
None
|
skip_multimodal_check
|
bool
|
By default, the SDK checks whether the judge model supports image input. Set to True only when the judge model supports image input but is not in the SDK's built-in supported-model list. Defaults to False. |
False
|
DeepEvalJsonCorrectnessMetric(expected_schema, models=None, fallback_models=None, threshold=0.5, aggregation_method=AggregationMethod.MAJORITY_VOTE, max_concurrent_judges=None)
Bases: DeepEvalMetricFactory
DeepEval JSON Correctness Metric Integration.
This metric evaluates whether a response is JSON correct according to a specified schema. It helps ensure that AI responses follow the expected JSON structure.
Available Fields
- input (str): The query to evaluate the metric.
- actual_output (str): The generated response to evaluate the metric.
Scoring
- 0.0-1.0 (Binary): 0.0 means the response is not JSON correct according to the schema, 1.0 means the response is JSON correct according to the schema.
Cookbook Example
Please refer to example_deepeval_json_correctness.py in the gen-ai-sdk-cookbook repository.
Initializes the DeepEvalJsonCorrectnessMetric class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expected_schema
|
Type[BaseModel]
|
The expected schema class (not instance) for the response.
Example: |
required |
threshold
|
float
|
The threshold to use for the metric. Defaults to 0.5. |
0.5
|
models
|
BaseLMInvoker | list[BaseLMInvoker] | None
|
The model invoker(s) to use for multi-judge evaluation. Defaults to None. |
None
|
fallback_models
|
list[BaseLMInvoker] | None
|
Ordered list of fallback invokers tried in sequence when the primary judge fails. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
The aggregation method to use for the metric. Defaults to AggregationMethod.MAJORITY_VOTE. |
MAJORITY_VOTE
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If expected_schema is not a valid BaseModel class. |
DeepEvalKnowledgeRetentionMetric(name='deepeval_knowledge_retention', threshold=0.5, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, skip_multimodal_check=False, max_concurrent_judges=None)
Bases: ConvDeepEvalMetricFactory
Whether the assistant retains information the user shared in earlier turns.
Conversation-level: scores the whole transcript in one judge call.
A decision-model judge scores the whole conversation in DeepEval's native system_one mode.
Initialize the metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric name used in scoring output. Defaults to "deepeval_knowledge_retention". |
'deepeval_knowledge_retention'
|
threshold
|
float
|
Pass/fail threshold in [0, 1]. Defaults to 0.5. |
0.5
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
Judge model(s). None uses the SDK default; a list runs multi-judge. A decision model judges in
DeepEval's native |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered fallback invokers. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
Strategy used when
|
AGGREGATION_METHOD
|
skip_multimodal_check
|
bool
|
When True, the caller asserts the judge supports image input. Defaults to False. |
False
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
DeepEvalMetric(metric, name, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, max_concurrent_judges=None, skip_multimodal_check=False)
Bases: BaseMetric
DeepEval Metric.
A wrapper for DeepEval metrics.
Available Fields
- input (str): The query to evaluate the metric.
- actual_output (str, optional): The generated response to evaluate the metric.
- expected_output (str, optional): The expected response to evaluate the metric.
- expected_context (str | list[str], optional): The expected retrieved context to evaluate the metric. If a str, it will be converted into a list with a single element.
- retrieved_context (str | list[str], optional): The list of retrieved contexts to evaluate the metric. If a str, it will be converted into a list with a single element.
Scoring
- 0.0-1.0 (Continuous): Or Boolean depending on the DeepEval metric.
Initializes the DeepEvalMetric class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
BaseMetric
|
The DeepEval metric to wrap. |
required |
name
|
str
|
The name of the metric. |
required |
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
The model invoker(s) to use for multi-judge evaluation. Defaults to None. |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered fallback invokers tried when the primary judge fails. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
The aggregation method to use for the metric. Defaults to DefaultValues.AGGREGATION_METHOD. |
AGGREGATION_METHOD
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
skip_multimodal_check
|
bool
|
When True, asserts the judge supports image input so multimodal capability resolution skips the probe for models not in the blessed list. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
EvalConfigurationError
|
If the DeepEval metric needs a test-case parameter that this wrapper does not pass to DeepEval. |
DeepEvalMetricFactory(name, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, max_concurrent_judges=None, skip_multimodal_check=False, **kwargs)
Bases: DeepEvalMetric, ABC
DeepEval Metric Factory.
Abstract base class for creating DeepEval metrics with a shared model invoker.
Available Fields
- (Dynamic): Depends on the specific DeepEval metric being created.
Scoring
- (Dynamic): Depends on the specific DeepEval metric.
Initializes the metric, handling common model invoker creation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name for the metric. |
required |
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
The model invoker(s) to use for multi-judge evaluation.
|
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered list of fallback invokers tried in sequence when the primary judge fails. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
The aggregation method to use for repeated-judge evaluation. Defaults to DefaultValues.AGGREGATION_METHOD. |
AGGREGATION_METHOD
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
skip_multimodal_check
|
bool
|
When True, asserts the judge supports image input so multimodal capability resolution skips the probe for models not in the blessed list. Defaults to False. |
False
|
**kwargs
|
Additional arguments for the specific DeepEval metric constructor. |
{}
|
Raises:
| Type | Description |
|---|---|
EvalConfigurationError
|
If the threshold is outside [0, 1] or the judge configuration is invalid. |
DeepEvalPromptAlignmentMetric(prompt_instructions, models=None, fallback_models=None, threshold=0.5, aggregation_method=AggregationMethod.AVERAGE, max_concurrent_judges=None)
Bases: DeepEvalMetricFactory
DeepEval Prompt Alignment Metric Integration.
This metric evaluates whether a response is aligned with the prompt instructions.
It helps ensure that AI responses are aligned with the prompt instructions. A decision-model judge
(BaseDMInvoker, such as TypeSafe Jev) scores it through DeepEval's native system_one path, with one question
per instruction: DeepEval asks the questions and computes the score, and no LLM call is made. A chain that mixes
both kinds of judge tries each judge in order, each as one complete measurement, so one run can hold rows scored by
either kind.
Available Fields
- input (str): The query to evaluate the metric.
- actual_output (str): The generated response to evaluate the metric.
Scoring
- 0.0-1.0 (Continuous): Scale where closer to 1.0 means more aligned with the prompt instructions, closer to 0.0 means less aligned with the prompt instructions.
Cookbook Example
Please refer to example_deepeval_prompt_alignment.py in the
gen-ai-sdk-cookbook repository.
Initializes the DeepEvalPromptAlignmentMetric class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt_instructions
|
list[str]
|
a list of strings specifying the instructions you want followed in your prompt template. |
required |
threshold
|
float
|
The threshold to use for the metric. Defaults to 0.5. |
0.5
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
The judge invoker(s) to use for multi-judge evaluation. Each is an LM invoker or a decision-model invoker. Defaults to None, which uses the default LM judge. |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered list of fallback invokers, LM or decision model, tried in sequence when the primary judge fails. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
The aggregation method to use for the metric. Defaults to AggregationMethod.AVERAGE. |
AVERAGE
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
EvalConfigurationError
|
If prompt_instructions is empty, is not a list, or contains a non-string item. |
DeepEvalRoleAdherenceMetric(name='deepeval_role_adherence', threshold=0.5, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, skip_multimodal_check=False, max_concurrent_judges=None)
Bases: ConvDeepEvalMetricFactory
Whether the assistant stayed in its assigned role across the conversation.
Conversation-only.
A decision-model judge scores the whole conversation in DeepEval's native system_one mode.
Initialize the metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric name used in scoring output. Defaults to "deepeval_role_adherence". |
'deepeval_role_adherence'
|
threshold
|
float
|
Pass/fail threshold in [0, 1]. Defaults to 0.5. |
0.5
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
Judge model(s). None uses the SDK default; a list runs multi-judge. A decision model judges in
DeepEval's native |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered fallback invokers. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
Strategy used when
|
AGGREGATION_METHOD
|
skip_multimodal_check
|
bool
|
When True, the caller asserts the judge supports image input. Defaults to False. |
False
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
DeepEvalTextToImageMetric(models=None, fallback_models=None, threshold=0.5, aggregation_method=AggregationMethod.AVERAGE, max_concurrent_judges=None, skip_multimodal_check=False)
Bases: BaseDeepEvalImageMetric
DeepEval Text-to-Image Metric.
Native DeepEval multimodal metric that judges a generated image against the
text prompt that requested it (semantic consistency and perceptual quality).
Put the prompt text in input and the generated image in actual_output
with a [ATTACHMENT:...] placeholder.
Available Fields
- input (str): The text prompt describing the desired image.
- actual_output (str): The generated image placeholder.
Scoring
- 0.0-1.0 (Continuous): Higher means the generated image better matches the prompt.
Initialize the DeepEvalTextToImageMetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models
|
BaseLMInvoker | list[BaseLMInvoker] | None
|
Judge model invoker(s). Defaults to None. |
None
|
fallback_models
|
list[BaseLMInvoker] | None
|
Ordered fallback invokers. Defaults to None. |
None
|
threshold
|
float
|
Success threshold. Defaults to 0.5. |
0.5
|
aggregation_method
|
AggregationSelector
|
Multi-judge aggregation. Defaults to AVERAGE. |
AVERAGE
|
max_concurrent_judges
|
int | None
|
Concurrency limit. Defaults to None. |
None
|
skip_multimodal_check
|
bool
|
By default, the SDK checks whether the judge model supports image input. Set to True only when the judge model supports image input but is not in the SDK's built-in supported-model list. Defaults to False. |
False
|
DeepEvalToolCorrectnessMetric(threshold=0.5, include_reason=True, strict_mode=False, should_exact_match=False, should_consider_ordering=False, available_tools=None, evaluation_params=None, models=None, fallback_models=None, aggregation_method=AggregationMethod.AVERAGE, max_concurrent_judges=None)
Bases: DeepEvalMetricFactory
DeepEval Tool Correctness Metric.
This metric evaluates whether an agent correctly selects and calls tools based on the user query and available tool definitions.
A decision-model judge (BaseDMInvoker, such as TypeSafe Jev) is asked only the tool-selection question, as one
native Score decision, and only when available_tools is set. Tool matching stays deterministic. Without
available_tools no judge is called and the row's usage is unmeasured.
Available Fields
- query (str): The input query.
- generated_response (str, optional): The actual output/response.
- expected_response (str, optional): The expected output/response.
- tools_called (list[ToolCall], optional): The tools actually called by the agent. Each item should include 'name', 'input_parameters', and optionally 'output'. If not provided, will be extracted from agent_trajectory.
- expected_tools (list[ToolCall], optional): The expected tools to be called. Each item should include 'name', 'input_parameters', and optionally 'output'. If not provided, will be extracted from expected_agent_trajectory.
- agent_trajectory (list[dict], optional): Agent messages in OpenAI format (role-based with 'user', 'assistant', 'tool' roles). Tool calls are extracted from assistant messages with 'tool_calls' field.
- expected_agent_trajectory (list[dict], optional): Expected agent messages in OpenAI format, same structure as agent_trajectory.
- available_tools (list[dict] | None, optional): All available tools for context. Each tool definition should have 'name', 'description', and 'parameters'.
Scoring
- 0.0-1.0 (Continuous): Scale where closer to 1.0 means more correct tool usage, closer to 0.0 means less correct tool usage.
Cookbook Example
Please refer to example_deepeval_tool_correctness.py in the gen-ai-sdk-cookbook repository.
Initializes DeepEvalToolCorrectnessMetric class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
The threshold to use for the metric. Defaults to 0.5. |
0.5
|
include_reason
|
bool
|
Whether to include score reasoning. Defaults to True. |
True
|
strict_mode
|
bool
|
Whether to enforce strict scoring. Defaults to False. |
False
|
should_exact_match
|
bool
|
Whether tool calls must exactly match. Defaults to False. |
False
|
should_consider_ordering
|
bool
|
Whether call order matters. Defaults to False. |
False
|
available_tools
|
list[dict[str, Any]] | None
|
Available tool definitions. Defaults to None. |
None
|
evaluation_params
|
list[ToolCallParams | str] | None
|
The tool call fields that the LLM judge
will compare between the actual and expected tool calls. Defaults to None (all supported
fields are evaluated by DeepEval's default behaviour when None or empty list is passed).
String entries are accepted and coerced to the matching
|
None
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
The judge invoker(s) to use for multi-judge evaluation. Each is an LM invoker or a decision-model invoker.
|
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered list of fallback invokers, LM or decision model, tried in sequence when the primary judge fails. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
The aggregation method to use for the metric. Defaults to AggregationMethod.AVERAGE. |
AVERAGE
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use. Defaults to None. |
None
|
DeepEvalToolUseMetric(available_tools, name='deepeval_tool_use', threshold=0.5, include_reason=True, strict_mode=False, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, skip_multimodal_check=False, max_concurrent_judges=None)
Bases: ConvDeepEvalMetricFactory
Whether the agent selected the right tools, from a known catalogue, across the conversation.
Conversation-only; DeepEvalToolCorrectnessMetric scores single-turn rows.
A decision-model judge scores the whole conversation, with the catalogue, in DeepEval's native system_one
mode.
Initialize the metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
available_tools
|
list[dict[str, Any]]
|
The tools the agent could choose from, each with 'name', 'description', and 'parameters'. |
required |
name
|
str
|
Metric name used in scoring output. Defaults to "deepeval_tool_use". |
'deepeval_tool_use'
|
threshold
|
float
|
Pass/fail threshold in [0, 1]. Defaults to 0.5. |
0.5
|
include_reason
|
bool
|
Whether to include score reasoning. Defaults to True. |
True
|
strict_mode
|
bool
|
Whether to enforce strict scoring. Defaults to False. |
False
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
Judge model(s). None uses the SDK default; a list runs multi-judge. A decision model judges in
DeepEval's native |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered fallback invokers. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
Strategy used when
|
AGGREGATION_METHOD
|
skip_multimodal_check
|
bool
|
When True, the caller asserts the judge supports image input. Defaults to False. |
False
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
EvalConfigurationError
|
If |
DeepEvalTopicAdherenceMetric(relevant_topics, name='deepeval_topic_adherence', threshold=0.5, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, skip_multimodal_check=False, max_concurrent_judges=None)
Bases: ConvDeepEvalMetricFactory
Whether the conversation stayed within an allowed set of topics.
Conversation-level: scores the whole transcript in one judge call. Only accepts
ConversationalTestCase input.
A decision-model judge scores the whole conversation in DeepEval's native system_one mode.
Initialize the metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
relevant_topics
|
list[str]
|
The topics the conversation is allowed to cover. |
required |
name
|
str
|
Metric name used in scoring output. Defaults to "deepeval_topic_adherence". |
'deepeval_topic_adherence'
|
threshold
|
float
|
Pass/fail threshold in [0, 1]. Defaults to 0.5. |
0.5
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
Judge model(s). None uses the SDK default; a list runs multi-judge. A decision model judges in
DeepEval's native |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered fallback invokers. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
Strategy used when
|
AGGREGATION_METHOD
|
skip_multimodal_check
|
bool
|
When True, the caller asserts the judge supports image input. Defaults to False. |
False
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
EvalConfigurationError
|
If |
DeepEvalTurnContextualPrecisionMetric(name='deepeval_turn_contextual_precision', threshold=DefaultValues.CONTEXTUAL_PRECISION_THRESHOLD, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, skip_multimodal_check=False, max_concurrent_judges=None, window_size=10, evaluation_template=TurnContextualPrecisionTemplate)
Bases: ConvDeepEvalMetricFactory
Whether each turn's relevant retrieved context is ranked above its irrelevant context.
Conversation-only; DeepEvalContextualPrecisionMetric scores single-turn rows.
A decision-model judge scores the whole conversation in DeepEval's native system_one mode.
Initialize the metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric name used in scoring output. Defaults to "deepeval_turn_contextual_precision". |
'deepeval_turn_contextual_precision'
|
threshold
|
float
|
Pass/fail threshold in [0, 1]. Defaults to 0.4, the same cutoff as the single-turn contextual precision metric. |
CONTEXTUAL_PRECISION_THRESHOLD
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
Judge model(s). None uses the SDK default; a list runs multi-judge. A decision model judges in
DeepEval's native |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered fallback invokers. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
Strategy used when
|
AGGREGATION_METHOD
|
skip_multimodal_check
|
bool
|
When True, the caller asserts the judge supports image input. Defaults to False. |
False
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
window_size
|
int
|
How many recent exchanges the judge sees in one sliding window. A decision-model judge scores the whole conversation, so this applies to LM judges only. Defaults to 10, DeepEval's own default. |
10
|
evaluation_template
|
Type[TurnContextualPrecisionTemplate]
|
The prompt template the judge uses. A decision-model judge receives the template's native questions, which must be Noul or Score questions. Defaults to TurnContextualPrecisionTemplate. |
TurnContextualPrecisionTemplate
|
DeepEvalTurnContextualRecallMetric(name='deepeval_turn_contextual_recall', threshold=DefaultValues.CONTEXTUAL_RECALL_THRESHOLD, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, skip_multimodal_check=False, max_concurrent_judges=None, window_size=10, evaluation_template=TurnContextualRecallTemplate)
Bases: ConvDeepEvalMetricFactory
Whether each turn's retrieved context covers what the conversation's expected outcome needs.
Conversation-only; DeepEvalContextualRecallMetric scores single-turn rows.
A decision-model judge scores the whole conversation in DeepEval's native system_one mode.
Initialize the metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric name used in scoring output. Defaults to "deepeval_turn_contextual_recall". |
'deepeval_turn_contextual_recall'
|
threshold
|
float
|
Pass/fail threshold in [0, 1]. Defaults to 0.6, the same cutoff as the single-turn contextual recall metric. |
CONTEXTUAL_RECALL_THRESHOLD
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
Judge model(s). None uses the SDK default; a list runs multi-judge. A decision model judges in
DeepEval's native |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered fallback invokers. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
Strategy used when
|
AGGREGATION_METHOD
|
skip_multimodal_check
|
bool
|
When True, the caller asserts the judge supports image input. Defaults to False. |
False
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
window_size
|
int
|
How many recent exchanges the judge sees in one sliding window. A decision-model judge scores the whole conversation, so this applies to LM judges only. Defaults to 10, DeepEval's own default. |
10
|
evaluation_template
|
Type[TurnContextualRecallTemplate]
|
The prompt template the judge uses. A decision-model judge receives the template's native questions, which must be Noul or Score questions. Defaults to TurnContextualRecallTemplate. |
TurnContextualRecallTemplate
|
DeepEvalTurnContextualRelevancyMetric(name='deepeval_turn_contextual_relevancy', threshold=0.5, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, skip_multimodal_check=False, max_concurrent_judges=None, window_size=10)
Bases: ConvDeepEvalMetricFactory
How relevant each turn's retrieved context is to the user turn it was retrieved for.
Conversation-only; DeepEvalContextualRelevancyMetric scores single-turn rows.
A decision-model judge scores the whole conversation in DeepEval's native system_one mode.
Initialize the metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric name used in scoring output. Defaults to "deepeval_turn_contextual_relevancy". |
'deepeval_turn_contextual_relevancy'
|
threshold
|
float
|
Pass/fail threshold in [0, 1]. Defaults to 0.5. |
0.5
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
Judge model(s). None uses the SDK default; a list runs multi-judge. A decision model judges in
DeepEval's native |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered fallback invokers. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
Strategy used when
|
AGGREGATION_METHOD
|
skip_multimodal_check
|
bool
|
When True, the caller asserts the judge supports image input. Defaults to False. |
False
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
window_size
|
int
|
How many recent exchanges the judge sees in one sliding window. A decision-model judge scores the whole conversation, so this applies to LM judges only. Defaults to 10, DeepEval's own default. |
10
|
DeepEvalTurnFaithfulnessMetric(name='deepeval_turn_faithfulness', threshold=0.5, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, skip_multimodal_check=False, max_concurrent_judges=None, window_size=10, turn_aggregation=TurnAggregationMethod.MEAN)
Bases: ConvDeepEvalMetricFactory
Whether each assistant turn relies only on the context retrieved for that turn.
Conversation-only; DeepEvalFaithfulnessMetric scores single-turn rows.
A decision-model judge scores the whole conversation in DeepEval's native system_one mode.
Initialize the metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric name used in scoring output. Defaults to "deepeval_turn_faithfulness". |
'deepeval_turn_faithfulness'
|
threshold
|
float
|
Pass/fail threshold in [0, 1]. Defaults to 0.5. |
0.5
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
Judge model(s). None uses the SDK default; a list runs multi-judge. A decision model judges in
DeepEval's native |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered fallback invokers. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
Strategy used when
|
AGGREGATION_METHOD
|
skip_multimodal_check
|
bool
|
When True, the caller asserts the judge supports image input. Defaults to False. |
False
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
window_size
|
int
|
How many recent exchanges the judge sees in one sliding window. A decision-model judge scores the whole conversation, so this applies to LM judges only. Defaults to 10, DeepEval's own default. |
10
|
turn_aggregation
|
TurnAggregationSelector
|
How per-turn scores become the
row's score: MEAN averages them, WORST_TURN takes the lowest. A
|
MEAN
|
Raises:
| Type | Description |
|---|---|
EvalConfigurationError
|
If |
DeepEvalTurnRelevancyMetric(name='deepeval_turn_relevancy', threshold=0.5, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, skip_multimodal_check=False, max_concurrent_judges=None, window_size=10)
Bases: ConvDeepEvalMetricFactory
Whether each assistant turn answers the user turn that preceded it.
Conversation-only; DeepEvalAnswerRelevancyMetric scores single-turn rows.
A decision-model judge scores the whole conversation in DeepEval's native system_one mode.
Initialize the metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric name used in scoring output. Defaults to "deepeval_turn_relevancy". |
'deepeval_turn_relevancy'
|
threshold
|
float
|
Pass/fail threshold in [0, 1]. Defaults to 0.5. |
0.5
|
models
|
BaseLMInvoker | BaseDMInvoker | list[BaseLMInvoker | BaseDMInvoker] | None
|
Judge model(s). None uses the SDK default; a list runs multi-judge. A decision model judges in
DeepEval's native |
None
|
fallback_models
|
list[BaseLMInvoker | BaseDMInvoker] | None
|
Ordered fallback invokers. Defaults to None. |
None
|
aggregation_method
|
AggregationSelector
|
Strategy used when
|
AGGREGATION_METHOD
|
skip_multimodal_check
|
bool
|
When True, the caller asserts the judge supports image input. Defaults to False. |
False
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
window_size
|
int
|
How many recent exchanges the judge sees in one sliding window. A decision-model judge scores the whole conversation, so this applies to LM judges only. Defaults to 10, DeepEval's own default. |
10
|
GEvalCompletenessMetric(*args, threshold=1.0, **kwargs)
Bases: DeepEvalGEvalMetric
GEval Completeness Metric.
This metric is used to evaluate the completeness of the generated output.
Available Fields
- query (str): The query to evaluate the completeness of the model's output.
- generated_response (str): The generated response to evaluate the completeness of the model's output.
- expected_response (str): The expected response to evaluate the completeness of the model's output.
Scoring
- [0, 1] (Continuous): Normalized score range. Stored native 1-3 rubric value in rubric_score field.
Cookbook Example
Please refer to example_geval_completeness.py in the gen-ai-sdk-cookbook repository.
Initializes the GEvalCompletenessMetric class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
The name of the metric. Defaults to "completeness". |
required |
evaluation_params
|
list[SingleTurnParams] | None
|
The evaluation parameters. Defaults to [INPUT, ACTUAL_OUTPUT, EXPECTED_OUTPUT]. |
required |
models
|
BaseLMInvoker | list[BaseLMInvoker] | None
|
The model invoker(s) to use for the metric. |
required |
criteria
|
str | None
|
The criteria to use for the metric. Defaults to COMPLETENESS_CRITERIA. |
required |
evaluation_steps
|
list[str] | None
|
The evaluation steps to use for the metric. Defaults to COMPLETENESS_EVALUATION_STEPS. |
required |
rubric
|
list[Rubric] | None
|
The rubric to use for the metric. Defaults to COMPLETENESS_RUBRIC. |
required |
threshold
|
float
|
The threshold to use for the metric. Defaults to 1.0. Must be between 0.0 and 1.0 inclusive. |
1.0
|
additional_info
|
str | None
|
Domain knowledge and scoring rules. Defaults to None. |
required |
fewshot
|
str | None
|
Few-shot examples for this metric. Defaults to COMPLETENESS_FEW_SHOT. |
required |
strict_mode
|
bool
|
If True, binarizes score to 1.0 or 0.0. Defaults to False. |
required |
GEvalConcisenessMetric(name=None, evaluation_params=None, criteria=None, evaluation_steps=None, rubric=None, threshold=0.5, additional_info=None, fewshot=None, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, max_concurrent_judges=None, strict_mode=False, multimodal=None, multimodal_rules=None, skip_multimodal_check=False)
Bases: DeepEvalGEvalMetric
GEval Conciseness Metric.
This metric is used to evaluate whether the generated output contains only the essential information requested.
Available Fields
- input (str): The input to evaluate the conciseness of the model's output against.
- actual_output (str): The generated output to evaluate the conciseness of.
Scoring
- [0, 1] (Continuous): Normalized score range. Stored native 0-1 rubric value in rubric_score field. Higher score is better (higher_is_better=True).
Cookbook Example
Please refer to example_geval_conciseness.py in the gen-ai-sdk-cookbook repository.
GEvalContextSufficiencyMetric(name=None, evaluation_params=None, criteria=None, evaluation_steps=None, rubric=None, threshold=0.5, additional_info=None, fewshot=None, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, max_concurrent_judges=None, strict_mode=False, multimodal=None, multimodal_rules=None, skip_multimodal_check=False)
Bases: DeepEvalGEvalMetric
GEval Context Sufficiency Metric.
This metric is used to evaluate if the context contains enough information to answer the query.
Available Fields
- query (str): The query to evaluate.
- retrieved_context (str | list[str]): The retrieved context to check for sufficiency.
Scoring
- 0-1 (Binary): Where 0 means insufficient context and 1 means sufficient context.
Cookbook Example
Please refer to example_geval_context_sufficiency.py in the gen-ai-sdk-cookbook repository.
GEvalGroundednessMetric(*args, threshold=1.0, **kwargs)
Bases: DeepEvalGEvalMetric
GEval Groundedness Metric.
This metric is used to evaluate the groundedness of the generated output.
Available Fields
- query (str): The query to evaluate the groundedness of the model's output.
- generated_response (str): The generated response to evaluate the groundedness of the model's output.
- retrieved_context (str): The retrieved context to evaluate the groundedness of the model's output.
Scoring
- [0, 1] (Continuous): Normalized score range. Stored native 1-3 rubric value in rubric_score field.
Cookbook Example
Please refer to example_geval_groundedness.py in the gen-ai-sdk-cookbook repository.
Initializes the GEvalGroundednessMetric class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
The name of the metric. Defaults to "groundedness". |
required |
evaluation_params
|
list[SingleTurnParams] | None
|
The evaluation parameters. Defaults to [INPUT, ACTUAL_OUTPUT, RETRIEVAL_CONTEXT]. |
required |
models
|
BaseLMInvoker | list[BaseLMInvoker] | None
|
The model invoker(s) to use for the metric. |
required |
criteria
|
str | None
|
The criteria to use for the metric. Defaults to GROUNDEDNESS_CRITERIA. |
required |
evaluation_steps
|
list[str] | None
|
The evaluation steps to use for the metric. Defaults to GROUNDEDNESS_EVALUATION_STEPS. |
required |
rubric
|
list[Rubric] | None
|
The rubric to use for the metric. Defaults to GROUNDEDNESS_RUBRIC. |
required |
threshold
|
float
|
The threshold to use for the metric. Defaults to 1.0. Must be between 0.0 and 1.0 inclusive. |
1.0
|
additional_info
|
str | None
|
Domain knowledge and scoring rules. Defaults to None. |
required |
fewshot
|
str | None
|
Few-shot examples for this metric. Defaults to GROUNDEDNESS_FEW_SHOT. |
required |
strict_mode
|
bool
|
If True, binarizes score to 1.0 or 0.0. Defaults to False. |
required |
GEvalHelpfulnessMetric(name=None, evaluation_params=None, criteria=None, evaluation_steps=None, rubric=None, threshold=0.5, additional_info=None, fewshot=None, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, max_concurrent_judges=None, strict_mode=False, multimodal=None, multimodal_rules=None, skip_multimodal_check=False)
Bases: DeepEvalGEvalMetric
GEval Helpfulness Metric.
This metric judges whether the generated response is helpful and relevant to the input. It uses the OpenEvals
RAG_HELPFULNESS_PROMPT mapped into the GEval prompt slots. It judges practical usefulness only; it does not check
support from retrieved context.
Available Fields
- input (str): The query the response should address.
- actual_output (str): The generated response to judge.
Scoring
- [0, 1] (Continuous): Normalized score range. Stored native 0-1 rubric value in rubric_score field. Higher score is better (higher_is_better=True).
Cookbook Example
Please refer to example_geval_helpfulness.py in the gen-ai-sdk-cookbook repository.
GEvalLanguageConsistencyMetric(name=None, evaluation_params=None, criteria=None, evaluation_steps=None, rubric=None, threshold=0.5, additional_info=None, fewshot=None, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, max_concurrent_judges=None, strict_mode=False, multimodal=None, multimodal_rules=None, skip_multimodal_check=False)
Bases: DeepEvalGEvalMetric
GEval Language Consistency Metric.
This metric is used to predict if the question and generated response is a language consistency response.
Available Fields
- query (str): The query to predict if it is a language consistency response.
- generated_response (str): The generated response to predict if it is a language consistency response.
Scoring
- [0, 1] (Continuous): Normalized score range. Stored native 0-1 rubric value in rubric_score field.
Cookbook Example
Please refer to example_geval_language_consistency.py in the gen-ai-sdk-cookbook repository.
GEvalRedundancyMetric(*args, threshold=0.5, **kwargs)
Bases: DeepEvalGEvalMetric
GEval Redundancy Metric.
This metric is used to evaluate the redundancy of the generated output.
Available Fields
- query (str): The query to evaluate the redundancy of the model's output.
- generated_response (str): The generated response to evaluate the redundancy of the model's output.
Scoring
- [0, 1] (Continuous): Normalized score range. Stored native 1-3 rubric value in rubric_score field. Lower score is better (higher_is_better=False).
Cookbook Example
Please refer to example_geval_redundancy.py in the gen-ai-sdk-cookbook repository.
Initializes GEvalRedundancyMetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Positional arguments passed to :class: |
()
|
|
threshold
|
float
|
The threshold to use for the metric. Defaults to 0.5. |
0.5
|
**kwargs
|
Keyword arguments passed to :class: |
{}
|
GEvalRefusalAlignmentMetric(name=None, evaluation_params=None, criteria=None, evaluation_steps=None, rubric=None, threshold=0.5, additional_info=None, fewshot=None, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, max_concurrent_judges=None, strict_mode=False, multimodal=None, multimodal_rules=None, skip_multimodal_check=False)
Bases: DeepEvalGEvalMetric
GEval Refusal Alignment Metric.
This metric evaluates whether the generated response correctly aligns with the expected refusal behavior. It checks if both the expected and generated responses have the same refusal status.
Available Fields
- query (str): The query to evaluate the metric.
- expected_response (str): The expected response to evaluate the metric.
- generated_response (str): The generated response to evaluate the metric.
- is_refusal (bool, optional): Whether the sample should be treated as a refusal response.
Scoring
- [0, 1] (Continuous): Normalized score range. Stored native 0-1 rubric value in rubric_score field.
Cookbook Example
Please refer to example_geval_refusal_alignment.py in the gen-ai-sdk-cookbook repository.
GEvalRefusalMetric(name=None, evaluation_params=None, criteria=None, evaluation_steps=None, rubric=None, threshold=0.5, additional_info=None, fewshot=None, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, max_concurrent_judges=None, strict_mode=False, multimodal=None, multimodal_rules=None, skip_multimodal_check=False)
Bases: DeepEvalGEvalMetric
GEval Refusal Metric.
This metric is used to predict if the question and expected response is a refusal response.
Available Fields
- query (str): The query to predict if it is a refusal response.
- expected_response (str): The expected response to predict if it is a refusal response.
Scoring
- [0, 1] (Continuous): Normalized score range. Stored native 0-1 rubric value in rubric_score field. Higher score is better (higher_is_better=True).
Cookbook Example
Please refer to example_geval_refusal.py in the gen-ai-sdk-cookbook repository.
GEvalSummarizationCoherenceMetric(name=None, evaluation_params=None, criteria=None, evaluation_steps=None, rubric=None, threshold=0.5, additional_info=None, fewshot=None, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, max_concurrent_judges=None, strict_mode=False, multimodal=None, multimodal_rules=None, skip_multimodal_check=False)
Bases: GEvalSummarizationBaseMetric
GEval Summarization Coherence metric.
This metric is used to evaluate the coherence quality of summarization output using GEval.
Available Fields
- input (str): Source text or transcript.
- summary (str): Generated summary.
Scoring
- [0, 1] float: A higher score indicates better coherence.
Cookbook Example
Please refer to example_geval_summarization_coherence.py in the gen-ai-sdk-cookbook repository.
GEvalSummarizationConsistencyMetric(*args, threshold=1, **kwargs)
Bases: GEvalSummarizationBaseMetric
GEval Summarization Consistency metric.
This metric is used to evaluate factual consistency quality of summarization output using GEval.
Available Fields
- input (str): Source text or transcript.
- summary (str): Generated summary.
Scoring
- [0, 1] float: A higher score indicates better consistency.
Cookbook Example
Please refer to example_geval_summarization_consistency.py in the gen-ai-sdk-cookbook repository.
Initializes GEvalSummarizationConsistencyMetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Positional arguments passed to :class: |
()
|
|
threshold
|
float
|
The threshold to use for the metric. Defaults to 1. |
1
|
**kwargs
|
Keyword arguments passed to :class: |
{}
|
GEvalSummarizationFluencyMetric(name=None, evaluation_params=None, criteria=None, evaluation_steps=None, rubric=None, threshold=0.5, additional_info=None, fewshot=None, models=None, fallback_models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, max_concurrent_judges=None, strict_mode=False, multimodal=None, multimodal_rules=None, skip_multimodal_check=False)
Bases: GEvalSummarizationBaseMetric
GEval Summarization Fluency metric.
This metric is used to evaluate fluency quality of summarization output using GEval.
Available Fields
- input (str): Source text or transcript.
- summary (str): Generated summary.
Scoring
- [0, 1] float: A higher score indicates better fluency.
Cookbook Example
Please refer to example_geval_summarization_fluency.py in the gen-ai-sdk-cookbook repository.
GEvalSummarizationRelevanceMetric(*args, threshold=1, **kwargs)
Bases: GEvalSummarizationBaseMetric
GEval Summarization Relevance metric.
This metric is used to evaluate the relevance quality of summarization output using GEval.
Available Fields
- input (str): Source text or transcript.
- summary (str): Generated summary.
Scoring
- [0, 1] float: A higher score indicates better relevance.
Cookbook Example
Please refer to example_geval_summarization_relevance.py in the gen-ai-sdk-cookbook repository.
Initializes GEvalSummarizationRelevanceMetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Positional arguments passed to :class: |
()
|
|
threshold
|
float
|
The threshold to use for the metric. Defaults to 1. |
1
|
**kwargs
|
Keyword arguments passed to :class: |
{}
|
LMBasedMetric(name, response_schema, prompt_builder, parse_response_fn=None, models=None, aggregation_method=DefaultValues.AGGREGATION_METHOD, max_concurrent_judges=None, multimodal=None, multimodal_rules=None, attachment_resolver_registry=None)
Bases: BaseMetric
A multi purpose LM-based metric class.
This class is a multi purpose LM-based metric class that can be used to evaluate the performance of a LM-based metric. It can be used to evaluate the performance of a LM-based metric by providing a response schema, a prompt builder, a model id, and a model credentials.
Available Fields
- (Dynamic): Depends on the
prompt_builderand specific metric implementation.
Scoring
- (Dynamic): Depends on the specific metric implementation and response validation.
Initialize the LMBasedMetric class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the metric. |
required |
response_schema
|
ResponseSchema
|
The response schema to use for the metric. |
required |
prompt_builder
|
PromptBuilder
|
The prompt builder to use for the metric. |
required |
parse_response_fn
|
Callable[[str | LMOutput], MetricOutput] | None
|
The function to use to parse the response from the LM. Defaults to a function that parses the response from the LM. |
None
|
models
|
BaseLMInvoker | list[BaseLMInvoker] | None
|
The model invoker(s) to use for multi-judge evaluation.
|
None
|
aggregation_method
|
AggregationSelector
|
The aggregation method to use for the metric. Defaults to DefaultValues.AGGREGATION_METHOD. |
AGGREGATION_METHOD
|
max_concurrent_judges
|
int | None
|
The maximum number of concurrent judges to use for the metric. Defaults to None. |
None
|
multimodal
|
bool | None
|
Controls multimodal judge rule injection. |
None
|
multimodal_rules
|
str | None
|
Custom multimodal rules used when rule injection is enabled. Defaults to the SDK-wide multimodal judge rules. |
None
|
attachment_resolver_registry
|
AttachmentResolverRegistry | None
|
Resolver registry for row-level attachment placeholders. Defaults to the standard file/http/https/data registry. |
None
|
PyTrecMetric(metrics=None, k=20)
Bases: BaseClassicalRetrievalMetric
PyTrec Metric.
A wrapper for pytrec_eval to evaluate common Information Retrieval (IR) metrics.
This metric allows you to compute various standard IR scores like NDCG, MAP, MRR, Reciprocal Rank, etc., based on
retrieved chunks and ground truth chunk IDs.
Available Fields
- retrieved_chunks (dict[str, float]): The retrieved chunk ids with their similarity score.
- ground_truth_chunk_ids (list[str]): The ground truth chunk ids.
Scoring
- 0.0-1.0 (Continuous): A higher score indicates better retrieval performance.
Cookbook Example
Please refer to example_pytrec_metric.py in the gen-ai-sdk-cookbook repository.
Initializes the PyTrecMetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
list[PyTrecEvalMetric | str] | set[PyTrecEvalMetric | str] | None
|
The metrics to evaluate. Defaults to all metrics. |
None
|
k
|
int | list[int]
|
The number of retrieved chunks to consider. Defaults to 20. |
20
|
result_names
property
The sub-metric names this metric returns, such as map@5.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: One name per configured metric and k value. |
TopKAccuracy(k=20)
Bases: BaseClassicalRetrievalMetric
Top-K Accuracy Metric.
Evaluates whether the ground truth chunk IDs are present within the top K retrieved chunks. This is a boolean-style hit/miss metric averaged over the dataset; a score of 1.0 means the relevant document was always found in the top K results.
Available Fields
- retrieved_chunks (dict[str, float]): The retrieved chunk ids with their similarity score.
- ground_truth_chunk_ids (list[str]): The ground truth chunk ids.
Scoring
- 0.0-1.0 (Continuous): A higher score indicates better top-k accuracy.
Cookbook Example
Please refer to example_top_k_accuracy.py in the gen-ai-sdk-cookbook repository.
Initializes the TopKAccuracy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
list[int] | int
|
The number of retrieved chunks to consider. Defaults to 20. |
20
|
result_names
property
The sub-metric names this metric returns, such as top_k_accuracy@5.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: One name per k value. |
top_k_accuracy(qrels, results)
Evaluates the top k accuracy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qrels
|
dict[str, dict[str, int]]
|
The ground truth of the retrieved chunks. There are two possible values: |
required |
- 1
|
the chunk is relevant to the query. |
required | |
- 0
|
the chunk is not relevant to the query. |
required | |
results
|
dict[str, dict[str, float]]
|
The retrieved chunks with their similarity score. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
dict[str, dict]: The top k accuracy. |
Example
qrels = {
"q1": {"chunk1": 1, "chunk2": 1},
}
results = {"q1": {"chunk1": 0.9, "chunk2": 0.8, "chunk3": 0.7}}