deepset-ai / deepset-ai/haystack
JsonSchemaValidator rejects valid empty schemas and ignores empty runtime overrides
@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(...)raisesValueError.- Passing
json_schema={}torun()does not override a stricter schema from__init__. Theorfallback 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
- Have you had a look at our new FAQ page?
System:
- OS: Linux
- Haystack version:
mainat7476cef96f44ad4d3375e5c8de98ed9730f26d23
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.