microsoft/semantic-kernel · error · ValueError

Unsupported service name: {service_name}

Error message

Unsupported service name: {service_name}

What it means

ValueError raised by the chat_completion_services sample helper when the requested service_name is not a key in the chat_services dictionary. Because service_name is typed as the Services enum, this fires when a caller passes a value outside the supported set (a raw string that is not an enum member, or a Services member the dict was not populated for).

Source

Thrown at python/samples/concepts/setup/chat_completion_services.py:73

            instruction_role=instruction_role
        ),
        Services.AZURE_AI_INFERENCE: lambda: get_azure_ai_inference_chat_completion_service_and_request_settings(
            instruction_role=instruction_role
        ),
        Services.ANTHROPIC: lambda: get_anthropic_chat_completion_service_and_request_settings(),
        Services.BEDROCK: lambda: get_bedrock_chat_completion_service_and_request_settings(),
        Services.GOOGLE_AI: lambda: get_google_ai_chat_completion_service_and_request_settings(),
        Services.MISTRAL_AI: lambda: get_mistral_ai_chat_completion_service_and_request_settings(),
        Services.OLLAMA: lambda: get_ollama_chat_completion_service_and_request_settings(),
        Services.ONNX: lambda: get_onnx_chat_completion_service_and_request_settings(),
        Services.VERTEX_AI: lambda: get_vertex_ai_chat_completion_service_and_request_settings(),
        Services.DEEPSEEK: lambda: get_deepseek_chat_completion_service_and_request_settings(),
        Services.NVIDIA: lambda: get_nvidia_chat_completion_service_and_request_settings(),
    }

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


def get_openai_chat_completion_service_and_request_settings(
    instruction_role: str | None = None,
) -> tuple["ChatCompletionClientBase", "PromptExecutionSettings"]:
    """Return OpenAI chat completion service and request settings.

    Args:
        instruction_role (str | None): The role to use for 'instruction' messages, for example,
            'developer' or 'system'. (Optional)

    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.

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass a valid Services enum member, e.g. Services.OPENAI (use the enum, not a raw string).
  2. If accepting user input, validate/coerce it into Services first: Services(value) and handle ValueError.
  3. Ensure the requested service's setup function is present in the chat_services dict (and its settings import succeeds).

Example fix

# before
service = get_chat_completion_service_and_request_settings("open_ai")  # raises
# after - use the enum
service = get_chat_completion_service_and_request_settings(Services.OPENAI)
# or validate user input first
try:
    service_enum = Services(input_str)
except ValueError:
    raise SystemExit(f"Unknown service '{input_str}'. Choose from: {[s.value for s in Services]}")
service = get_chat_completion_service_and_request_settings(service_enum)
Defensive patterns

Strategy: validation

Validate before calling

from samples.concepts.setup.chat_completion_services import Services, get_chat_completion_service_and_request_settings

def resolve_service(name: str):
    try:
        enum = Services(name)            # coerce raw input -> enum
    except ValueError:
        raise ValueError(
            f"Unknown service '{name}'. Choose from: {[s.value for s in Services]}")
    return get_chat_completion_service_and_request_settings(enum)

Type guard

def is_supported_service(name: object) -> bool:
    return isinstance(name, Services) or (
        isinstance(name, str) and name in {s.value for s in Services}
    )

Try / catch

try:
    service, settings = get_chat_completion_service_and_request_settings(service_name)
except ValueError as e:
    # show the user the allowed set
    print(f"{e}. Valid: {[s.value for s in Services]}")

Prevention

When it happens

Trigger: Calling get_chat_completion_service_and_request_settings(service_name) with a value not in the chat_services map - e.g. a typo string 'open_ai', an unimplemented Services member, or Services cast from an invalid string.

Common situations: Passing a string instead of a Services enum member; a typo in the service name; referencing a service whose setup function was removed from the dict; or env/CLI input parsed into an invalid enum value.

Related errors


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