Skip to content

fix: validate top-level JSON arrays in JsonSchemaValidator - #13072

Closed
Harbor404 wants to merge 1 commit into
deepset-ai:mainfrom
Harbor404:fix/jsonschema-array-validation
Closed

Harbor404 wants to merge 1 commit into
deepset-ai:mainfrom
Harbor404:fix/jsonschema-array-validation

Conversation

@Harbor404

Copy link
Copy Markdown

Related Issues

Proposed Changes

JsonSchemaValidator treated every top-level JSON array as a list of OpenAI function-calling tool calls. As a result, [1, 2] was validated element-by-element against an array schema, while [] skipped validation entirely and could bypass minItems.

This change validates the whole payload once for regular schemas. Per-message validation now runs only for OpenAI function-calling schemas or non-empty function-calling message lists, preserving the existing tool-call behavior.

  • Updated JsonSchemaValidator.run() to choose whole-payload or per-tool-call validation based on the schema and payload.
  • Added a helper to detect function-calling message lists.
  • Added regression tests for a valid integer array and an empty array that violates minItems.
  • Added a release note.

How did you test it?

  • hatch run test:unit test/components/validators/test_json_schema.py -q --no-cov --tb=short
    • 22 passed
  • hatch run test:types haystack/components/validators/json_schema.py
    • Success: no issues found in 1 source file
  • hatch run fmt-check haystack/components/validators/json_schema.py test/components/validators/test_json_schema.py
    • passed

Before the fix, the two new tests failed as expected: [1, 2] produced validation_error, and [] was accepted.

Notes for the reviewer

Function-calling payloads may use either a full OpenAI function-calling schema or a schema that describes one function-call object while the message contains a list. Both existing paths are preserved by detecting non-empty function-calling message lists instead of always iterating over arrays.

This PR is a draft because the repository currently allows only one non-draft PR per community contributor, and #13059 is already open. It can be marked ready for review once that PR is merged or closed.

This PR was fully generated with an AI assistant. I have reviewed the changes and run the relevant tests.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I used a conventional commit type for the PR title.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run focused tests, formatting, and type checks.

Validate the complete payload once for regular schemas and only validate individual tool calls when the payload is an OpenAI function-calling list.
@vercel

vercel Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

@Harbor404 is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Hi @Harbor404, thanks for your interest in contributing to Haystack! 🙏

⛔ First-time contributors can have at most 1 open pull request in this repository until it has been approved, so this PR was closed automatically. Your open pull request #13059 is unaffected. Once it has been approved by a maintainer, you are welcome to open more PRs. Feel free to reopen this one at that point.

See the contributing guidelines for details.

This is an automated message to help us keep the review queue healthy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JsonSchemaValidator rejects valid arrays and skips constraints on empty arrays

1 participant