{"record":{"id":"a5803123f619d0c9","repo":"microsoft/semantic-kernel","slug":"ai-service-not-recognized","errorCode":null,"errorMessage":"AI service not recognized.","messagePattern":"AI service not recognized\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/samples/demos/telemetry/scenarios.py","lineNumber":96,"sourceCode":"                    async for update in ai_service.get_streaming_chat_message_contents(\n                        chat_history, PromptExecutionSettings()\n                    ):\n                        print(update[0].content, end=\"\")\n                    print()\n            elif isinstance(ai_service, TextCompletionClientBase):\n                if not stream:\n                    completion = await ai_service.get_text_contents(\n                        \"Why is the sky blue in one sentence?\", PromptExecutionSettings()\n                    )\n                    print(completion)\n                else:\n                    async for update in ai_service.get_streaming_text_contents(\n                        \"Why is the sky blue?\", PromptExecutionSettings()\n                    ):\n                        print(update[0].content, end=\"\")\n                    print()\n            else:\n                raise ValueError(\"AI service not recognized.\")\n        except Exception as e:\n            current_span.record_exception(e)\n            print(f\"Error running AI service: {e}\")\n\n\nasync def run_kernel_function(stream: bool = False) -> None:\n    \"\"\"Run a kernel function.\n\n    This function runs a kernel function and prints the output.\n    Telemetry will be collected for the function execution behind the scenes,\n    and the traces will be sent to the configured telemetry backend.\n\n    The telemetry will include information about the kernel function execution\n    and the AI service execution.\n\n    Args:\n        stream (bool): Whether to use streaming for the plugin invocation.\n    \"\"\"","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/samples/demos/telemetry/scenarios.py#L78-L114","documentation":"Thrown in the telemetry demo when the AI service retrieved from the kernel is neither a ChatCompletionClientBase nor a TextCompletionClientBase. The sample only knows how to drive those two service shapes; any other registered service type (e.g. an embedding service, or a custom service that doesn't subclass either base) triggers this ValueError.","triggerScenarios":"Calling run_ai_service after registering a non-chat/non-text service (e.g. OpenAITextEmbedding) as the first/default service and then fetching it; kernel.get_service returning an embedding or custom service.","commonSituations":"Adding an embedding service before/instead of a chat completion service; writing a custom service class that doesn't inherit from the recognized bases; selecting the wrong service_id.","solutions":["Register a ChatCompletionClientBase or TextCompletionClientBase service (e.g. OpenAIChatCompletion) in the kernel before running the scenario.","Select the correct service via its service_id instead of grabbing the first registered service.","Ensure your custom service subclasses ChatCompletionClientBase or TextCompletionClientBase if you want the demo to drive it.","Register the chat/text service before any embedding services so it is the one retrieved."],"exampleFix":"# before\nkernel.add_service(OpenAITextEmbedding(service_id='text-embedding'))\n# after\nkernel.add_service(OpenAIChatCompletion(service_id='open_ai'))\n# run_ai_service will now recognize the chat completion service.","handlingStrategy":"type-guard","validationCode":"from semantic_kernel.connectors.ai.chat_completion_client_base import ChatCompletionClientBase\nfrom semantic_kernel.connectors.ai.text_completion_client_base import TextCompletionClientBase\nsvc = kernel.get_service()\nassert isinstance(svc, (ChatCompletionClientBase, TextCompletionClientBase)), \\\n    f'Unsupported service type: {type(svc).__name__}'","typeGuard":"from semantic_kernel.connectors.ai.chat_completion_client_base import ChatCompletionClientBase\ndef is_runnable_ai_service(svc) -> bool:\n    from semantic_kernel.connectors.ai.text_completion_client_base import TextCompletionClientBase\n    return isinstance(svc, (ChatCompletionClientBase, TextCompletionClientBase))","tryCatchPattern":null,"preventionTips":["Register a chat or text completion service before running the scenario.","Select services by explicit service_id rather than 'first registered'.","Register the chat service before embedding services.","Ensure custom services subclass the recognized bases."],"tags":["telemetry","ai-service","kernel","type-mismatch","demo"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}