{"record":{"id":"c46ce9530e66c7b0","repo":"run-llama/llama_index","slug":"name-is-none","errorCode":null,"errorMessage":"name is None.","messagePattern":"name is None\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/tools/types.py","lineNumber":59,"sourceCode":"            parameters = {\n                k: v\n                for k, v in parameters.items()\n                if k in [\"type\", \"properties\", \"required\", \"definitions\", \"$defs\"]\n            }\n        return parameters\n\n    @property\n    def fn_schema_str(self) -> str:\n        \"\"\"Get fn schema as string.\"\"\"\n        if self.fn_schema is None:\n            raise ValueError(\"fn_schema is None.\")\n        parameters = self.get_parameters_dict()\n        return json.dumps(parameters, ensure_ascii=False)\n\n    def get_name(self) -> str:\n        \"\"\"Get name.\"\"\"\n        if self.name is None:\n            raise ValueError(\"name is None.\")\n        return self.name\n\n    def _sanitize_name(self, name: Optional[str]) -> Optional[str]:\n        \"\"\"\n        Sanitize name to match OpenAI's function name requirements.\n\n        OpenAI requires function names to match ^[a-zA-Z0-9_-]+$.\n        Generic Pydantic models like GenericModel[int] contain brackets\n        which are not allowed.\n        \"\"\"\n        if name is None:\n            return None\n        return re.sub(r\"[^a-zA-Z0-9_-]\", \"_\", name)\n\n    @deprecated(\n        \"Deprecated in favor of `to_openai_tool`, which should be used instead.\"\n    )\n    def to_openai_function(self) -> Dict[str, Any]:","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/tools/types.py#L41-L77","documentation":"ToolMetadata.get_name() refuses to return when the name field is None. The name field is Optional in the pydantic model, but most execution paths (tool registration, agent tool-call routing, logging) require a concrete name, so this method fails fast rather than returning None.","triggerScenarios":"Calling tool.metadata.get_name() on metadata constructed without a name, e.g. ToolMetadata(description='...'). Frequently triggered indirectly by agent frameworks that call get_name() on every tool in a list.","commonSituations":"Custom tools built with ToolMetadata where only description was supplied; programmatic tool creation from config dicts where the 'name' key was misspelled; older code upgrading to a LlamaIndex version that added this strict check.","solutions":["Always set name explicitly: ToolMetadata(name='search_docs', description='...').","When creating tools from config, validate required keys ('name', 'description') before constructing ToolMetadata.","Use FunctionTool.from_defaults(fn=fn, name='...') which forwards the name into metadata."],"exampleFix":"# before\n tool = FunctionTool.from_defaults(fn=search, description='search docs')\n agent_tool_name = tool.metadata.get_name()  # ValueError\n\n# after\n tool = FunctionTool.from_defaults(fn=search, name='search_docs', description='search docs')\n agent_tool_name = tool.metadata.get_name()","handlingStrategy":"validation","validationCode":"def require_tool_name(metadata):\n    if getattr(metadata, 'name', None) is None:\n        raise ValueError('ToolMetadata.name is required for agent registration')\n    return metadata.name","typeGuard":"def has_tool_name(metadata) -> bool:\n    return getattr(metadata, 'name', None) is not None","tryCatchPattern":"try:\n    name = tool.metadata.get_name()\nexcept ValueError as e:\n    if 'name is None' in str(e):\n        name = getattr(tool.fn, '__name__', 'anonymous_tool')\n        tool.metadata = tool.metadata.model_copy(update={'name': name})\n    else:\n        raise","preventionTips":["Always pass name= to FunctionTool.from_defaults or ToolMetadata.","Validate tool config keys ('name', 'description') at load time.","Add a smoke test that calls get_name() on every tool your agent registers."],"tags":["tool-metadata","name-required","value-error"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}