linshenkx/prompt-optimizer · error · Error
Missing prompt.format
Error message
Missing prompt.format
What it means
The prompt body object (data.prompt) must carry a `format` field that is exactly 'text' or 'messages'. Anything else — including a missing format, null, or a value like 'markdown' — throws this error before content parsing begins.
Source
Thrown at packages/ui/src/composables/app/useAppPromptGardenImport.ts:550
if (data.schemaVersion !== 1) {
throw new Error('Unsupported Garden response schemaVersion')
}
const optimizerTarget = isPlainObject(data.optimizerTarget) ? data.optimizerTarget : null
const optimizerTargetKey =
optimizerTarget && typeof optimizerTarget.subModeKey === 'string'
? optimizerTarget.subModeKey.trim()
: ''
if (!optimizerTargetKey) {
throw new Error('Missing optimizerTarget.subModeKey')
}
const prompt = isPlainObject(data.prompt) ? data.prompt : null
const format = prompt && (prompt.format === 'text' || prompt.format === 'messages')
? (prompt.format as 'text' | 'messages')
: null
if (!format) {
throw new Error('Missing prompt.format')
}
let promptText: string | undefined
let promptMessages: ConversationMessage[] | undefined
if (format === 'text') {
const t = prompt && typeof prompt.text === 'string' ? prompt.text : ''
if (!t.trim()) {
throw new Error('Empty prompt.text')
}
promptText = t
} else {
const msgs = normalizeImportedConversationMessages(prompt?.messages)
if (!msgs.length) {
throw new Error('Empty prompt.messages')
}
promptMessages = msgs
}
View on GitHub (pinned to 3e677b1d9f)
Solutions
- Set prompt.format to exactly 'text' (plain string content) or 'messages' (conversation array)
- Check for case sensitivity and trailing whitespace in the value
- If upstream renamed formats, add a mapping in parseV1 or re-export
Example fix
// before
{ "prompt": { "format": "markdown", "text": "hi" } }
// after
{ "prompt": { "format": "text", "text": "hi" } } Defensive patterns
Strategy: type-guard
Validate before calling
const fmt = raw?.prompt?.format
if (fmt !== 'text' && fmt !== 'messages') { /* reject before import */ } Type guard
const isPromptFormat = (v: unknown): v is 'text' | 'messages' => v === 'text' || v === 'messages'
Try / catch
catch (e) { if (e.message === 'Missing prompt.format') showImportError('Unsupported prompt format'); else throw e } Prevention
- Whitelist format values at export time
- Use literal union types when building payloads
- Watch for case-sensitive comparisons when hand-editing JSON
When it happens
Trigger: data.prompt is null/not an object, prompt.format is undefined, or prompt.format is a string other than 'text'/'messages' (case-sensitive).
Common situations: New export format names upstream (e.g. 'chat', 'markdown'); truncated payloads; case mismatches like 'Text'; hand-edited JSON where format was deleted.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Missing optimizerTarget.subModeKey
- Empty prompt.text
- Empty prompt.messages
- Missing variables
- CONTEXT_ERROR_CODES.STORAGE_ERROR
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/4d06bd331cc5016b.
Report an issue: GitHub.