deepset-ai / deepset-ai/haystack

JsonSchemaValidator raises IndexError for an empty message list

Open
#12,765 0 comments 0 reactions 1 assignee View on GitHub

@davidsbatista is already working on this.

Since Sep 16, 2026.

Dominant language
Python
Stars
26.6k
Forks
3.2k
Avg merge
1d 3h
Merged PRs (30d)
194

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.