{"record":{"id":"9a39f19c5395c13a","repo":"langgenius/dify","slug":"parameter-key-must-be-a-string","errorCode":null,"errorMessage":"Parameter '${key}' must be a string","messagePattern":"Parameter '(.+?)' must be a string","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"sdks/nodejs-client/src/client/validation.ts","lineNumber":113,"sourceCode":"          `Parameter '${key}' exceeds maximum length of ${MAX_STRING_LENGTH} characters`,\n        )\n      }\n    } else if (Array.isArray(value)) {\n      if (value.length > MAX_LIST_LENGTH) {\n        throw new ValidationError(\n          `Parameter '${key}' exceeds maximum size of ${MAX_LIST_LENGTH} items`,\n        )\n      }\n    } else if (isRecord(value)) {\n      if (Object.keys(value).length > MAX_DICT_LENGTH) {\n        throw new ValidationError(\n          `Parameter '${key}' exceeds maximum size of ${MAX_DICT_LENGTH} items`,\n        )\n      }\n    }\n\n    if (key === 'user' && typeof value !== 'string') {\n      throw new ValidationError(`Parameter '${key}' must be a string`)\n    }\n    if ((key === 'page' || key === 'limit' || key === 'page_size') && !Number.isInteger(value)) {\n      throw new ValidationError(`Parameter '${key}' must be an integer`)\n    }\n    if (key === 'files' && !Array.isArray(value) && typeof value !== 'object') {\n      throw new ValidationError(`Parameter '${key}' must be a list or dict`)\n    }\n    if (key === 'rating' && value !== 'like' && value !== 'dislike') {\n      throw new ValidationError(`Parameter '${key}' must be 'like' or 'dislike'`)\n    }\n  })\n}\n","sourceCodeStart":95,"sourceCodeEnd":126,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/sdks/nodejs-client/src/client/validation.ts#L95-L126","documentation":"Thrown by validateParams() in validation.ts:113 as a ValidationError specifically for the 'user' key. The HTTP layer requires the user identifier (used for audit/end-user attribution on the Dify backend) to be a string. Any non-string user value in query or body fails this key-specific check after the generic size checks.","triggerScenarios":"Calling any endpoint with { user: 12345 } (numeric id), { user: { id: 1 } } (object), or { user: true } in the query/body. The check at validation.ts:112 fires because key === 'user' && typeof value !== 'string'.","commonSituations":"Internal user ids stored as numbers in the DB and passed through without coercion; passing a user object instead of its id field; boolean flags accidentally assigned to user.","solutions":["Coerce the user id to string at the boundary: const user = String(internalId).","Pull the identifier field from the user object before passing: session.user.id.","Type the user param as string throughout your call layer so non-strings fail at compile time."],"exampleFix":"// before\nawait client.chat('fx', { query, user: session.userId }) // session.userId is number 42\n\n// after\nawait client.chat('fx', { query, user: String(session.userId) })","handlingStrategy":"type-guard","validationCode":"function assertUserString(params: Record<string, unknown>) {\n  if ('user' in params && typeof params.user !== 'string') {\n    throw new Error(`Parameter 'user' must be a string`)\n  }\n}","typeGuard":"function isUserString(params: Record<string, unknown>): params is { user: string } {\n  return typeof params.user === 'string'\n}","tryCatchPattern":"try {\n  await client.chat('fx', payload)\n} catch (err) {\n  if (err instanceof Error && /Parameter 'user' must be a string/.test(err.message)) {\n    await client.chat('fx', { ...payload, user: String(payload.user) })\n  } else throw err\n}","preventionTips":["Always coerce internal numeric user ids to strings before SDK calls.","Type the user param as string throughout your request DTOs.","Pull user from session.user.id, never the whole session object."],"tags":["validation","user","type-coercion","http","guard"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}