Fix inverse metric adjustment to skip string labels from code-based evaluators#46663
Merged
imatiach-msft merged 1 commit intoAzure:mainfrom May 1, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes inverse-metric adjustment logic so evaluators that emit string pass/fail labels (not booleans) don’t get their label incorrectly overwritten when is_inverse=True, addressing incorrect label="pass" reporting for deflection-rate-like metrics.
Changes:
- Extend
_adjust_for_inverse_metricto recognize string"pass"/"fail"labels (case/whitespace-insensitive). - Update
_adjust_for_inverse_metricdocstring to document string-label behavior and examples.
5a574e6 to
740e8c2
Compare
…valuators
Code-based evaluators like deflection_rate return string pass/fail labels
that already reflect direction-aware semantics. The inverse metric
adjustment was incorrectly treating these strings as boolean False
(since isinstance('fail', bool) is False), flipping 'fail' to 'pass'.
Fix: skip _adjust_for_inverse_metric entirely when the label is a string,
since string labels mean the evaluator already computed the correct
direction-aware pass/fail. Boolean labels (from safety evaluators) still
get inverted as before.
Fixes Bug #5240742
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
740e8c2 to
fe204e7
Compare
qusongms
approved these changes
May 1, 2026
YoYoJa
approved these changes
May 1, 2026
Contributor
YoYoJa
left a comment
There was a problem hiding this comment.
It might be better to have consistent type of value for evaluator in the future?
imatiach-msft
added a commit
that referenced
this pull request
May 6, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
imatiach-msft
added a commit
that referenced
this pull request
May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix inverse metric adjustment to skip string labels from code-based evaluators
Bug
Bug #5240742 - deflection_rate evaluator shows incorrect pass/fail labels in AppInsights (score=1.0 labeled "pass" instead of "fail").
Root Cause
_create_result_object()calls_adjust_for_inverse_metric(label)for all inverse (decrease+boolean) metrics. Code-based evaluators likedeflection_ratereturn string labels ("pass"/"fail") that already reflect direction-aware semantics. But_adjust_for_inverse_metriconly handlesbool- it treats any non-bool (including strings) asFalse, mapping everything to "pass".Fix
Skip
_adjust_for_inverse_metricentirely when the label is already a string, since string labels mean the evaluator already computed the correct direction-aware pass/fail.Before (buggy):
After (fix):
Boolean labels (from safety evaluators like
indirect_attack,code_vulnerability) continue to be inverted as before.Tests
TestAdjustForInverseMetric(3 tests): boolean True/False and None handlingTestIsInverseMetric(4 tests): hardcoded, configured, non-inverse, deflection_rateTestCreateResultObjectInverseMetric(4 tests): integration tests verifying string labels preserved, boolean labels adjusted, non-inverse unmodifiedAffected Evaluators
Only
deflection_rateis affected - it is the only evaluator that is both code-based (string labels) AND decrease+boolean (triggers inverse path). All other inverse metrics return boolean labels and are unaffected.