{"record":{"id":"5bd6d9cf0f08a791","repo":"danny-avila/LibreChat","slug":"missing-required-field-prompt-5bd6d9","errorCode":null,"errorMessage":"Missing required field: prompt","messagePattern":"Missing required field: prompt","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"api/app/clients/tools/structured/GeminiImageGen.js","lineNumber":326,"sourceCode":" * Creates Gemini Image Generation tool\n * @param {Object} fields - Configuration fields\n * @returns {ReturnType<tool>} - The image generation tool\n */\nfunction createGeminiImageTool(fields = {}) {\n  const override = fields.override ?? false;\n\n  if (!override && !fields.isAgent) {\n    throw new Error('This tool is only available for agents.');\n  }\n\n  const { req, imageFiles = [], userId, fileStrategy, GEMINI_API_KEY, GOOGLE_KEY } = fields;\n\n  const imageOutputType = fields.imageOutputType || EImageOutputType.PNG;\n\n  const geminiImageGenTool = tool(\n    async ({ prompt, image_ids, aspectRatio, imageSize }, runnableConfig) => {\n      if (!prompt) {\n        throw new Error('Missing required field: prompt');\n      }\n\n      logger.debug('[GeminiImageGen] Generating image', { aspectRatio, imageSize });\n\n      let ai;\n      try {\n        ai = await initializeGeminiClient({\n          GEMINI_API_KEY,\n          GOOGLE_KEY,\n        });\n      } catch (error) {\n        logger.error('[GeminiImageGen] Failed to initialize client:', error);\n        return [\n          [{ type: ContentTypes.TEXT, text: `Failed to initialize Gemini: ${error.message}` }],\n          { content: [], file_ids: [] },\n        ];\n      }\n","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/app/clients/tools/structured/GeminiImageGen.js#L308-L344","documentation":"Runtime guard at the top of the Gemini image tool's async callback: the destructured `prompt` argument must be present before initializeGeminiClient and the generation call proceed. Thrown before any Google API call.","triggerScenarios":"The Gemini image tool is invoked with arguments where `prompt` is missing, null, undefined, or empty — e.g., the model only passed image_ids or aspectRatio.","commonSituations":"LLM emitted a tool call with optional-only fields; schema change dropped prompt from required; programmatic invocation that built args from optional user input; prompt lost during arg marshalling upstream.","solutions":["Ensure the tool-call arguments always include a non-empty `prompt` string.","Mark `prompt` as required in the tool's input schema so the model is forced to emit it.","Validate args before invoking when prompt comes from user input.","Log the raw tool arguments at the boundary to catch silent prompt drops."],"exampleFix":"// before\nawait geminiImageTool.invoke({ image_ids: ['file-1'] }); // throws\n\n// after\nawait geminiImageTool.invoke({ prompt: 'a fox under moonlight', image_ids: ['file-1'] });","handlingStrategy":"validation","validationCode":"function buildGeminiImageArgs(input) {\n  if (typeof input.prompt !== 'string' || !input.prompt.trim()) {\n    throw new Error('Gemini image tool requires a non-empty prompt.');\n  }\n  return input;\n}","typeGuard":"function hasPrompt(arg) {\n  return typeof arg?.prompt === 'string' && arg.prompt.trim().length > 0;\n}","tryCatchPattern":"try {\n  await geminiTool.invoke(args);\n} catch (e) {\n  if (/Missing required field: prompt/.test(e.message)) return 'A prompt is required to generate an image.';\n  throw e;\n}","preventionTips":["Require `prompt` in the Gemini image tool schema.","Validate tool-call args at the boundary before invoking.","Log raw model tool-call JSON to detect prompt omissions."],"tags":["gemini","input-validation","prompt","tool-args"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}