Skip to content

fix: ignore non-list QueryExpander replies#11630

Merged
anakin87 merged 2 commits into
deepset-ai:mainfrom
oyinkanchekwas:fix-query-expander-non-list-queries
Jun 15, 2026
Merged

fix: ignore non-list QueryExpander replies#11630
anakin87 merged 2 commits into
deepset-ai:mainfrom
oyinkanchekwas:fix-query-expander-non-list-queries

Conversation

@oyinkanchekwas

@oyinkanchekwas oyinkanchekwas commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

What changed

QueryExpander now checks that queries is a list before iterating over it.

Before this, a response like {"queries": "search term"} was treated as an iterable, so it produced single-character queries.

Testing

  • hatch run test:unit test/components/query/test_query_expander.py -q
  • hatch run fmt-check haystack/components/query/query_expander.py test/components/query/test_query_expander.py
  • hatch run test:types haystack/components/query/query_expander.py test/components/query/test_query_expander.py

@oyinkanchekwas oyinkanchekwas requested a review from a team as a code owner June 14, 2026 23:46
@oyinkanchekwas oyinkanchekwas requested review from anakin87 and Copilot and removed request for a team June 14, 2026 23:46
@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Improves QueryExpander robustness when parsing LLM JSON by rejecting malformed "queries" fields that aren’t lists, preventing accidental iteration over strings (character-by-character) and similar invalid structures.

Changes:

  • Added a type check in _parse_expanded_queries to return [] (and warn) when "queries" is not a list.
  • Added parametrized test coverage for several non-list "queries" values.
  • Added release note documenting the behavior change.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test/components/query/test_query_expander.py Adds parametrized tests ensuring non-list "queries" values are rejected and logged.
haystack/components/query/query_expander.py Adds a guard + warning to prevent iterating invalid "queries" types (e.g., strings).
releasenotes/notes/query-expander-reject-non-list-queries-6f3b1c2d8e9a4b70.yaml Documents the fix in release notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +268 to +273
if not isinstance(parsed["queries"], list):
logger.warning(
"Expected 'queries' to be a list but got {type}. Returning no expanded queries.",
type=type(parsed["queries"]).__name__,
)
return []
@CLAassistant

CLAassistant commented Jun 14, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added the type:documentation Improvements on the docs label Jun 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/query
  query_expander.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.

Looks good!

Comment thread releasenotes/notes/query-expander-reject-non-list-queries-6f3b1c2d8e9a4b70.yaml Outdated
@anakin87 anakin87 enabled auto-merge (squash) June 15, 2026 08:03
@anakin87 anakin87 merged commit d136813 into deepset-ai:main Jun 15, 2026
26 of 34 checks passed
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.

4 participants