Skip to content

Commit 65612ca

Browse files
m7md7sienCopilot
andauthored
Implement Input Validation for Agentic Evaluators (#44618)
* Implement Input Validation for Agentic Evaluators * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 5ec642f commit 65612ca

28 files changed

+1409
-216
lines changed

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_evaluators/_coherence/_coherence.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from typing_extensions import overload, override
88

99
from azure.ai.evaluation._evaluators._common import PromptyEvaluatorBase
10+
from azure.ai.evaluation._evaluators._common._validators import ConversationValidator, ValidatorInterface
11+
from azure.ai.evaluation._exceptions import ErrorTarget
1012
from azure.ai.evaluation._model_configurations import Conversation
1113

1214

@@ -67,6 +69,8 @@ class CoherenceEvaluator(PromptyEvaluatorBase[Union[str, float]]):
6769
_PROMPTY_FILE = "coherence.prompty"
6870
_RESULT_KEY = "coherence"
6971

72+
_validator: ValidatorInterface
73+
7074
id = "azureai://built-in/evaluators/coherence"
7175
"""Evaluator identifier, experimental and to be used only with evaluation in cloud."""
7276

@@ -76,6 +80,10 @@ def __init__(self, model_config, *, threshold=3, credential=None, **kwargs):
7680
prompty_path = os.path.join(current_dir, self._PROMPTY_FILE)
7781
self._threshold = threshold
7882
self._higher_is_better = True
83+
84+
# Initialize input validator
85+
self._validator = ConversationValidator(error_target=ErrorTarget.COHERENCE_EVALUATOR)
86+
7987
super().__init__(
8088
model_config=model_config,
8189
prompty_file=prompty_path,
@@ -141,3 +149,17 @@ def __call__( # pylint: disable=docstring-missing-param
141149
:rtype: Union[Dict[str, float], Dict[str, Union[float, Dict[str, List[float]]]]]
142150
"""
143151
return super().__call__(*args, **kwargs)
152+
153+
@override
154+
async def _real_call(self, **kwargs):
155+
"""The asynchronous call where real end-to-end evaluation logic is performed.
156+
157+
:keyword kwargs: The inputs to evaluate.
158+
:type kwargs: Dict
159+
:return: The evaluation result.
160+
:rtype: Union[DoEvalResult[T_EvalValue], AggregateResult[T_EvalValue]]
161+
"""
162+
# Validate input before processing
163+
self._validator.validate_eval_input(kwargs)
164+
165+
return await super()._real_call(**kwargs)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
"""Validators package init."""
5+
6+
from ._validator_interface import ValidatorInterface
7+
from ._conversation_validator import ConversationValidator
8+
from ._tool_definitions_validator import ToolDefinitionsValidator
9+
from ._tool_calls_validator import ToolCallsValidator
10+
from ._task_navigation_efficiency_validator import TaskNavigationEfficiencyValidator
11+
12+
__all__ = [
13+
"ValidatorInterface",
14+
"ConversationValidator",
15+
"ToolDefinitionsValidator",
16+
"ToolCallsValidator",
17+
"TaskNavigationEfficiencyValidator",
18+
]

0 commit comments

Comments
 (0)