Skip to content

fix(dspy): ignore empty normalized answers in passage matching - #10973

Open
WeiLiuu wants to merge 1 commit into
stanfordnlp:mainfrom
WeiLiuu:fix/ignore-empty-passage-answers
Open

WeiLiuu wants to merge 1 commit into
stanfordnlp:mainfrom
WeiLiuu:fix/ignore-empty-passage-answers

Conversation

@WeiLiuu

@WeiLiuu WeiLiuu commented Nov 26, 2026 •

Copy link
Copy Markdown

answer_passage_match returns True for any passage when one of the reference answers normalizes to nothing (empty string, "the", "A", punctuation only).

import dspy
from dspy.evaluate.metrics import answer_passage_match

pred = dspy.Prediction(context=["Tokyo is in Japan."])
answer_passage_match(dspy.Example(answer=["Paris", "the"]), pred)  # True, should be False
answer_passage_match(dspy.Example(answer=["A"]), pred)             # True, should be False

has_answer in dsp/utils/dpr.py compares the empty token list with a zero-length slice of the passage, and that always matches. This PR skips references with zero tokens. If every reference is empty the result is False. A real reference after an empty one still matches.

Added a parametrized test in tests/evaluate/test_metrics.py (empty string, articles, punctuation, all empty, empty followed by a real match). tests/evaluate passes locally with --extra, 61 passed.

This is not covered by #10783 (empty answer list) or #10913 (non-string values). The example above still returns True on the #10783 branch.

One thing I ran into: on a fresh checkout the ty pre-commit hook fails before it starts, because uv.lock has dspy 3.4.1 and pyproject.toml says 3.5.0. Not related to this change.

AI use: Claude and Codex did most of the work, the patch and the test, and drafted this text.

has_answer treated a reference that normalizes to zero tokens (empty string, an article, punctuation only) as a match for any passage. Skip such references before the token search.
@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

Fixes false passage matches caused by answers that normalize to no tokens.

  • Passage matching skips answers that normalize to no tokens.

No actionable issues found. Review was based on source inspection; tests were not run.

Reviews (2) · Last reviewed commit: "fix(dspy): ignore empty normalized answe..." · Reviewed by Greptile

This branch has not been deployed

No deployments
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