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 image_gen_oai tool callback: the destructured `prompt` must be present before it constructs the OpenAI client and calls images.generate. Thrown before any network I/O.
Source
Thrown at api/app/clients/tools/structured/OpenAIImageTools.js:127
const imageFiles = fields.imageFiles ?? [];
/**
* Image Generation Tool
*/
const imageGenTool = tool(
async (
{
prompt,
background = 'auto',
n = 1,
output_compression = 100,
quality = 'auto',
size = 'auto',
},
runnableConfig,
) => {
if (!prompt) {
throw new Error('Missing required field: prompt');
}
const clientConfig = { ...closureConfig };
const proxyDispatcher = getProxyDispatcher();
if (proxyDispatcher) {
clientConfig.fetchOptions = {
dispatcher: proxyDispatcher,
};
}
/** @type {OpenAI} */
const openai = new OpenAI(clientConfig);
let output_format = imageOutputType;
if (
background === 'transparent' &&
output_format !== EImageOutputType.PNG &&
output_format !== EImageOutputType.WEBP
) {
logger.warn(View on GitHub (pinned to 5ff282f900)
Solutions
- Always include a non-empty `prompt` string in the tool-call arguments.
- Mark `prompt` as required in the tool schema.
- Validate args at the boundary before invoking the tool.
- Inspect the raw tool-call JSON to confirm the model is emitting `prompt` and not a synonym.
Example fix
// before
await imageGenTool.invoke({ size: '1024x1024' }); // throws
// after
await imageGenTool.invoke({ prompt: 'a fox in snow', size: '1024x1024' }); Defensive patterns
Strategy: validation
Validate before calling
function buildImageGenArgs(input) {
if (typeof input.prompt !== 'string' || !input.prompt.trim()) {
throw new Error('image_gen_oai 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 imageGenTool.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 image_gen_oai schema.
- Validate tool-call args before invoking.
- Log raw model tool-call JSON to catch missing prompts.
When it happens
Trigger: The OpenAI image-generation tool is invoked with a payload where `prompt` is missing/null/empty — e.g., only quality/size/background were supplied.
Common situations: The model emitted tool args without prompt; the JSON schema does not mark prompt required so the model omitted it; programmatic caller built args from optional input; refactoring renamed the field.
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/1578711e0aca2edc.
Report an issue: GitHub.