microsoft/semantic-kernel · error · ServiceInitializationError
Failed to initialize the Amazon Bedrock Text Completion…
Error message
Failed to initialize the Amazon Bedrock Text Completion Service.
What it means
Raised during BedrockTextCompletion construction when BedrockSettings (text_model_id, model_provider, env vars) fails Pydritic validation. Mirrors the chat-completion init error: a ServiceInitializationError thrown before the client is created, with the ValidationError chained.
Solutions
- Inspect the chained ValidationError (e.__cause__) to find the failing field.
- Supply a valid text_model_id and supported model_provider.
- Verify env file path/encoding if loading from .env.
Example fix
# before service = BedrockTextCompletion(model_id="amazon.titan-text", model_provider="bogus") # after service = BedrockTextCompletion(model_id="amazon.titan-text-express-v1", model_provider="amazon")
Defensive patterns
Strategy: try-catch
Validate before calling
SUPPORTED_PROVIDERS = {"anthropic", "amazon", "meta", "mistral", "ai21", "cohere", "stability"}
assert model_provider is None or model_provider in SUPPORTED_PROVIDERS Try / catch
from semantic_kernel.exceptions import ServiceInitializationError
try:
service = BedrockTextCompletion(model_id=model_id, model_provider=model_provider)
except ServiceInitializationError as e:
print("Bedrock settings error:", e.__cause__) Prevention
- Use a supported model_provider or omit to infer from model_id.
- Inspect __cause__ for the failing field.
- Verify env file path/encoding.
When it happens
Trigger: BedrockSettings validation fails — invalid model_provider, malformed env, missing/invalid required config for the text-completion settings path.
Common situations: Unsupported model_provider string; wrong env_file_path; settings schema change after an SDK upgrade; typos in configuration.
Related errors
- The Amazon Bedrock Text Model ID is missing.
- Failed to initialize the Amazon Bedrock Chat Completion…
- Failed to initialize the Amazon Bedrock Text Embedding…
- The Amazon Bedrock Chat Model ID is missing.
- 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/7c5971ee2cfe498e.
Report an issue: GitHub.
Appendix: source
Thrown at python/semantic_kernel/connectors/ai/bedrock/services/bedrock_text_completion.py:71
Args:
model_id: The Amazon Bedrock text model ID to use.
model_provider: The Bedrock model provider to use.
service_id: The Service ID for the text 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 to load settings from.
env_file_encoding: The encoding of the .env file.
"""
try:
bedrock_settings = BedrockSettings(
text_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 Text Completion Service.") from e
if bedrock_settings.text_model_id is None:
raise ServiceInitializationError("The Amazon Bedrock Text Model ID is missing.")
super().__init__(
ai_model_id=bedrock_settings.text_model_id,
service_id=service_id or bedrock_settings.text_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 BedrockTextPromptExecutionSettingsView on GitHub (pinned to c028a0c7dc)