{"record":{"id":"b65b3852432ed693","repo":"linshenkx/prompt-optimizer","slug":"image-understanding-user-prompt-cannot-be-empty","errorCode":null,"errorMessage":"Image understanding user prompt cannot be empty","messagePattern":"Image understanding user prompt cannot be empty","errorType":"validation","errorClass":"RequestConfigError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/llm/adapters/abstract-adapter.ts","lineNumber":208,"sourceCode":"      }\n\n      if (!['system', 'user', 'assistant', 'tool'].includes(msg.role)) {\n        throw new RequestConfigError(`Invalid message role: ${msg.role}`)\n      }\n\n      if (typeof msg.content !== 'string') {\n        throw new RequestConfigError('Message content must be a string')\n      }\n    }\n  }\n\n  protected validateImageUnderstandingRequest(request: ImageUnderstandingRequest): void {\n    if (!request || typeof request !== 'object') {\n      throw new RequestConfigError('Image understanding request cannot be empty')\n    }\n\n    if (typeof request.userPrompt !== 'string' || !request.userPrompt.trim()) {\n      throw new RequestConfigError('Image understanding user prompt cannot be empty')\n    }\n\n    if (!Array.isArray(request.images) || request.images.length === 0) {\n      throw new RequestConfigError('Image understanding request requires at least one image')\n    }\n\n    request.images.forEach((image, index) => {\n      if (!image || typeof image !== 'object') {\n        throw new RequestConfigError(`Image at index ${index} is invalid`)\n      }\n\n      if (typeof image.b64 !== 'string' || !image.b64.trim()) {\n        throw new RequestConfigError(`Image at index ${index} is missing base64 data`)\n      }\n    })\n  }\n\n  // ===== 工具方法 =====","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/llm/adapters/abstract-adapter.ts#L190-L226","documentation":"Thrown by validateImageUnderstandingRequest when request.userPrompt is not a string or is empty/whitespace-only. The image-understanding endpoints require a textual prompt to accompany the images; an empty prompt is rejected client-side before any API call.","triggerScenarios":"Calling sendImageUnderstanding({ userPrompt: '', images: [...] }) or with userPrompt: '   ' or a non-string value (undefined, number).","commonSituations":"UI prompt field left blank by the user and forwarded unchecked; prompt loaded from config key that doesn't exist (undefined); whitespace from trimmed form input.","solutions":["Default the prompt: request.userPrompt = prompt || 'Describe this image'","Require a non-empty prompt in the UI/form layer before invoking the API","Trim and check userPrompt.length > 0 in a pre-call validation step"],"exampleFix":"// before\nawait adapter.sendImageUnderstanding({ userPrompt: '', images: [{ b64 }] })\n\n// after\nawait adapter.sendImageUnderstanding({ userPrompt: 'Describe this image', images: [{ b64 }] })","handlingStrategy":"validation","validationCode":"const prompt = (request.userPrompt ?? '').trim()\nif (!prompt) throw new Error('prompt required')\nawait adapter.sendImageUnderstanding({ ...request, userPrompt: prompt })","typeGuard":"function hasValidPrompt(r: ImageUnderstandingRequest): boolean {\n  return typeof r.userPrompt === 'string' && r.userPrompt.trim().length > 0\n}","tryCatchPattern":"null","preventionTips":["Default empty prompts to a sensible fallback string","Validate form input before invoking the API"],"tags":["validation","image-understanding","empty-prompt"],"backgroundTag":"empty-prompt-validation","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}