microsoft/semantic-kernel · error · ServiceInitializationError

Failed to initialize the booking sample settings.

Error message

Failed to initialize the booking sample settings.

What it means

A ServiceInitializationError wrapping a pydantic ValidationError raised while constructing BookingSampleSettings. The sample instantiates a pydantic settings model that requires Microsoft Graph / Bookings credentials (tenant_id, client_id, client_secret, business_id, service_id); if validation fails the raw error is re-thrown as a friendlier service-init exception with the original chained as cause.

Source

Thrown at python/samples/demos/booking_restaurant/restaurant_booking.py:30

from semantic_kernel.connectors.ai.open_ai.prompt_execution_settings.open_ai_prompt_execution_settings import (
    OpenAIChatPromptExecutionSettings,
)
from semantic_kernel.connectors.ai.open_ai.services.open_ai_chat_completion import OpenAIChatCompletion
from semantic_kernel.contents.chat_history import ChatHistory
from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError
from semantic_kernel.functions.kernel_arguments import KernelArguments
from semantic_kernel.kernel import Kernel

kernel = Kernel()

service_id = "open_ai"
ai_service = OpenAIChatCompletion(service_id=service_id, ai_model_id="gpt-3.5-turbo")
kernel.add_service(ai_service)

try:
    booking_sample_settings = BookingSampleSettings()
except ValidationError as e:
    raise ServiceInitializationError("Failed to initialize the booking sample settings.") from e

tenant_id = booking_sample_settings.tenant_id
client_id = booking_sample_settings.client_id
client_secret = booking_sample_settings.client_secret
client_secret_credential = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)

graph_client = GraphServiceClient(credentials=client_secret_credential, scopes=["https://graph.microsoft.com/.default"])

booking_business_id = booking_sample_settings.business_id
booking_service_id = booking_sample_settings.service_id

bookings_plugin = BookingsPlugin(
    graph_client=graph_client,
    booking_business_id=booking_business_id,
    booking_service_id=booking_service_id,
)

kernel.add_plugin(bookings_plugin, "BookingsPlugin")

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Populate all required BookingSampleSettings env vars (tenant_id, client_id, client_secret, business_id, service_id) from your Azure app registration and Bookings configuration.
  2. Inspect the chained ValidationError (`from e`) to see exactly which fields failed; it lists the missing/invalid fields.
  3. Ensure the .env file is in the demo's working directory and is actually loaded by pydantic-settings.

Example fix

// before
try:
    booking_sample_settings = BookingSampleSettings()
except ValidationError as e:
    raise ServiceInitializationError("Failed to initialize the booking sample settings.") from e

// after
# first inspect the wrapped error to see missing fields
try:
    booking_sample_settings = BookingSampleSettings()
except ValidationError as e:
    print(e.errors())  # shows which env vars are missing
    raise
Defensive patterns

Strategy: try-catch

Validate before calling

from booking_sample_settings import BookingSampleSettings
import os

required = ["BOOKING_TENANT_ID", "BOOKING_CLIENT_ID", "BOOKING_CLIENT_SECRET", "BOOKING_BUSINESS_ID", "BOOKING_SERVICE_ID"]
missing = [k for k in required if not os.getenv(k)]
if missing:
    raise SystemExit(f"Missing booking env vars: {missing}")
settings = BookingSampleSettings()

Try / catch

try:
    booking_sample_settings = BookingSampleSettings()
except ValidationError as e:
    for err in e.errors():
        print(err['loc'], err['msg'])
    raise

Prevention

When it happens

Trigger: Importing/running restaurant_booking.py when one or more required BookingSampleSettings fields cannot be resolved from environment variables, causing pydantic to raise ValidationError.

Common situations: Missing or misnamed env vars for the booking demo (e.g. tenant id, client secret, business id); .env file not loaded; values left blank; copied sample without populating the real Azure app registration credentials.

Related errors


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