haystack icon indicating copy to clipboard operation
haystack copied to clipboard

JsonSchemaValidator raises IndexError for an empty message list

Open Harsh23Kashyap opened this issue 2 months ago • 1 comments

Describe the bug

JsonSchemaValidator.run([]) raises a bare IndexError while trying to read messages[-1]. The component accepts a list of messages and documents validation errors, but it does not validate that the list contains a message before indexing it.

Error message

IndexError: list index out of range

Expected behavior

An empty message list should raise a descriptive ValueError, consistent with the component's existing validation errors for a missing schema or a message with no text content.

To Reproduce

from haystack.components.validators import JsonSchemaValidator

validator = JsonSchemaValidator(json_schema={"type": "object"})
validator.run([])

Additional context

The failure happens before schema validation at last_message = messages[-1]. A guard at the start of run() can turn the implementation detail into an actionable input error.

FAQ Check

System:

  • OS: Linux
  • Haystack version: main at 44246f850714529353513a2a41e691bb1cf78b7e

Harsh23Kashyap avatar Sep 16 '26 03:09 Harsh23Kashyap

Picking this up. #12766 had the fix and was approved, but was closed after the lint failure wasn't addressed, and #12807 / #12881 were closed by the CLA gate, so nothing is open for it now. I'll open a PR with the same approach — a ValueError for an empty messages list before messages[-1] is read — plus a regression test and a release note.

ShousenZHANG avatar Oct 02 '26 03:10 ShousenZHANG