microsoft/semantic-kernel · error · ValueError

Unsupported service name: {service_name}

Error message

Unsupported service name: {service_name}

What it means

A ValueError raised by the text-completion setup dispatcher when the requested service_name does not match any key in its supported services dict. The dispatcher only knows a fixed set (OPENAI, BEDROCK, GOOGLE_AI, HUGGING_FACE, OLLAMA, ONNX, VERTEX_AI); anything else is rejected rather than silently ignored.

Source

Thrown at python/samples/concepts/setup/text_completion_services.py:48

    """Return service and request settings.

    Args:
        service_name (Services): The service name.
    """
    # Use lambdas or functions to delay instantiation
    text_services = {
        Services.OPENAI: lambda: get_openai_text_completion_service_and_request_settings(),
        Services.BEDROCK: lambda: get_bedrock_text_completion_service_and_request_settings(),
        Services.GOOGLE_AI: lambda: get_google_ai_text_completion_service_and_request_settings(),
        Services.HUGGING_FACE: lambda: get_hugging_face_text_completion_service_and_request_settings(),
        Services.OLLAMA: lambda: get_ollama_text_completion_service_and_request_settings(),
        Services.ONNX: lambda: get_onnx_text_completion_service_and_request_settings(),
        Services.VERTEX_AI: lambda: get_vertex_ai_text_completion_service_and_request_settings(),
    }

    # Call the appropriate lambda or function based on the service name
    if service_name not in text_services:
        raise ValueError(f"Unsupported service name: {service_name}")
    return text_services[service_name]()


def get_openai_text_completion_service_and_request_settings() -> tuple[
    "TextCompletionClientBase", "PromptExecutionSettings"
]:
    """Return OpenAI text completion service and request settings.

    The service credentials can be read by 3 ways:
    1. Via the constructor
    2. Via the environment variables
    3. Via an environment file

    The request settings control the behavior of the service. The default settings are sufficient to get started.
    However, you can adjust the settings to suit your needs.
    Note: Some of the settings are NOT meant to be set by the user.
    Please refer to the Semantic Kernel Python documentation for more information:
    https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel-python

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass one of the supported Services members: OPENAI, BEDROCK, GOOGLE_AI, HUGGING_FACE, OLLAMA, ONNX, or VERTEX_AI.
  2. If you need a service not in the list, add its lambda to the text_services dict in this sample file.
  3. Check the exact value of service_name against Services enum definitions before calling.

Example fix

// before
text_completion_services(Services.AZURE_OPENAI)

// after
text_completion_services(Services.OPENAI)
Defensive patterns

Strategy: validation

Validate before calling

from semantic_kernel.services import Services  # adjust import to actual enum location

SUPPORTED_TEXT = {Services.OPENAI, Services.BEDROCK, Services.GOOGLE_AI, Services.HUGGING_FACE, Services.OLLAMA, Services.ONNX, Services.VERTEX_AI}
assert service_name in SUPPORTED_TEXT, f"{service_name} not supported for text completion"

Type guard

def is_supported_text_service(name) -> bool:
    return name in {Services.OPENAI, Services.BEDROCK, Services.GOOGLE_AI, Services.HUGGING_FACE, Services.OLLAMA, Services.ONNX, Services.VERTEX_AI}

Try / catch

try:
    svc, settings = text_completion_services(service_name)
except ValueError:
    # fallback or prompt user for a supported service name
    ...

Prevention

When it happens

Trigger: Calling the dispatcher with a Services enum member (or string) not present in the text_services dict keys, e.g. passing Services.AZURE_OPENAI which has no text-completion lambda wired here.

Common situations: Passing a raw string that doesn't match the enum value; using a Services member that is valid for chat/embedding but not for text completion; a typo; expecting ONNX-style names that differ from the enum.

Related errors


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