High severity beginner · Fix: 2-5 min

ValueError

semantic_kernel.kernel.KernelError: Service not added to kernel

What this error means
This error occurs when you try to use a Semantic Kernel service that has not been registered or added to the kernel instance.

Stack trace

traceback
Traceback (most recent call last):
  File "app.py", line 42, in <module>
    kernel.get_service("text_completion")
  File "semantic_kernel/kernel.py", line 210, in get_service
    raise KernelError("Service not added to kernel")
semantic_kernel.kernel.KernelError: Service not added to kernel
QUICK FIX
Add the missing service to the kernel with kernel.add_service() before calling it.

Why it happens

Semantic Kernel requires all AI services (like text completion or embeddings) to be explicitly added to the kernel before use. This error happens when your code attempts to access a service that was never registered, causing the kernel to raise an exception.

Detection

Check your kernel initialization code to ensure all required services are added before calling them. Logging kernel service registrations can help detect missing services early.

Causes & fixes

1

The AI service (e.g., text completion) was never added to the kernel instance.

✓ Fix

Add the required service to the kernel using kernel.add_service() or the appropriate method before accessing it.

2

Typo or mismatch in the service name when retrieving it from the kernel.

✓ Fix

Verify the exact service name string matches the one used during registration, including case sensitivity.

3

Kernel initialization code runs after the service retrieval call, causing the service to be missing at access time.

✓ Fix

Ensure the kernel and its services are fully initialized before any service calls by reordering your code.

Code: broken vs fixed

Broken - triggers the error
python
from semantic_kernel import Kernel

kernel = Kernel()
# Missing: kernel.add_service('text_completion', service_instance)

result = kernel.get_service('text_completion').complete('Hello')  # This line raises the error
Fixed - works correctly
python
import os
from semantic_kernel import Kernel
from semantic_kernel.ai.open_ai import OpenAITextCompletion

os.environ['OPENAI_API_KEY'] = os.environ.get('OPENAI_API_KEY')  # Ensure your API key is set

kernel = Kernel()
text_completion = OpenAITextCompletion(api_key=os.environ['OPENAI_API_KEY'])
kernel.add_service('text_completion', text_completion)  # Added service registration

result = kernel.get_service('text_completion').complete('Hello')
print(result)  # This works now
Added the missing service registration call kernel.add_service() before accessing the service, ensuring the kernel knows about the service.

Workaround

Wrap the service retrieval in try/except, and if the service is missing, initialize and add it dynamically before retrying the call.

Prevention

Always register all required AI services with the kernel during initialization and validate service availability before usage to avoid runtime errors.

Python 3.9+ · semantic-kernel >=0.10.0 · tested on 0.12.0
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.