xtekky/gpt4free · error · ValueError

Prompt is empty.

Error message

Prompt is empty.

What it means

ValueError from gTTS.create_async_generator when get_last_message(messages, prompt) yields empty text. Google TTS needs the string to vocalize; with neither a non-empty message nor prompt the call aborts before constructing the output file.

Source

Thrown at g4f/Provider/audio/gTTS.py:66

    default_tld = "com"
    default_format = "mp3"

    default_model = "en-US"
    models = list(models.keys())
    audio_models = models

    @classmethod
    async def create_async_generator(
        cls,
        model: str,
        messages: Messages,
        prompt: str = None,
        audio: dict = {},
        **kwargs,
    ) -> AsyncResult:
        prompt = get_last_message(messages, prompt)
        if not prompt:
            raise ValueError("Prompt is empty.")
        format = audio.get("format", cls.default_format)
        filename = get_filename([cls.model_id], prompt, f".{format}", prompt)
        target_path = os.path.join(get_media_dir(), filename)
        ensure_media_dir()

        if "language" in audio:
            model = (
                locals[audio["language"]][0] if audio["language"] in locals else model
            )

        gTTS_Service(
            prompt,
            **{
                "lang": audio.get("language", cls.default_language),
                "tld": audio.get("tld", cls.default_tld),
                "slow": audio.get("slow", False),
                **models.get(model, {}),
            },

View on GitHub (pinned to 973504e177)

Solutions

  1. Pass the text explicitly via prompt='...'
  2. Guarantee the last message has non-empty content
  3. Add a guard in the pipeline: skip TTS when the text is blank

Example fix

# before
await client.speech.create(model='gTTS', text=user_input)  # user_input == ''

# after
if user_input.strip():
    await client.speech.create(model='gTTS', text=user_input)
Defensive patterns

Strategy: validation

Validate before calling

text = (prompt or '').strip() or (messages[-1]['content'] if messages else '')
if not text:
    return  # nothing to speak; skip gTTS call

Try / catch

except ValueError as e:
    if 'Prompt is empty' in str(e):
        log.warning('gTTS skipped: empty input'); return None

Prevention

When it happens

Trigger: Audio request through gTTS with an empty messages list and no prompt, or all message contents empty.

Common situations: Empty user input forwarded to speech; upstream text-generation step returned '' and the result is piped straight into TTS.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/263d55378f4db0db. Report an issue: GitHub.