Skip to content

feat: optionally penalize ambiguous answer relevancy verdicts - #3006

Open
Yashaswini1233 wants to merge 2 commits into
confident-ai:mainfrom
Yashaswini1233:feat/answer-relevancy-ambiguous-statements
Open

feat: optionally penalize ambiguous answer relevancy verdicts#3006
Yashaswini1233 wants to merge 2 commits into
confident-ai:mainfrom
Yashaswini1233:feat/answer-relevancy-ambiguous-statements

Conversation

@Yashaswini1233

Copy link
Copy Markdown

Summary

  • Adds a penalize_ambiguous_statements option to AnswerRelevancyMetric.
  • When enabled, idk verdicts are treated as irrelevant when calculating the answer relevancy score.
  • Preserves the existing behavior by default with penalize_ambiguous_statements=False.
  • Includes ambiguous verdicts in the generated reason when penalization is enabled.

Motivation

Currently, AnswerRelevancyMetric counts every verdict other than no as relevant, which means an idk verdict contributes positively to the score.

This change provides an opt-in stricter scoring mode for users who want ambiguous statements to be penalized while remaining backward compatible with the existing behavior.

Addresses #1137.

Testing

Added focused tests covering:

  • Existing/default idk scoring behavior
  • Penalized idk scoring
  • Ambiguous-only verdicts
  • Strict mode behavior
  • Existing empty-output regression behavior

Validation performed locally:

  • 8 targeted tests passed
  • black --check passed
  • Python compilation passed
  • git diff --check passed

@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown

@Yashaswini1233 is attempting to deploy a commit to the Confident AI Team on Vercel.

A member of the Team first needs to authorize it.

@Yashaswini1233

Copy link
Copy Markdown
Author

Note on CI: the lint check is currently failing on deepeval/test_case/llm_test_case.py, which is unchanged by this PR and identical to the version on upstream/main. I also reproduced the check locally with Black 25.12.0. The changes introduced in this PR are Black-formatted and the 8 targeted Answer Relevancy tests pass locally.

@Yashaswini1233 Yashaswini1233 changed the title feat: optionally penalize ambiguous answer relevancy verdictsfeat: optionally penalize ambiguous answer relevancy verdicts feat: optionally penalize ambiguous answer relevancy verdicts Aug 5, 2026
+ [ele for ele in actual_output if isinstance(ele, MLLMImage)],
)

def _calculate_score(self):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate method definition.
This PR adds a new _calculate_score method at line 313 that only contains the empty-verdicts guard (return 1), but the original full _calculate_score is still defined below it at ~line 325. In Python, when a method is defined twice in the same class body, the second definition silently overrides the first — so this new one is unreachable dead code and will never execute.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. I removed the duplicate _calculate_score() definition and retained the empty-verdict guard in the single complete method. All 8 targeted tests pass locally.

@Yashaswini1233

Copy link
Copy Markdown
Author

The duplicate _calculate_score() definition has been removed, leaving one complete scoring method with the empty-verdict guard intact. All 8 targeted tests pass locally. The remaining Black CI failure is on .scripts/release.py, which is unrelated to this PR. The Vercel check requires repository authorization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants