langgenius/dify · error · ValidationError

Parameter '${key}' exceeds maximum size of ${MAX_LIST_LENGTH

Error message

Parameter '${key}' exceeds maximum size of ${MAX_LIST_LENGTH} items

What it means

Thrown by validateParams() in validation.ts:101 as a ValidationError. Any array-valued query or body param exceeding 1000 items (MAX_LIST_LENGTH) is rejected in the HTTP layer. The key name is interpolated.

Source

Thrown at sdks/nodejs-client/src/client/validation.ts:101

export function validateParams(params: Record<string, unknown>): void {
  Object.entries(params).forEach(([key, value]) => {
    if (value === undefined || value === null) {
      return
    }

    // Only check max length for strings; empty strings are allowed for optional params
    // Required fields are validated at method level via ensureNonEmptyString
    if (typeof value === 'string') {
      if (value.length > MAX_STRING_LENGTH) {
        throw new ValidationError(
          `Parameter '${key}' exceeds maximum length of ${MAX_STRING_LENGTH} characters`,
        )
      }
    } else if (Array.isArray(value)) {
      if (value.length > MAX_LIST_LENGTH) {
        throw new ValidationError(
          `Parameter '${key}' exceeds maximum size of ${MAX_LIST_LENGTH} items`,
        )
      }
    } else if (isRecord(value)) {
      if (Object.keys(value).length > MAX_DICT_LENGTH) {
        throw new ValidationError(
          `Parameter '${key}' exceeds maximum size of ${MAX_DICT_LENGTH} items`,
        )
      }
    }

    if (key === 'user' && typeof value !== 'string') {
      throw new ValidationError(`Parameter '${key}' must be a string`)
    }
    if ((key === 'page' || key === 'limit' || key === 'page_size') && !Number.isInteger(value)) {
      throw new ValidationError(`Parameter '${key}' must be an integer`)
    }
    if (key === 'files' && !Array.isArray(value) && typeof value !== 'object') {
      throw new ValidationError(`Parameter '${key}' must be a list or dict`)

View on GitHub (pinned to ef8544b173)

Solutions

  1. Chunk the array and make multiple requests: for (const c of chunk(arr, 1000)) await client....(c).
  2. Move the bulk payload to a dedicated batch endpoint or upload flow if available.
  3. Validate size before the call and surface a domain-specific error.

Example fix

// before
await client.chat('fx', { query, user, inputs: { ids: allIds } }) // >1000

// after
for (const chunk of chunkArray(allIds, 1000)) {
  await client.chat('fx', { query, user, inputs: { ids: chunk } })
}
Defensive patterns

Strategy: validation

Validate before calling

const MAX_LIST_LENGTH = 1000
function assertBoundedArrays(params: Record<string, unknown>) {
  for (const [k, v] of Object.entries(params)) {
    if (Array.isArray(v) && v.length > MAX_LIST_LENGTH) {
      throw new Error(`Parameter '${k}' exceeds ${MAX_LIST_LENGTH} items; chunk it`)
    }
  }
}

Type guard

function isBoundedArrayParams(params: Record<string, unknown>, max = 1000): boolean {
  return Object.values(params).every((v) => !Array.isArray(v) || v.length <= max)
}

Try / catch

try {
  await client.chat('fx', payload)
} catch (err) {
  if (err instanceof Error && /exceeds maximum size/.test(err.message) && /items/.test(err.message)) {
    // chunk the offending array and loop
  } else throw err
}

Prevention

When it happens

Trigger: Any request carrying an array field with > 1000 elements in query or record body — e.g. lists of ids, batched inputs, tag arrays. Triggered from client.ts request() before the HTTP call.

Common situations: Bulk operations sending an unbounded list; aggregating many selection items without chunking; passing a corpus slice in one shot.

Related errors


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/3a94974ee21fc8a0. Report an issue: GitHub.