{"record":{"id":"a1d705384ed2ea81","repo":"microsoft/semantic-kernel","slug":"error-unable-to-create-azure-cognitive-search-cli","errorCode":null,"errorMessage":"Error: unable to create Azure Cognitive Search client.","messagePattern":"Error: unable to create Azure Cognitive Search client\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/azure_cognitive_search/utils.py","lineNumber":79,"sourceCode":"    elif token_credential:\n        token_credential = token_credential\n    elif os.getenv(ENV_VAR_API_KEY):\n        azure_credential = AzureKeyCredential(os.getenv(ENV_VAR_API_KEY))\n    else:\n        raise ServiceInitializationError(\"Error: missing Azure Cognitive Search client credentials.\")\n\n    if azure_credential is None and token_credential is None:\n        raise ServiceInitializationError(\"Error: Azure Cognitive Search credentials not set.\")\n\n    sk_headers = {USER_AGENT: \"Semantic-Kernel\"}\n\n    if azure_credential:\n        return SearchIndexClient(endpoint=service_endpoint, credential=azure_credential, headers=sk_headers)\n\n    if token_credential:\n        return SearchIndexClient(endpoint=service_endpoint, credential=token_credential, headers=sk_headers)\n\n    raise ValueError(\"Error: unable to create Azure Cognitive Search client.\")\n\n\ndef get_index_schema(vector_size: int, vector_search_profile_name: str) -> list:\n    \"\"\"Return the schema of search indexes.\n\n    Args:\n        vector_size (int): The size of the vectors being stored in collection/index.\n        vector_search_profile_name (str): The name of the vector search profile.\n\n    Returns:\n        list: The Azure Cognitive Search schema as list type.\n    \"\"\"\n    return [\n        SimpleField(\n            name=SEARCH_FIELD_ID,\n            type=SearchFieldDataType.String,\n            searchable=True,\n            filterable=True,","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/azure_cognitive_search/utils.py#L61-L97","documentation":"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.","triggerScenarios":"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.","commonSituations":"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`.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Defensive/unreachable under normal flow; ensure a credential is truthy so a\n# SearchIndexClient is returned before reaching this ValueError.\nassert azure_credential or token_credential, \"both credentials falsy unexpectedly\"","typeGuard":"def can_build_client(azure_credential, token_credential) -> bool:\n    return bool(azure_credential) or bool(token_credential)","tryCatchPattern":"try:\n    client = get_search_index_async_client(...)\nexcept ValueError as e:\n    if \"unable to create Azure Cognitive Search client\" in str(e):\n        raise SystemExit(\"unexpected fallthrough; supply valid credentials\") from e\n    raise","preventionTips":["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."],"tags":["azure-cognitive-search","credentials","defensive-guard","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}