Skip to content

JSON example import skips depth validation for array objects #43782

Closed

Description

@dhairyajangir

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

Current main at 1a817b99720bd709d82a0084d73a7b44548cfbf8 (web package version 1.17.1).

Cloud or Self Hosted

Self Hosted (Source). Reproduced in the repository's React component/unit test runner; no deployed instance is claimed.

Steps to reproduce

In the LLM node's structured-output JSON schema configuration, import this JSON example:

{
  "rows": [
    {
      "child": {
        "child": {
          "child": {
            "child": {
              "child": {
                "child": {
                  "child": {
                    "child": {
                      "value": "leaf"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  ]
}

The imported example produces a schema with depth 11: the root object, the array, and nine nested item objects. JSON_SCHEMA_MAX_DEPTH is 10.

At the production-helper boundary on current main:

checkJsonDepth(example) // 1
checkJsonSchemaDepth(jsonToSchema(example)) // 11

A regression test that renders the real JsonImporter with the real checkJsonDepth, enters this example, and clicks Submit confirms that the importer calls onSubmit and closes instead of showing the depth error. The schema configuration's raw JSON-schema view uses checkJsonSchemaDepth when switching from that view or saving, so the same generated schema fails its depth validation there.

✔️ Expected Behavior

Import should enforce the same existing maximum depth as the generated schema. Reject the depth-11 example with Schema exceeds maximum depth of 10.; still accept an array-of-object example whose generated schema is exactly depth 10. Empty arrays, primitive arrays, and first-item schema inference should keep their current behavior.

❌ Actual Behavior

checkJsonDepth returns zero for every array before reaching its array branch, so objects inside arrays are skipped entirely. Imports can therefore accept examples whose generated schemas exceed the editor's existing limit.

AI assistance: Codex helped reproduce and investigate this report. Evidence is from the repository test runner and source-path inspection, not a full browser deployment.

Activity

  1. dosubot commented on Oct 9, 2026

    @dosubot

    Hi @dhairyajangir! I'm Dosu and I'm helping the Dify team.

    Your diagnosis matches the code. The first line of checkJsonDepth returns 0 for anything that isn't 'object', arrays included, so the 'array' branch below it never runs [1]. checkJsonSchemaDepth counts an array of objects as the item depth plus 1 [2].

    Relaxing the guard alone would probably leave the count one level short. The existing array branch returns checkJsonDepth(json[0]) with no + 1, so your depth-11 example would be counted as 10 and still be accepted. To match the schema helper, the array branch should return checkJsonDepth(json[0]) + 1 when the first item is an object. Empty and primitive arrays would still fall through to 0, which keeps their current behavior.

    I haven't run this, so your regression test is the right check: include a depth-10 example that must pass and the depth-11 example that must be rejected. I also haven't checked how jsonToSchema handles a top-level array example, so cover that case in the test too.

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about dify

  2. Stream29 commented on Oct 12, 2026

    @Stream29
    Contributor

    On ed7592fe21, a React importer test accepts the reported depth-11 schema. With #43793, it rejects that input and still accepts depth-10.

    Component fixture — editor input adapter:

    Main:
    Main importer component

    With #43793:
    Candidate importer component

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    review: highghfind author score; see https://ghfind.com

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions