linshenkx/prompt-optimizer · error · Error

Empty prompt.messages

Error message

Empty prompt.messages

What it means

When format === 'messages', the prompt body's `messages` array is passed through normalizeImportedConversationMessages; if normalization yields zero messages, this error is thrown. Zero results can mean the input was empty or every entry failed normalization (bad role, invalid structure).

Source

Thrown at packages/ui/src/composables/app/useAppPromptGardenImport.ts:564

    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
    }

    if (!Array.isArray(data.variables)) {
      throw new Error('Missing variables')
    }
    const variablesForImport = data.variables
      .map((v): { name: string; defaultValue?: string } => {
        if (!isPlainObject(v)) return { name: '' }
        const name = typeof v.name === 'string' ? v.name.trim() : ''
        const defaultValue = typeof v.defaultValue === 'string' ? v.defaultValue : undefined
        return { name, defaultValue }
      })
      .filter((v) => isValidVariableName(v.name))

    const snapshotVariables = data.variables
      .map((v): GardenSnapshotVariable | null => {

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Inspect prompt.messages and confirm each entry has a recognized role and valid content shape
  2. Log which entries normalizeImportedConversationMessages drops to find the invalid message structure
  3. Re-export with a conversation containing at least one valid user/assistant message

Example fix

// before
{ "prompt": { "format": "messages", "messages": [] } }

// after
{ "prompt": { "format": "messages", "messages": [ { "role": "user", "content": "Hello" } ] } }
Defensive patterns

Strategy: validation

Validate before calling

const msgs = raw?.prompt?.messages
if (!Array.isArray(msgs) || msgs.length === 0) { /* block import */ }
// additionally check each entry has a known role

Type guard

const isMessageArray = (v: unknown): v is Array<{ role: string; content: unknown }> =>
  Array.isArray(v) && v.length > 0 && v.every(m => isPlainObject(m) && typeof m.role === 'string')

Try / catch

catch (e) { if (e.message === 'Empty prompt.messages') showImportError('Conversation is empty or invalid'); else throw e }

Prevention

When it happens

Trigger: prompt.messages is undefined/null/[] or contains only entries that normalizeImportedConversationMessages filters out (missing/invalid role or content).

Common situations: Messages exported with roles the importer doesn't recognize (e.g. 'tool', 'system2'); entries whose content is an unsupported shape; empty conversations exported as valid; upstream renamed 'role'/'content' keys.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/db98943d8b1c2b64. Report an issue: GitHub.