Unsuccessful Requests Metric

pydantic model ibm_watsonx_gov.metrics.unsuccessful_requests.unsuccessful_requests_metric.UnsuccessfulRequestsMetric

Bases: GenAIMetric

Defines the Unsuccessful Requests metric class.

The Unsuccessful Requests metric measures whether the model answered the request successfully or not by comparing the generated text against the list of unsuccessful phrases.

Examples

  1. Create Unsuccessful Requests metric with default parameters and compute using metrics evaluator.
    metric = UnsuccessfulRequestsMetric()
    result = MetricsEvaluator().evaluate(data={"generated_text": "...", metrics=[metric])
    
  2. Create Unsuccessful Requests metric with a custom threshold.
    threshold  = MetricThreshold(type="upper_limit", value=0.2)
    metric = UnsuccessfulRequestsMetric(threshold=threshold)
    

Show JSON schema
{
   "title": "UnsuccessfulRequestsMetric",
   "description": "Defines the Unsuccessful Requests metric class.\n\nThe Unsuccessful Requests metric measures whether the model answered the request successfully or not by comparing the generated text against the list of unsuccessful phrases.\n\nExamples:\n    1. Create Unsuccessful Requests metric with default parameters and compute using metrics evaluator.\n        .. code-block:: python\n\n            metric = UnsuccessfulRequestsMetric()\n            result = MetricsEvaluator().evaluate(data={\"generated_text\": \"...\", metrics=[metric])\n\n    2. Create Unsuccessful Requests metric with a custom threshold.\n        .. code-block:: python\n\n            threshold  = MetricThreshold(type=\"upper_limit\", value=0.2)\n            metric = UnsuccessfulRequestsMetric(threshold=threshold)",
   "type": "object",
   "properties": {
      "name": {
         "const": "unsuccessful_requests",
         "default": "unsuccessful_requests",
         "description": "The unsuccessful requests metric name.",
         "title": "Name",
         "type": "string"
      },
      "thresholds": {
         "default": [
            {
               "type": "upper_limit",
               "value": 0.1
            }
         ],
         "description": "The metric thresholds.",
         "items": {
            "$ref": "#/$defs/MetricThreshold"
         },
         "title": "Thresholds",
         "type": "array"
      },
      "tasks": {
         "default": [
            "retrieval_augmented_generation",
            "question_answering"
         ],
         "description": "The list of supported tasks.",
         "items": {
            "$ref": "#/$defs/TaskType"
         },
         "title": "Tasks",
         "type": "array"
      },
      "group": {
         "$ref": "#/$defs/MetricGroup",
         "default": "answer_quality",
         "description": "The metric group.",
         "title": "Group"
      },
      "is_reference_free": {
         "default": true,
         "description": "Decides whether this metric needs a reference for computation",
         "title": "Is Reference Free",
         "type": "boolean"
      },
      "method": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "The method used to compute the metric.",
         "title": "Method"
      },
      "metric_dependencies": {
         "default": [],
         "description": "Metrics that needs to be evaluated first",
         "items": {
            "$ref": "#/$defs/GenAIMetric"
         },
         "title": "Metric Dependencies",
         "type": "array"
      },
      "unsuccessful_phrases": {
         "default": [
            "i don't know",
            "i do not know",
            "i'm not sure",
            "i am not sure",
            "i'm unsure",
            "i am unsure",
            "i'm uncertain",
            "i am uncertain",
            "i'm not certain",
            "i am not certain",
            "i can't fulfill",
            "i cannot fulfill"
         ],
         "description": "List of phrases to identify unsuccessful responses",
         "examples": [
            [
               "i do not know",
               "i am not sure"
            ]
         ],
         "items": {
            "type": "string"
         },
         "title": "Unsuccessful phrases",
         "type": "array"
      }
   },
   "$defs": {
      "GenAIMetric": {
         "description": "Defines the Generative AI metric interface",
         "properties": {
            "name": {
               "description": "The name of the metric",
               "title": "Metric Name",
               "type": "string"
            },
            "thresholds": {
               "default": [],
               "description": "The list of thresholds",
               "items": {
                  "$ref": "#/$defs/MetricThreshold"
               },
               "title": "Thresholds",
               "type": "array"
            },
            "tasks": {
               "description": "The task types this metric is associated with.",
               "items": {
                  "$ref": "#/$defs/TaskType"
               },
               "title": "Tasks",
               "type": "array"
            },
            "group": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/MetricGroup"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The metric group this metric belongs to."
            },
            "is_reference_free": {
               "default": true,
               "description": "Decides whether this metric needs a reference for computation",
               "title": "Is Reference Free",
               "type": "boolean"
            },
            "method": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The method used to compute the metric.",
               "title": "Method"
            },
            "metric_dependencies": {
               "default": [],
               "description": "Metrics that needs to be evaluated first",
               "items": {
                  "$ref": "#/$defs/GenAIMetric"
               },
               "title": "Metric Dependencies",
               "type": "array"
            }
         },
         "required": [
            "name",
            "tasks"
         ],
         "title": "GenAIMetric",
         "type": "object"
      },
      "MetricGroup": {
         "enum": [
            "retrieval_quality",
            "answer_quality",
            "content_safety",
            "performance",
            "usage",
            "tool_call_quality",
            "readability"
         ],
         "title": "MetricGroup",
         "type": "string"
      },
      "MetricThreshold": {
         "description": "The class that defines the threshold for a metric.",
         "properties": {
            "type": {
               "description": "Threshold type. One of 'lower_limit', 'upper_limit'",
               "enum": [
                  "lower_limit",
                  "upper_limit"
               ],
               "title": "Type",
               "type": "string"
            },
            "value": {
               "default": 0,
               "description": "The value of metric threshold",
               "title": "Threshold value",
               "type": "number"
            }
         },
         "required": [
            "type"
         ],
         "title": "MetricThreshold",
         "type": "object"
      },
      "TaskType": {
         "description": "Supported task types for generative AI models",
         "enum": [
            "question_answering",
            "classification",
            "summarization",
            "generation",
            "extraction",
            "retrieval_augmented_generation"
         ],
         "title": "TaskType",
         "type": "string"
      }
   }
}

