microsoft/semantic-kernel · error · ValueError
Error: unable to create Azure Cognitive Search client.
Error message
Error: unable to create Azure Cognitive Search client.
What it means
Final fallthrough in `get_search_index_async_client`: if neither `azure_credential` nor `token_credential` is truthy, it raises a plain `ValueError` (note: `ValueError`, inconsistent with the `ServiceInitializationError` used by the sibling guards). Given the earlier guards (1373/1374) this branch is effectively unreachable; it exists as a last-resort assertion.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/azure_cognitive_search/utils.py:79
elif token_credential:
token_credential = token_credential
elif os.getenv(ENV_VAR_API_KEY):
azure_credential = AzureKeyCredential(os.getenv(ENV_VAR_API_KEY))
else:
raise ServiceInitializationError("Error: missing Azure Cognitive Search client credentials.")
if azure_credential is None and token_credential is None:
raise ServiceInitializationError("Error: Azure Cognitive Search credentials not set.")
sk_headers = {USER_AGENT: "Semantic-Kernel"}
if azure_credential:
return SearchIndexClient(endpoint=service_endpoint, credential=azure_credential, headers=sk_headers)
if token_credential:
return SearchIndexClient(endpoint=service_endpoint, credential=token_credential, headers=sk_headers)
raise ValueError("Error: unable to create Azure Cognitive Search client.")
def get_index_schema(vector_size: int, vector_search_profile_name: str) -> list:
"""Return the schema of search indexes.
Args:
vector_size (int): The size of the vectors being stored in collection/index.
vector_search_profile_name (str): The name of the vector search profile.
Returns:
list: The Azure Cognitive Search schema as list type.
"""
return [
SimpleField(
name=SEARCH_FIELD_ID,
type=SearchFieldDataType.String,
searchable=True,
filterable=True,View on GitHub (pinned to c028a0c7dc)
Solutions
- Supply a valid credential (see error 1373) so the function returns a `SearchIndexClient` before this point.
- If hit during normal use, treat it as a bug in the credential-resolution logic and report it.
- Normalize the exception type in a wrapper so callers catch a single error family.
Defensive patterns
Strategy: validation
Validate before calling
# Defensive/unreachable under normal flow; ensure a credential is truthy so a # SearchIndexClient is returned before reaching this ValueError. assert azure_credential or token_credential, "both credentials falsy unexpectedly"
Type guard
def can_build_client(azure_credential, token_credential) -> bool:
return bool(azure_credential) or bool(token_credential) Try / catch
try:
client = get_search_index_async_client(...)
except ValueError as e:
if "unable to create Azure Cognitive Search client" in str(e):
raise SystemExit("unexpected fallthrough; supply valid credentials") from e
raise Prevention
- Provide a valid credential so the function returns a client before the fallthrough.
- Wrap the call to convert this `ValueError` into a single error family for callers.
- Report as a bug if reached during normal configuration.
When it happens
Trigger: Only reachable if both credential variables are falsy while bypassing the preceding checks — i.e. via a regression, monkeypatching, or a future refactor. Under current logic the function returns from one of the two `SearchIndexClient(...)` construction branches before reaching here.
Common situations: Test/monkeypatch interference; logic regression after editing the credential branches; a credential object that is truthy at the None-check but falsy at the final `if`.
Related errors
- Error: Azure Cognitive Search credentials not set.
- Error: self._search_index_client not set 1.
- Error: Azure Cognitive Search client not set.
- Error: missing Azure Cognitive Search client credentials.
- Failed to create Azure Cognitive Search settings.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/a1d705384ed2ea81.
Report an issue: GitHub.