JsonSchemaValidator raises IndexError for an empty message list
Author: Harsh23KashyapCreated Sep 16, 2026Updated Sep 16, 2026
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 rangeExpected 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
- Have you had a look at our new FAQ page?
System:
- OS: Linux
- Haystack version:
mainat44246f850714529353513a2a41e691bb1cf78b7e
Source: deepset-ai/haystack