deepset-ai / deepset-ai/haystack

JsonSchemaValidator rejects valid empty schemas and ignores empty runtime overrides

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

@julian-risch 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 rejects an empty JSON Schema ({}). Empty schemas are valid under the JSON Schema specification and match every JSON value.

There are two affected paths:

  • JsonSchemaValidator(json_schema={}).run(...) raises ValueError.
  • Passing json_schema={} to run() does not override a stricter schema from __init__. The or fallback silently uses the init schema instead.

Error message

ValueError: Provide a JSON schema for validation either in the run method or in the component init.

Expected behavior

The validator should pass valid JSON when its effective schema is {}. A schema supplied to run() should take precedence over the init schema, including when it is empty.

To Reproduce

from haystack.components.validators import JsonSchemaValidator
from haystack.dataclasses import ChatMessage

message = ChatMessage.from_assistant("{}")

# An empty schema is rejected.
JsonSchemaValidator(json_schema={}).run([message])

# An empty runtime schema is replaced by the stricter init schema.
validator = JsonSchemaValidator(json_schema={"type": "object", "required": ["name"]})
print(validator.run([message], json_schema={}).keys())
# dict_keys(['validation_error']) instead of dict_keys(['validated'])

Additional context

The fallback uses json_schema = json_schema or self.json_schema, and the missing-schema guard uses if not json_schema. Both treat a valid empty dictionary as if no schema was supplied.

FAQ Check

System:

  • OS: Linux
  • Haystack version: main at 7476cef96f44ad4d3375e5c8de98ed9730f26d23

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.