#12763·haystack

JsonSchemaValidator rejects valid empty schemas and ignores empty runtime overrides

Author: Harsh23KashyapCreated Sep 16, 2026Updated Sep 16, 2026

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

python
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