Fields:
field group: ', frozen=True)] = MetricGroup.ANSWER_QUALITY

The metric group.

field name: Annotated[Literal['unsuccessful_requests'], FieldInfo(annotation=NoneType, required=False, default='unsuccessful_requests', title='Name', description='The unsuccessful requests metric name.', frozen=True)] = 'unsuccessful_requests'

The unsuccessful requests metric name.

field tasks: ')] = [TaskType.RAG, TaskType.QA]

The list of supported tasks.

field thresholds: Annotated[list[MetricThreshold], FieldInfo(annotation=NoneType, required=False, default=[MetricThreshold(type='upper_limit', value=0.1)], title='Thresholds', description='The metric thresholds.')] = [MetricThreshold(type='upper_limit', value=0.1)]

The metric thresholds.

field unsuccessful_phrases: Annotated[list[str], FieldInfo(annotation=NoneType, required=False, default=["i don't know", 'i do not know', "i'm not sure", 'i am not sure', "i'm unsure", 'i am unsure', "i'm uncertain", 'i am uncertain', "i'm not certain", 'i am not certain', "i can't fulfill", 'i cannot fulfill'], title='Unsuccessful phrases', description='List of phrases to identify unsuccessful responses', examples=[['i do not know', 'i am not sure']])] = ["i don't know", 'i do not know', "i'm not sure", 'i am not sure', "i'm unsure", 'i am unsure', "i'm uncertain", 'i am uncertain', "i'm not certain", 'i am not certain', "i can't fulfill", 'i cannot fulfill']

List of phrases to identify unsuccessful responses

evaluate(data: DataFrame, configuration: GenAIConfiguration | AgenticAIConfiguration, **kwargs) AggregateMetricResult
model_post_init(context: Any, /) None

We need to both initialize private attributes and call the user-defined model_post_init method.

pydantic model ibm_watsonx_gov.metrics.unsuccessful_requests.unsuccessful_requests_metric.UnsuccessfulRequestsResult

Bases: RecordMetricResult

Show JSON schema
{
   "title": "UnsuccessfulRequestsResult",
   "type": "object",
   "properties": {
      "name": {
         "default": "unsuccessful_requests",
         "title": "Name",
         "type": "string"
      },
      "method": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "The method used to compute this metric result.",
         "examples": [
            "token_recall"
         ],
         "title": "Method"
      },
      "provider": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "The provider used to compute this metric result.",
         "title": "Provider"
      },
      "value": {
         "anyOf": [
            {
               "type": "number"
            },
            {
               "type": "string"
            },
            {
               "type": "boolean"
            },
            {
               "type": "null"
            }
         ],
         "description": "The metric value.",
         "title": "Value"
      },
      "errors": {
         "anyOf": [
            {
               "items": {
                  "$ref": "#/$defs/Error"
               },
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "The list of error messages",
         "title": "Errors"
      },
      "additional_info": {
         "anyOf": [
            {
               "type": "object"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "The additional information about the metric result.",
         "title": "Additional Info"
      },
      "group": {
         "$ref": "#/$defs/MetricGroup",
         "default": "answer_quality"
      },
      "thresholds": {
         "default": [],
         "description": "The metric thresholds",
         "items": {
            "$ref": "#/$defs/MetricThreshold"
         },
         "title": "Thresholds",
         "type": "array"
      },
      "record_id": {
         "description": "The record identifier.",
         "examples": [
            "record1"
         ],
         "title": "Record Id",
         "type": "string"
      },
      "record_timestamp": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "The record timestamp.",
         "examples": [
            "2025-01-01T00:00:00.000000Z"
         ],
         "title": "Record Timestamp"
      }
   },
   "$defs": {
      "Error": {
         "properties": {
            "code": {
               "description": "The error code",
               "title": "Code",
               "type": "string"
            },
            "message_en": {
               "description": "The error message in English.",
               "title": "Message En",
               "type": "string"
            },
            "parameters": {
               "default": [],
               "description": "The list of parameters to construct the message in a different locale.",
               "items": {},
               "title": "Parameters",
               "type": "array"
            }
         },
         "required": [
            "code",
            "message_en"
         ],
         "title": "Error",
         "type": "object"
      },
      "MetricGroup": {
         "enum": [
            "retrieval_quality",
            "answer_quality",
            "content_safety",
            "performance",
            "usage",
            "tool_call_quality",
            "readability"
         ],
         "title": "MetricGroup",
         "type": "string"
      },
      "MetricThreshold": {
         "description": "The class that defines the threshold for a metric.",
         "properties": {
            "type": {
               "description": "Threshold type. One of 'lower_limit', 'upper_limit'",
               "enum": [
                  "lower_limit",
                  "upper_limit"
               ],
               "title": "Type",
               "type": "string"
            },
            "value": {
               "default": 0,
               "description": "The value of metric threshold",
               "title": "Threshold value",
               "type": "number"
            }
         },
         "required": [
            "type"
         ],
         "title": "MetricThreshold",
         "type": "object"
      }
   },
   "required": [
      "value",
      "record_id"
   ]
}

Config:
  • arbitrary_types_allowed: bool = True

  • use_enum_values: bool = True

Fields:
field group: MetricGroup = MetricGroup.ANSWER_QUALITY
field name: str = 'unsuccessful_requests'