{"record":{"id":"df66e8871673bcbb","repo":"microsoft/semantic-kernel","slug":"failed-to-initialize-the-amazon-bedrock-chat-compl","errorCode":null,"errorMessage":"Failed to initialize the Amazon Bedrock Chat Completion Service.","messagePattern":"Failed to initialize the Amazon Bedrock Chat Completion Service\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/bedrock/services/bedrock_chat_completion.py","lineNumber":87,"sourceCode":"\n        Args:\n            model_id: The Amazon Bedrock chat model ID to use.\n            model_provider: The Bedrock model provider to use.\n            service_id: The Service ID for the completion service.\n            runtime_client: The Amazon Bedrock runtime client to use.\n            client: The Amazon Bedrock client to use.\n            env_file_path: The path to the .env file.\n            env_file_encoding: The encoding of the .env file.\n        \"\"\"\n        try:\n            bedrock_settings = BedrockSettings(\n                chat_model_id=model_id,\n                model_provider=model_provider,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as e:\n            raise ServiceInitializationError(\"Failed to initialize the Amazon Bedrock Chat Completion Service.\") from e\n\n        if bedrock_settings.chat_model_id is None:\n            raise ServiceInitializationError(\"The Amazon Bedrock Chat Model ID is missing.\")\n\n        super().__init__(\n            ai_model_id=bedrock_settings.chat_model_id,\n            service_id=service_id or bedrock_settings.chat_model_id,\n            runtime_client=runtime_client,\n            client=client,\n            bedrock_model_provider=bedrock_settings.model_provider,\n        )\n\n    # region Overriding base class methods\n\n    # Override from AIServiceClientBase\n    @override\n    def get_prompt_execution_settings_class(self) -> type[\"PromptExecutionSettings\"]:\n        return BedrockChatPromptExecutionSettings","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/bedrock/services/bedrock_chat_completion.py#L69-L105","documentation":"Raised during BedrockChatCompletion construction when BedrockSettings (chat_model_id, model_provider, env vars) fails Pydantic validation. This ServiceInitializationError is thrown before the Bedrock client is built; the original ValidationError is chained so the failing field is identifiable.","triggerScenarios":"BedrockSettings validation fails — e.g. an invalid model_provider value (not one of the supported providers), a malformed env var, or conflicting/missing required configuration. The AWS client (runtime_client/client) is constructed separately; this error is specifically about settings parsing.","commonSituations":"Passing model_provider as an unsupported string; misconfigured .env (env_file_path wrong); version drift where BedrockSettings added a required field; typos in model_id or provider.","solutions":["Inspect the chained ValidationError (e.__cause__) to see which field failed.","Provide a valid chat_model_id and a supported model_provider (or let it be inferred from the model_id).","Verify env_file_path/encoding if loading config from a .env file."],"exampleFix":"# before\nservice = BedrockChatCompletion(model_id=\"anthropic.claude\", model_provider=\"nonsense\")\n\n# after\nservice = BedrockChatCompletion(model_id=\"anthropic.claude-3-sonnet\", model_provider=\"anthropic\")","handlingStrategy":"try-catch","validationCode":"# Validate provider/model_id shape before constructing\nSUPPORTED_PROVIDERS = {\"anthropic\", \"amazon\", \"meta\", \"mistral\", \"ai21\", \"cohere\", \"stability\"}\nassert model_provider is None or model_provider in SUPPORTED_PROVIDERS, \\\n    f\"model_provider must be one of {SUPPORTED_PROVIDERS}\"","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceInitializationError\ntry:\n    service = BedrockChatCompletion(model_id=model_id, model_provider=model_provider)\nexcept ServiceInitializationError as e:\n    print(\"Bedrock settings error:\", e.__cause__)","preventionTips":["Use a supported model_provider value or omit it to infer from model_id.","Inspect __cause__ for the exact failing field.","Verify env file path if loading config from .env."],"tags":["bedrock","configuration","service-init","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}