{"record":{"id":"a0c50610b285220f","repo":"langgenius/dify","slug":"name-exceeds-maximum-length-of-max-string-len","errorCode":null,"errorMessage":"${name} exceeds maximum length of ${MAX_STRING_LENGTH} characters","messagePattern":"(.+?) exceeds maximum length of (.+?) characters","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"sdks/nodejs-client/src/client/validation.ts","lineNumber":13,"sourceCode":"import { ValidationError } from '../errors/dify-error'\nimport { isRecord } from '../internal/type-guards'\n\nconst MAX_STRING_LENGTH = 10000\nconst MAX_LIST_LENGTH = 1000\nconst MAX_DICT_LENGTH = 100\n\nexport function ensureNonEmptyString(value: unknown, name: string): asserts value is string {\n  if (typeof value !== 'string' || value.trim().length === 0) {\n    throw new ValidationError(`${name} must be a non-empty string`)\n  }\n  if (value.length > MAX_STRING_LENGTH) {\n    throw new ValidationError(`${name} exceeds maximum length of ${MAX_STRING_LENGTH} characters`)\n  }\n}\n\n/**\n * Validates optional string fields that must be non-empty when provided.\n * Use this for fields like `name` that are optional but should not be empty strings.\n *\n * For filter parameters that accept empty strings (e.g., `keyword: \"\"`),\n * use `validateParams` which allows empty strings for optional params.\n */\nexport function ensureOptionalString(value: unknown, name: string): void {\n  if (value === undefined || value === null) {\n    return\n  }\n  if (typeof value !== 'string' || value.trim().length === 0) {\n    throw new ValidationError(`${name} must be a non-empty string when set`)\n  }\n  if (value.length > MAX_STRING_LENGTH) {","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/sdks/nodejs-client/src/client/validation.ts#L1-L31","documentation":"Thrown by ensureNonEmptyString() in validation.ts:13 as a ValidationError when a required string exceeds 10000 characters (MAX_STRING_LENGTH). The cap is a defensive guard against accidentally passing oversized payloads (e.g. document text, prompts) into identifier fields. It applies to every field validated through ensureNonEmptyString — user, datasetId, fileId, name, etc.","triggerScenarios":"Passing a long string into a required-string slot: client.filePreview(hugeBlob, user) where the first arg is a base64 blob rather than a short file id; createDataset({ name: veryLongTitle }); user identifier sourced from a JWT or large token.","commonSituations":"Confusing a content field with an id field; concatenating user metadata into the user field; passing a serialized JSON blob where a short id was expected; copy-pasting a prompt into the wrong argument.","solutions":["Verify you are passing the short identifier, not the content: pass the file id from a prior upload, not the file bytes.","Trim or hash the value if you genuinely need a long user identifier — the SDK caps at 10000 chars by design.","Inspect the call stack to confirm which `${name}` triggered the error and route the long payload to the correct API (e.g. createDocumentByText for body content)."],"exampleFix":"// before\nawait client.filePreview(base64AudioBlob, user) // wrong arg\n\n// after\nawait client.filePreview(uploadedFileId, user)","handlingStrategy":"validation","validationCode":"function requireShortId(value: unknown, name: string, max = 256): string {\n  if (typeof value !== 'string' || value.trim().length === 0) throw new Error(`${name} required`)\n  if (value.length > max) throw new Error(`${name} looks like content, not an id`)\n  return value\n}","typeGuard":"function isShortId(value: unknown, max = 256): value is string {\n  return typeof value === 'string' && value.trim().length > 0 && value.length <= max\n}","tryCatchPattern":"try {\n  await client.filePreview(fileId, user)\n} catch (err) {\n  if (err instanceof Error && /exceeds maximum length/.test(err.message)) {\n    // prompt caller to upload first, then preview by id\n  } else throw err\n}","preventionTips":["Distinguish identifier fields from content fields in your types.","Run a sanity check: any id longer than ~256 chars is suspicious.","Never serialize large blobs into id slots."],"tags":["validation","length-limit","string","guard"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}