{"record":{"id":"fe04962b838f38d4","repo":"microsoft/autogen","slug":"invalid-name-name-name-must-be-less-than-64-ch-fe0496","errorCode":null,"errorMessage":"Invalid name: {name}. Name must be less than 64 characters.","messagePattern":"Invalid name: (.+?)\\. Name must be less than 64 characters\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/models/openai/_utils.py","lineNumber":13,"sourceCode":"import re\n\n\ndef assert_valid_name(name: str) -> str:\n    \"\"\"\n    Ensure that configured names are valid, raises ValueError if not.\n\n    For munging LLM responses use _normalize_name to ensure LLM specified names don't break the API.\n    \"\"\"\n    if not re.match(r\"^[a-zA-Z0-9_-]+$\", name):\n        raise ValueError(f\"Invalid name: {name}. Only letters, numbers, '_' and '-' are allowed.\")\n    if len(name) > 64:\n        raise ValueError(f\"Invalid name: {name}. Name must be less than 64 characters.\")\n    return name\n","sourceCodeStart":1,"sourceCodeEnd":15,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/models/openai/_utils.py#L1-L15","documentation":"Thrown by assert_valid_name in autogen_ext.models.openai._utils when a configured name is longer than 64 characters. Even if the character set is valid, the length cap (mirroring API-side identifier limits) is enforced client-side before the name reaches the provider.","triggerScenarios":"Passing a name that passes the character regex but exceeds 64 chars — e.g. auto-generated tool names combining module paths, class names, and suffixes, or long descriptive agent identifiers.","commonSituations":"Programmatically composed names (f'{module}_{class}_{method}') growing past 64 chars; names embedding UUIDs or long slugs; copy-pasted fully-qualified identifiers.","solutions":["Shorten the name to <= 64 characters (abbreviate or drop path segments)","Derive a stable short name, e.g. hashlib-based: name[:64] or a slug of the full name","Add a length check in name-generation code so long names fail loudly at build time"],"exampleFix":"# before\ntool_name = f\"{module_path}_{klass}_{method}\"  # 80+ chars\nassert_valid_name(tool_name)  # ValueError\n\n# after\ntool_name = f\"{module_path}_{klass}_{method}\"[:64]\nassert_valid_name(tool_name)","handlingStrategy":"validation","validationCode":"name = name[:64]  # enforce cap before use\nassert is_valid_name(name)","typeGuard":"def is_valid_name(name: str) -> bool:\n    import re\n    return bool(re.fullmatch(r\"[a-zA-Z0-9_-]{1,64}\", name))","tryCatchPattern":"try:\n    assert_valid_name(name)\nexcept ValueError as e:\n    if \"64 characters\" in str(e):\n        name = name[:64]\n        assert_valid_name(name)\n    else:\n        raise","preventionTips":["Cap auto-generated names at construction ([:64]) instead of hoping they stay short","For collisions after truncation, add a short hash suffix instead of more path segments","Log full original names alongside the truncated ones for traceability"],"tags":["openai","naming","validation","length-limit"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}