microsoft/semantic-kernel · error · ServiceInitializationError
Failed to initialize the Amazon Bedrock Chat Completion Serv
Error message
Failed to initialize the Amazon Bedrock Chat Completion Service.
What it means
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.
Source
Thrown at python/semantic_kernel/connectors/ai/bedrock/services/bedrock_chat_completion.py:87
Args:
model_id: The Amazon Bedrock chat model ID to use.
model_provider: The Bedrock model provider to use.
service_id: The Service ID for the completion service.
runtime_client: The Amazon Bedrock runtime client to use.
client: The Amazon Bedrock client to use.
env_file_path: The path to the .env file.
env_file_encoding: The encoding of the .env file.
"""
try:
bedrock_settings = BedrockSettings(
chat_model_id=model_id,
model_provider=model_provider,
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)
except ValidationError as e:
raise ServiceInitializationError("Failed to initialize the Amazon Bedrock Chat Completion Service.") from e
if bedrock_settings.chat_model_id is None:
raise ServiceInitializationError("The Amazon Bedrock Chat Model ID is missing.")
super().__init__(
ai_model_id=bedrock_settings.chat_model_id,
service_id=service_id or bedrock_settings.chat_model_id,
runtime_client=runtime_client,
client=client,
bedrock_model_provider=bedrock_settings.model_provider,
)
# region Overriding base class methods
# Override from AIServiceClientBase
@override
def get_prompt_execution_settings_class(self) -> type["PromptExecutionSettings"]:
return BedrockChatPromptExecutionSettingsView on GitHub (pinned to c028a0c7dc)
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.
Example fix
# before service = BedrockChatCompletion(model_id="anthropic.claude", model_provider="nonsense") # after service = BedrockChatCompletion(model_id="anthropic.claude-3-sonnet", model_provider="anthropic")
Defensive patterns
Strategy: try-catch
Validate before calling
# Validate provider/model_id shape before constructing
SUPPORTED_PROVIDERS = {"anthropic", "amazon", "meta", "mistral", "ai21", "cohere", "stability"}
assert model_provider is None or model_provider in SUPPORTED_PROVIDERS, \
f"model_provider must be one of {SUPPORTED_PROVIDERS}" Try / catch
from semantic_kernel.exceptions import ServiceInitializationError
try:
service = BedrockChatCompletion(model_id=model_id, model_provider=model_provider)
except ServiceInitializationError as e:
print("Bedrock settings error:", e.__cause__) Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The Amazon Bedrock Chat Model ID is missing.
- Failed to initialize the Amazon Bedrock Text Completion Serv
- The Amazon Bedrock Text Model ID is missing.
- Failed to initialize the Amazon Bedrock Text Embedding Servi
- The Amazon Bedrock Text Embedding Model ID is missing.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/df66e8871673bcbb.
Report an issue: GitHub.