{"record":{"id":"96b6cde05927113d","repo":"microsoft/semantic-kernel","slug":"unsupported-service-name-service-name","errorCode":null,"errorMessage":"Unsupported service name: {service_name}","messagePattern":"Unsupported service name: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/samples/concepts/setup/chat_completion_services.py","lineNumber":73,"sourceCode":"            instruction_role=instruction_role\n        ),\n        Services.AZURE_AI_INFERENCE: lambda: get_azure_ai_inference_chat_completion_service_and_request_settings(\n            instruction_role=instruction_role\n        ),\n        Services.ANTHROPIC: lambda: get_anthropic_chat_completion_service_and_request_settings(),\n        Services.BEDROCK: lambda: get_bedrock_chat_completion_service_and_request_settings(),\n        Services.GOOGLE_AI: lambda: get_google_ai_chat_completion_service_and_request_settings(),\n        Services.MISTRAL_AI: lambda: get_mistral_ai_chat_completion_service_and_request_settings(),\n        Services.OLLAMA: lambda: get_ollama_chat_completion_service_and_request_settings(),\n        Services.ONNX: lambda: get_onnx_chat_completion_service_and_request_settings(),\n        Services.VERTEX_AI: lambda: get_vertex_ai_chat_completion_service_and_request_settings(),\n        Services.DEEPSEEK: lambda: get_deepseek_chat_completion_service_and_request_settings(),\n        Services.NVIDIA: lambda: get_nvidia_chat_completion_service_and_request_settings(),\n    }\n\n    # Call the appropriate lambda or function based on the service name\n    if service_name not in chat_services:\n        raise ValueError(f\"Unsupported service name: {service_name}\")\n    return chat_services[service_name]()\n\n\ndef get_openai_chat_completion_service_and_request_settings(\n    instruction_role: str | None = None,\n) -> tuple[\"ChatCompletionClientBase\", \"PromptExecutionSettings\"]:\n    \"\"\"Return OpenAI chat completion service and request settings.\n\n    Args:\n        instruction_role (str | None): The role to use for 'instruction' messages, for example,\n            'developer' or 'system'. (Optional)\n\n    The service credentials can be read by 3 ways:\n    1. Via the constructor\n    2. Via the environment variables\n    3. Via an environment file\n\n    The request settings control the behavior of the service. The default settings are sufficient to get started.","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/samples/concepts/setup/chat_completion_services.py#L55-L91","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a valid Services enum member, e.g. Services.OPENAI (use the enum, not a raw string).","If accepting user input, validate/coerce it into Services first: Services(value) and handle ValueError.","Ensure the requested service's setup function is present in the chat_services dict (and its settings import succeeds)."],"exampleFix":"# before\nservice = get_chat_completion_service_and_request_settings(\"open_ai\")  # raises\n# after - use the enum\nservice = get_chat_completion_service_and_request_settings(Services.OPENAI)\n# or validate user input first\ntry:\n    service_enum = Services(input_str)\nexcept ValueError:\n    raise SystemExit(f\"Unknown service '{input_str}'. Choose from: {[s.value for s in Services]}\")\nservice = get_chat_completion_service_and_request_settings(service_enum)","handlingStrategy":"validation","validationCode":"from samples.concepts.setup.chat_completion_services import Services, get_chat_completion_service_and_request_settings\n\ndef resolve_service(name: str):\n    try:\n        enum = Services(name)            # coerce raw input -> enum\n    except ValueError:\n        raise ValueError(\n            f\"Unknown service '{name}'. Choose from: {[s.value for s in Services]}\")\n    return get_chat_completion_service_and_request_settings(enum)","typeGuard":"def is_supported_service(name: object) -> bool:\n    return isinstance(name, Services) or (\n        isinstance(name, str) and name in {s.value for s in Services}\n    )","tryCatchPattern":"try:\n    service, settings = get_chat_completion_service_and_request_settings(service_name)\nexcept ValueError as e:\n    # show the user the allowed set\n    print(f\"{e}. Valid: {[s.value for s in Services]}\")","preventionTips":["Pass a Services enum member, never a raw string guess.","Validate user/CLI input by coercing through Services(value) before calling.","Keep the chat_services dict and the Services enum in sync when adding/removing providers."],"tags":["python","sample","setup","configuration","enum"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}