microsoft/semantic-kernel · error · ServiceInitializationError

Failed to initialize the Amazon Bedrock Text Embedding Servi

Error message

Failed to initialize the Amazon Bedrock Text Embedding Service.

What it means

Raised during BedrockTextEmbedding construction when BedrockSettings (embedding_model_id, model_provider, env vars) fails Pydantic validation. ServiceInitializationError thrown before the client is built, original ValidationError chained.

Source

Thrown at python/semantic_kernel/connectors/ai/bedrock/services/bedrock_text_embedding.py:68

        Args:
            model_id: The Amazon Bedrock text embedding model ID to use.
            model_provider: The Bedrock model provider to use.
            service_id: The Service ID for the text embedding 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(
                embedding_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 Embedding Service.") from e

        if bedrock_settings.embedding_model_id is None:
            raise ServiceInitializationError("The Amazon Bedrock Text Embedding Model ID is missing.")

        super().__init__(
            ai_model_id=bedrock_settings.embedding_model_id,
            service_id=service_id or bedrock_settings.embedding_model_id,
            runtime_client=runtime_client,
            client=client,
            bedrock_model_provider=bedrock_settings.model_provider,
        )

    @override
    async def generate_embeddings(
        self,
        texts: list[str],
        settings: "PromptExecutionSettings | None" = None,
        **kwargs: Any,

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Inspect the chained ValidationError (e.__cause__) to find the failing field.
  2. Supply a valid embedding_model_id and supported model_provider.
  3. Verify env file path/encoding if loading from .env.

Example fix

# before
service = BedrockTextEmbedding(model_id="amazon.titan-embed", model_provider="bad")

# after
service = BedrockTextEmbedding(model_id="amazon.titan-embed-text-v2:0", 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 = BedrockTextEmbedding(model_id=model_id, model_provider=model_provider)
except ServiceInitializationError as e:
    print("Bedrock settings error:", e.__cause__)

Prevention

When it happens

Trigger: BedrockSettings validation fails — invalid model_provider, malformed env vars, missing/invalid required config for the embedding settings path.

Common situations: Unsupported model_provider string; wrong env_file_path; settings schema change after upgrade; typos in configuration.

Related errors


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