{"record":{"id":"ea8245fca8df7dbf","repo":"microsoft/semantic-kernel","slug":"model-id-model-id-does-not-contain-a-valid-model","errorCode":null,"errorMessage":"Model ID {model_id} does not contain a valid model provider name.","messagePattern":"Model ID (.+?) does not contain a valid model provider name\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/bedrock/services/model_provider/bedrock_model_provider.py","lineNumber":43,"sourceCode":"    \"\"\"Amazon Bedrock Model Provider Enum.\n\n    This list contains the providers of all base models available on Amazon Bedrock.\n    \"\"\"\n\n    AI21LABS = \"ai21\"\n    AMAZON = \"amazon\"\n    ANTHROPIC = \"anthropic\"\n    COHERE = \"cohere\"\n    META = \"meta\"\n    MISTRALAI = \"mistral\"\n\n    @classmethod\n    def to_model_provider(cls, model_id: str) -> \"BedrockModelProvider\":\n        \"\"\"Convert a model ID to a model provider.\"\"\"\n        try:\n            return next(provider for provider in cls if provider.value in model_id)\n        except StopIteration:\n            raise ValueError(f\"Model ID {model_id} does not contain a valid model provider name.\")\n\n\n# region Text Completion\n\n\nTEXT_COMPLETION_REQUEST_BODY_MAPPING: dict[\n    BedrockModelProvider, Callable[[str, BedrockTextPromptExecutionSettings], Any]\n] = {\n    BedrockModelProvider.AMAZON: bedrock_amazon_titan.get_text_completion_request_body,\n    BedrockModelProvider.ANTHROPIC: bedrock_anthropic_claude.get_text_completion_request_body,\n    BedrockModelProvider.COHERE: bedrock_cohere.get_text_completion_request_body,\n    BedrockModelProvider.AI21LABS: bedrock_ai21_labs.get_text_completion_request_body,\n    BedrockModelProvider.META: bedrock_meta_llama.get_text_completion_request_body,\n    BedrockModelProvider.MISTRALAI: bedrock_mistralai.get_text_completion_request_body,\n}\n\nTEXT_COMPLETION_RESPONSE_MAPPING: dict[BedrockModelProvider, Callable[[dict[str, Any], str], list[TextContent]]] = {\n    BedrockModelProvider.AMAZON: bedrock_amazon_titan.parse_text_completion_response,","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/bedrock/services/model_provider/bedrock_model_provider.py#L25-L61","documentation":"Raised by BedrockModelProvider.to_model_provider when none of the known provider substrings ('ai21', 'amazon', 'anthropic', 'cohere', 'meta', 'mistral') appear in the supplied model_id. The connector routes requests to provider-specific builders by matching the provider name inside the model ID string, so an unrecognized ID cannot be routed.","triggerScenarios":"Any Bedrock text/chat/embedding call that goes through get_*_request_body or parse_*_response without an explicit model_provider argument. Fires for a model_id like 'my-custom-model', 'llama-3-8b' (missing 'meta'), or an ARN/provisioned-model ID that does not contain one of the six provider keywords.","commonSituations":"User passes a short model alias instead of the full Bedrock model ID (e.g. 'claude-3' instead of 'anthropic.claude-3-sonnet'); using a new provider Bedrock added that SK has not mapped yet; passing an inference-profile ARN; copy-paste typo in the model ID.","solutions":["Use the full Bedrock model ID including the provider prefix, e.g. 'anthropic.claude-3-5-sonnet-20240620-v1:0', 'amazon.titan-embed-text-v2:0', 'meta.llama3-8b-instruct-v1:0'.","If using a cross-region or provisioned inference profile ARN, resolve the underlying base model ID first, or pass an explicit model_provider argument to bypass string matching.","If the provider is genuinely new (not in the BedrockModelProvider enum), request a library update; do not edit the enum in a fork unless you own the build.","Validate the model_id against your Bedrock account's list of available foundation models before constructing the service."],"exampleFix":"// before\nservice = BedrockChatCompletion(model_id=\"claude-3-sonnet\")\n// after\nservice = BedrockChatCompletion(model_id=\"anthropic.claude-3-5-sonnet-20240620-v1:0\")","handlingStrategy":"validation","validationCode":"SUPPORTED_PROVIDERS = (\"ai21\", \"amazon\", \"anthropic\", \"cohere\", \"meta\", \"mistral\")\n\ndef has_valid_bedrock_provider(model_id: str) -> bool:\n    return any(p in model_id for p in SUPPORTED_PROVIDERS)","typeGuard":"SUPPORTED_PROVIDERS = (\"ai21\", \"amazon\", \"anthropic\", \"cohere\", \"meta\", \"mistral\")\n\ndef is_valid_bedrock_model_id(model_id: object) -> bool:\n    return isinstance(model_id, str) and any(p in model_id for p in SUPPORTED_PROVIDERS)","tryCatchPattern":"try:\n    service = BedrockChatCompletion(model_id=model_id)\nexcept ValueError as e:\n    if \"does not contain a valid model provider name\" in str(e):\n        raise ValueError(f\"Use a full Bedrock model ID like 'anthropic.claude-3-5-sonnet-...'. Got: {model_id}\") from e\n    raise","preventionTips":["Always pass the full Bedrock model ID with provider prefix.","Validate the model ID against Bedrock's list-foundation-models output before constructing the service.","For inference-profile ARNs, pass model_provider explicitly to bypass string matching."],"tags":["bedrock","model-id","routing","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}