danny-avila/LibreChat · error · Error
Missing required field: prompt
Error message
Missing required field: prompt
What it means
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.
Source
Thrown at api/app/clients/tools/structured/GeminiImageGen.js:326
* Creates Gemini Image Generation tool
* @param {Object} fields - Configuration fields
* @returns {ReturnType<tool>} - The image generation tool
*/
function createGeminiImageTool(fields = {}) {
const override = fields.override ?? false;
if (!override && !fields.isAgent) {
throw new Error('This tool is only available for agents.');
}
const { req, imageFiles = [], userId, fileStrategy, GEMINI_API_KEY, GOOGLE_KEY } = fields;
const imageOutputType = fields.imageOutputType || EImageOutputType.PNG;
const geminiImageGenTool = tool(
async ({ prompt, image_ids, aspectRatio, imageSize }, runnableConfig) => {
if (!prompt) {
throw new Error('Missing required field: prompt');
}
logger.debug('[GeminiImageGen] Generating image', { aspectRatio, imageSize });
let ai;
try {
ai = await initializeGeminiClient({
GEMINI_API_KEY,
GOOGLE_KEY,
});
} catch (error) {
logger.error('[GeminiImageGen] Failed to initialize client:', error);
return [
[{ type: ContentTypes.TEXT, text: `Failed to initialize Gemini: ${error.message}` }],
{ content: [], file_ids: [] },
];
}
View on GitHub (pinned to 5ff282f900)
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.
Example fix
// before
await geminiImageTool.invoke({ image_ids: ['file-1'] }); // throws
// after
await geminiImageTool.invoke({ prompt: 'a fox under moonlight', image_ids: ['file-1'] }); Defensive patterns
Strategy: validation
Validate before calling
function buildGeminiImageArgs(input) {
if (typeof input.prompt !== 'string' || !input.prompt.trim()) {
throw new Error('Gemini image tool requires a non-empty prompt.');
}
return input;
} Type guard
function hasPrompt(arg) {
return typeof arg?.prompt === 'string' && arg.prompt.trim().length > 0;
} Try / catch
try {
await geminiTool.invoke(args);
} catch (e) {
if (/Missing required field: prompt/.test(e.message)) return 'A prompt is required to generate an image.';
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Missing required field: prompt
- Missing required field: prompt
- Missing required field: prompt
- Missing required field: finetune_id for finetuned generation
- Invalid endpoint for finetuned generation. Must be one of: $
AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12).
Data as JSON: /api/errors/5bd6d9cf0f08a791.
Report an issue: GitHub.