Skip to content

fix: raise a clear error when JsonSchemaValidator gets no messages - #13078

Merged
anakin87 merged 1 commit into
deepset-ai:mainfrom
ShousenZHANG:fix/json-schema-validator-empty-messages
Oct 2, 2026
Merged

anakin87 merged 1 commit into
deepset-ai:mainfrom
ShousenZHANG:fix/json-schema-validator-empty-messages

Conversation

@ShousenZHANG

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

JsonSchemaValidator.run() reads messages[-1] before checking anything, so an empty messages list raised IndexError: list index out of range from inside the component (json_schema.py:135).

It now raises ValueError("The provided list of messages is empty.") first. ValueError is what run() already raises for its other invalid inputs (a last message with no text, no schema at all), and the docstring's :raises ValueError: now lists the empty case too. Non-empty inputs take exactly the same path as before.

How did you test it?

  • New test_run_raises_clear_error_for_empty_messages. Before the fix it fails with IndexError: list index out of range at json_schema.py:135; after it, it passes.
  • test/components/validators/ -> 21 passed. Full unit suite -> 6629 passed; the only failure is the spam.csv case of test_from_file_path_guess_mime_type, which fails identically on a clean main checkout on Windows (local mime registry) and is untouched here.
  • hatch run test:types -> no issues in 551 files. hatch run fmt-check -> clean. reno lint -> clean.

Notes for the reviewer

Release note added under fixes, since the exception type a caller sees for an empty list changes from IndexError to ValueError.


This PR was written with AI assistance.

JsonSchemaValidator.run() read messages[-1] unconditionally, so an empty
list leaked an IndexError. Raise a ValueError that names the problem
instead, and document it under :raises:.

Same approach as deepset-ai#12766, which was approved but closed without merging.

Fixes deepset-ai#12765.
@ShousenZHANG
ShousenZHANG requested a review from a team as a code owner October 2, 2026 11:09
@ShousenZHANG
ShousenZHANG requested review from anakin87 and a balanced review from Copilot and removed request for a team October 2, 2026 11:09
@vercel

vercel Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

@ShousenZHANG 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/validators
  json_schema.py 140
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.

👍

@anakin87
anakin87 merged commit 643d1b9 into deepset-ai:main Oct 2, 2026
27 of 28 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.

JsonSchemaValidator raises IndexError for an empty message list

3 participants