Skip to content

fix: skip invalid numeric indices in LLMRanker responses - #13576

Merged
anakin87 merged 5 commits into
deepset-ai:mainfrom
solitarybear:fix/llm-ranker-response-indices
Nov 6, 2026
Merged

anakin87 merged 5 commits into
deepset-ai:mainfrom
solitarybear:fix/llm-ranker-response-indices

Conversation

@solitarybear

Copy link
Copy Markdown
Contributor

Related Issues

No existing issue identified. Independently reproduced on main at 0de7bcdc0f0683b8a321197d635c5c39b6e804d0; the affected source is unchanged at the updated base 63dcc3c4ee.

Proposed Changes:

LLMRanker converts model-response indices using int(). Given {"documents": [{"index": 1.9}, {"index": 2}]} and top_k=1, it therefore returns document 1 instead of skipping the invalid entry and returning document 2. Boolean indices can also select the wrong document, while 1e400 raises an uncaught OverflowError, even with raise_on_failure=False.

Skip boolean, fractional, and non-finite indices before conversion in the shared response parser. Preserve integer strings and integer-valued floats. If a nonempty ranking has no valid indices, use the existing fallback/error policy, including returning all fallback documents regardless of top_k.

Add regression tests for both execution paths and both failure policies, update the component documentation, and add a release note.

How did you test it?

  • Before the fix: 24 regression cases failed; 2 compatibility cases passed.
  • After the fix: all 26 focused cases passed.
  • After updating the base: the complete ranker unit-test module passed, 74 passed, 3 integration tests deselected.
  • Focused mypy, Ruff lint/format checks, applicable pre-commit hooks on the four changed files, and git diff --check passed.

The tests use MockChatGenerator and require no GPU, model download, or API key. I ran the checks locally with Python 3.12.3. Full-repository tests, repository-wide type checking, live-provider integration tests, and the documentation-site build were not run.

Notes for the reviewer

This validates model-produced JSON in a parser that already skips unusable indices. It preserves existing valid input handling, including "2" and 2.0. The tests inject malformed responses deterministically; they do not measure their frequency with a live provider.

AI tools were used to help draft and organize this contribution. I reviewed the final changes and ran the local checks; I remain responsible for their correctness.

Checklist

  • I have read the contributors guidelines and code of conduct.
  • Related issue update: not applicable; no existing issue identified.
  • Unit tests and docstrings are updated.
  • The proposed title uses the conventional fix: prefix.
  • The changed behavior is documented.
  • A release note is included.
  • Applicable pre-commit hooks passed locally.
  • I have personally reviewed and understood all four changed files.

@vercel

vercel Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

@solitarybear is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Nov 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@solitarybear
solitarybear marked this pull request as ready for review November 5, 2026 15:49
@solitarybear
solitarybear requested a review from a team as a code owner November 5, 2026 15:49
@solitarybear
solitarybear requested review from anakin87 and removed request for a team November 5, 2026 15:49
@github-actions github-actions Bot added the type:documentation Improvements on the docs label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/rankers
  llm_ranker.py 413
  haystack/core/pipeline
  pipeline.py
Project Total  

This report was generated by python-coverage-comment-action

@anakin87 anakin87 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

I took the opportunity to simplify the code and restructure tests for this component

@anakin87
anakin87 enabled auto-merge (squash) November 6, 2026 09:49
@anakin87
anakin87 merged commit 44a2e81 into deepset-ai:main Nov 6, 2026
22 of 23 checks passed
@solitarybear

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for taking the time to simplify the code and restructure the tests. Much appreciated!

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

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants