microsoft/semantic-kernel · error · ServiceInvalidRequestError

Prompt is required.

Error message

Prompt is required.

What it means

Raised by the deprecated generate_image method on OpenAITextToImageBase. The method first copies the description argument into settings.prompt (if settings.prompt is empty), then re-checks; if there is still no prompt it throws ServiceInvalidRequestError (a subclass of ServiceResponseException). This guards against a call where neither a description nor a settings.prompt was supplied.

Source

Thrown at python/semantic_kernel/connectors/ai/open_ai/services/open_ai_text_to_image_base.py:63

            settings = OpenAITextToImageExecutionSettings(**kwargs)
        if not isinstance(settings, OpenAITextToImageExecutionSettings):
            settings = OpenAITextToImageExecutionSettings.from_prompt_execution_settings(settings)
        if width:
            warn("The 'width' argument is deprecated. Use 'settings.size' instead.", DeprecationWarning)
            if settings.size and not settings.size.width:
                settings.size.width = width
        if height:
            warn("The 'height' argument is deprecated. Use 'settings.size' instead.", DeprecationWarning)
            if settings.size and not settings.size.height:
                settings.size.height = height
        if not settings.size and width and height:
            settings.size = ImageSize(width=width, height=height)

        if not settings.prompt:
            settings.prompt = description

        if not settings.prompt:
            raise ServiceInvalidRequestError("Prompt is required.")

        if not settings.ai_model_id:
            settings.ai_model_id = self.ai_model_id

        response = await self._send_request(settings)

        assert isinstance(response, ImagesResponse)  # nosec
        if not response.data or not (response.data[0].url or response.data[0].b64_json):
            raise ServiceResponseException("Failed to generate image.")

        return response.data[0].url or response.data[0].b64_json  # type: ignore[return-value]

    async def generate_images(
        self,
        prompt: str,
        settings: PromptExecutionSettings | None = None,
        **kwargs: Any,
    ) -> list[str]:

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass a non-empty description: await service.generate_image('A red panda')
  2. Migrate off the deprecated generate_image to generate_images(prompt='A red panda'), which is the supported path
  3. If using settings, set settings.prompt explicitly before calling
  4. Guard the caller so description is never None or empty

Example fix

# before (deprecated, raises)
await service.generate_image(description=None)

# after (supported API)
await service.generate_images(prompt="A red panda")
Defensive patterns

Strategy: validation

Validate before calling

if not description:
    raise ValueError("generate_image requires a non-empty description")
await service.generate_image(description=description)

Type guard

def is_valid_prompt(p: str | None) -> bool:
    return isinstance(p, str) and p.strip() != ""

Try / catch

from semantic_kernel.exceptions.service_exceptions import ServiceInvalidRequestError

try:
    await service.generate_image(description=desc)
except ServiceInvalidRequestError as e:
    if "Prompt is required" in str(e):
        # prompt/description missing — fix caller and retry
        ...
    raise

Prevention

When it happens

Trigger: Calling await service.generate_image(description=None) or generate_image('') while settings (if passed) has no prompt field. Also when kwargs contain no 'prompt' and no description is given.

Common situations: Migrating to the new generate_images API and passing the prompt in the wrong place; passing settings that were constructed without a prompt; the description variable is conditionally populated and resolved to an empty string.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/18c6063e23710cb2. Report an issue: GitHub.