{"record":{"id":"6b71b6e83f772e09","repo":"microsoft/semantic-kernel","slug":"failed-to-initialize-the-booking-sample-settings","errorCode":null,"errorMessage":"Failed to initialize the booking sample settings.","messagePattern":"Failed to initialize the booking sample settings\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/samples/demos/booking_restaurant/restaurant_booking.py","lineNumber":30,"sourceCode":"from semantic_kernel.connectors.ai.open_ai.prompt_execution_settings.open_ai_prompt_execution_settings import (\n    OpenAIChatPromptExecutionSettings,\n)\nfrom semantic_kernel.connectors.ai.open_ai.services.open_ai_chat_completion import OpenAIChatCompletion\nfrom semantic_kernel.contents.chat_history import ChatHistory\nfrom semantic_kernel.exceptions.service_exceptions import ServiceInitializationError\nfrom semantic_kernel.functions.kernel_arguments import KernelArguments\nfrom semantic_kernel.kernel import Kernel\n\nkernel = Kernel()\n\nservice_id = \"open_ai\"\nai_service = OpenAIChatCompletion(service_id=service_id, ai_model_id=\"gpt-3.5-turbo\")\nkernel.add_service(ai_service)\n\ntry:\n    booking_sample_settings = BookingSampleSettings()\nexcept ValidationError as e:\n    raise ServiceInitializationError(\"Failed to initialize the booking sample settings.\") from e\n\ntenant_id = booking_sample_settings.tenant_id\nclient_id = booking_sample_settings.client_id\nclient_secret = booking_sample_settings.client_secret\nclient_secret_credential = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)\n\ngraph_client = GraphServiceClient(credentials=client_secret_credential, scopes=[\"https://graph.microsoft.com/.default\"])\n\nbooking_business_id = booking_sample_settings.business_id\nbooking_service_id = booking_sample_settings.service_id\n\nbookings_plugin = BookingsPlugin(\n    graph_client=graph_client,\n    booking_business_id=booking_business_id,\n    booking_service_id=booking_service_id,\n)\n\nkernel.add_plugin(bookings_plugin, \"BookingsPlugin\")","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/samples/demos/booking_restaurant/restaurant_booking.py#L12-L48","documentation":"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.","triggerScenarios":"Importing/running restaurant_booking.py when one or more required BookingSampleSettings fields cannot be resolved from environment variables, causing pydantic to raise ValidationError.","commonSituations":"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.","solutions":["Populate all required BookingSampleSettings env vars (tenant_id, client_id, client_secret, business_id, service_id) from your Azure app registration and Bookings configuration.","Inspect the chained ValidationError (`from e`) to see exactly which fields failed; it lists the missing/invalid fields.","Ensure the .env file is in the demo's working directory and is actually loaded by pydantic-settings."],"exampleFix":"// before\ntry:\n    booking_sample_settings = BookingSampleSettings()\nexcept ValidationError as e:\n    raise ServiceInitializationError(\"Failed to initialize the booking sample settings.\") from e\n\n// after\n# first inspect the wrapped error to see missing fields\ntry:\n    booking_sample_settings = BookingSampleSettings()\nexcept ValidationError as e:\n    print(e.errors())  # shows which env vars are missing\n    raise","handlingStrategy":"try-catch","validationCode":"from booking_sample_settings import BookingSampleSettings\nimport os\n\nrequired = [\"BOOKING_TENANT_ID\", \"BOOKING_CLIENT_ID\", \"BOOKING_CLIENT_SECRET\", \"BOOKING_BUSINESS_ID\", \"BOOKING_SERVICE_ID\"]\nmissing = [k for k in required if not os.getenv(k)]\nif missing:\n    raise SystemExit(f\"Missing booking env vars: {missing}\")\nsettings = BookingSampleSettings()","typeGuard":null,"tryCatchPattern":"try:\n    booking_sample_settings = BookingSampleSettings()\nexcept ValidationError as e:\n    for err in e.errors():\n        print(err['loc'], err['msg'])\n    raise","preventionTips":["Document the exact env var names BookingSampleSettings expects.","Run a startup env-var check before constructing pydantic settings models."],"tags":["configuration","env-vars","pydantic","azure","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}