{"record":{"id":"5877d8c8c845c0ec","repo":"microsoft/autogen","slug":"invalid-configuration-str-e","errorCode":null,"errorMessage":"Invalid configuration: {str(e)}","messagePattern":"Invalid configuration: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/tools/azure/_ai_search.py","lineNumber":631,"sourceCode":"            result_strings.append(f\"Result {i} (Score: {result.score:.2f}): {content_str}\")\n\n        return \"\\n\".join(result_strings)\n\n    @classmethod\n    def _validate_config(\n        cls, config_dict: Dict[str, Any], search_type: Literal[\"full_text\", \"vector\", \"hybrid\"]\n    ) -> None:\n        \"\"\"Validate configuration for specific search types.\"\"\"\n        credential = config_dict.get(\"credential\")\n        if isinstance(credential, str):\n            raise TypeError(\"Credential must be AzureKeyCredential, AsyncTokenCredential, or a valid dict\")\n        if isinstance(credential, dict) and \"api_key\" not in credential:\n            raise ValueError(\"If credential is a dict, it must contain an 'api_key' key\")\n\n        try:\n            _ = AzureAISearchConfig(**config_dict)\n        except Exception as e:\n            raise ValueError(f\"Invalid configuration: {str(e)}\") from e\n\n        if search_type == \"vector\":\n            vector_fields = config_dict.get(\"vector_fields\")\n            if not vector_fields or len(vector_fields) == 0:\n                raise ValueError(\"vector_fields must contain at least one field name for vector search\")\n\n        elif search_type == \"hybrid\":\n            vector_fields = config_dict.get(\"vector_fields\")\n            search_fields = config_dict.get(\"search_fields\")\n\n            if not vector_fields or len(vector_fields) == 0:\n                raise ValueError(\"vector_fields must contain at least one field name for hybrid search\")\n\n            if not search_fields or len(search_fields) == 0:\n                raise ValueError(\"search_fields must contain at least one field name for hybrid search\")\n\n    @classmethod\n    @abstractmethod","sourceCodeStart":613,"sourceCodeEnd":649,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/tools/azure/_ai_search.py#L613-L649","documentation":"After the cheap credential pre-checks, _validate_config trial-constructs AzureAISearchConfig(**config_dict). If the pydantic model rejects any field (missing required field, wrong type, endpoint not http(s), top <= 0, semantic/vector interdependent rules), the pydantic ValidationError is wrapped into ValueError('Invalid configuration: <details>').","triggerScenarios":"Any factory constructor call whose kwargs fail AzureAISearchConfig validation: missing name/endpoint/index_name, endpoint without http(s)://, top=0 or negative, query_type='semantic' without semantic_config_name, query_type='vector' without vector_fields, wrong type for a list field.","commonSituations":"Typos in kwarg names (e.g. index instead of index_name) that become unexpected/missing fields; endpoint passed without scheme; drift between the factory signature and the config model after a library upgrade.","solutions":["Read the wrapped message — it contains the underlying pydantic error verbatim, naming the offending field.","Construct AzureAISearchConfig(...) directly in a test to iterate on validation errors quickly, then move the corrected values into the tool factory call.","Check required fields (name, endpoint, index_name, credential) and the interdependent rules (semantic → semantic_config_name; vector → vector_fields).","After upgrading autogen-ext, diff the factory signature and AzureAISearchConfig field list for renames."],"exampleFix":"# before\nAzureAISearchTool(name='s', endpoint='svc.search.windows.net', index_name='idx', credential=cred)\n# after (endpoint needs scheme; error text will say exactly which field failed)\nAzureAISearchTool(name='s', endpoint='https://svc.search.windows.net', index_name='idx', credential=cred)","handlingStrategy":"validation","validationCode":"from autogen_ext.tools.azure._config import AzureAISearchConfig\n\ndef config_dict_is_valid(config_dict: dict) -> bool:\n    try:\n        AzureAISearchConfig(**config_dict)\n        return True\n    except Exception:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    tool = await AzureAISearchTool.create_(...)\nexcept ValueError as e:\n    if str(e).startswith('Invalid configuration:'):\n        # str(e) embeds the pydantic error naming the bad field — log and surface it\n        log.error('Bad search tool config: %s', e)\n    raise","preventionTips":["Dry-run AzureAISearchConfig(**kwargs) in unit tests for every config shape you ship.","Type your config dicts (TypedDict/dataclass) instead of building ad-hoc dicts at call sites.","Check required fields (name, endpoint, index_name, credential) and interdependent rules before calling factories."],"tags":["azure","azure-ai-search","configuration","pydantic","validation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}