linshenkx/prompt-optimizer · error · Error
Empty prompt.text
Error message
Empty prompt.text
What it means
When format === 'text', the prompt body must include a `text` string with non-whitespace content. The importer rejects empty, all-whitespace, or non-string text because an imported prompt with no content is unusable.
Source
Thrown at packages/ui/src/composables/app/useAppPromptGardenImport.ts:558
: ''
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
}
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 : undefinedView on GitHub (pinned to 3e677b1d9f)
Solutions
- Ensure prompt.text is a non-empty string with at least one non-whitespace character
- If the content lives under a different key upstream, fix the export or map the field before import
- For intentionally blank prompts, block them at the Garden export side rather than importing
Example fix
// before
{ "prompt": { "format": "text", "text": " " } }
// after
{ "prompt": { "format": "text", "text": "Summarize the following document." } } Defensive patterns
Strategy: validation
Validate before calling
if (fmt === 'text' && !(typeof raw.prompt.text === 'string' && raw.prompt.text.trim())) {
// block import: empty prompt body
} Type guard
const hasNonEmptyText = (p: unknown): boolean => isPlainObject(p) && typeof p.text === 'string' && p.text.trim().length > 0
Try / catch
catch (e) { if (e.message === 'Empty prompt.text') showImportError('Prompt has no content'); else throw e } Prevention
- Reject empty prompts at creation/export time
- Trim-validate prompt bodies in the editor
- Add fixture tests covering whitespace-only text
When it happens
Trigger: prompt.text is undefined, null, a non-string, an empty string '', or contains only spaces/newlines (fails t.trim()).
Common situations: Placeholder/draft prompts exported before content was written; whitespace-only templates; fields renamed upstream (e.g. 'content' instead of 'text').
Related errors
- Empty prompt.messages
- Unrecognized data structure
- ${label} content must not be empty.
- Iteration failed: Template not found or invalid
- Missing optimizerTarget.subModeKey
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/44db7ec419be2524.
Report an issue: GitHub.