Skip to content

[BUG] Reranker crashes with KeyError if a document is missing the text_key #816

Description

@suhaniiz

Description of the Bug

The list comprehension used to prepare query-document pairs (pairs = [(query, doc[text_key]) for doc in documents]) assumes that every dictionary passed inside the documents list contains the target text_key. If an unvalidated or poorly structured payload passes through, the code throws an unhandled KeyError and crashes the entire pipeline request.

Steps to Reproduce

Missing the default "text" key entirely

malformed_docs = [{"source": "system_logs"}]
reranker.rerank("query", malformed_docs)

Expected Behavior

The code should handle missing keys gracefully, either by skipping the invalid dictionary, logging a warning, or using a safe fallback like doc.get(text_key, "") to prevent the application from crashing.

Screenshots / Logs

No response

Environment

=

GSSoC '26

  • Yes, I am participating in GirlScript Summer of Code and would like to fix this.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggssocGirlScript Summer of Code 2026 issue/PR

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions