Skip to content

feat: add penalize_ambiguous_claims to HallucinationMetric#2704

Open
nuthalapativarun wants to merge 1 commit into
confident-ai:mainfrom
nuthalapativarun:feat/hallucination-penalize-ambiguous-claims
Open

feat: add penalize_ambiguous_claims to HallucinationMetric#2704
nuthalapativarun wants to merge 1 commit into
confident-ai:mainfrom
nuthalapativarun:feat/hallucination-penalize-ambiguous-claims

Conversation

@nuthalapativarun

Copy link
Copy Markdown
Contributor

Summary

Adds a penalize_ambiguous_claims: bool = False parameter to HallucinationMetric, mirroring the same flag on FaithfulnessMetric (PR #2670) and AnswerRelevancyMetric. When set to True, verdicts of "idk" (the LLM cannot determine agreement or contradiction) are counted as hallucinations and surfaced with an (Ambiguous) prefix in the reason.

Changes

  • deepeval/metrics/hallucination/schema.py — added "idk" to HallucinationVerdict.verdict literal
  • deepeval/metrics/hallucination/template.py — updated prompt to allow "idk" for ambiguous verdicts
  • deepeval/metrics/hallucination/hallucination.py — added penalize_ambiguous_claims param; updated _calculate_score, _generate_reason, and _a_generate_reason to handle "idk" verdicts
  • tests/test_metrics/test_hallucination_metric.py — added TestHallucinationPenalizeAmbiguousClaims with three no-API-key unit tests that verify score calculation directly

Test plan

  • python -m pytest tests/test_metrics/test_hallucination_metric.py::TestHallucinationPenalizeAmbiguousClaims -v — all 3 tests pass (no API key required)
  • python -m black --check deepeval/metrics/hallucination/ — passes
  • python -m ruff check deepeval/metrics/hallucination/ — passes

Notes

The change is fully backward compatible: penalize_ambiguous_claims defaults to False, and "idk" verdicts were not possible before this change (old schema only allowed "yes"/"no"). Existing callers see no behavioral change unless they opt in.

@vercel

vercel Bot commented May 29, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

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.

1 participant