microsoft/autogen · error · ValueError
Invalid name: {name}. Name must be less than 64 characters.
Error message
Invalid name: {name}. Name must be less than 64 characters. What it means
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.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/models/openai/_utils.py:13
import re
def assert_valid_name(name: str) -> str:
"""
Ensure that configured names are valid, raises ValueError if not.
For munging LLM responses use _normalize_name to ensure LLM specified names don't break the API.
"""
if not re.match(r"^[a-zA-Z0-9_-]+$", name):
raise ValueError(f"Invalid name: {name}. Only letters, numbers, '_' and '-' are allowed.")
if len(name) > 64:
raise ValueError(f"Invalid name: {name}. Name must be less than 64 characters.")
return name
View on GitHub (pinned to 027ecf0a37)
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
Example fix
# before
tool_name = f"{module_path}_{klass}_{method}" # 80+ chars
assert_valid_name(tool_name) # ValueError
# after
tool_name = f"{module_path}_{klass}_{method}"[:64]
assert_valid_name(tool_name) Defensive patterns
Strategy: validation
Validate before calling
name = name[:64] # enforce cap before use assert is_valid_name(name)
Type guard
def is_valid_name(name: str) -> bool:
import re
return bool(re.fullmatch(r"[a-zA-Z0-9_-]{1,64}", name)) Try / catch
try:
assert_valid_name(name)
except ValueError as e:
if "64 characters" in str(e):
name = name[:64]
assert_valid_name(name)
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: Programmatically composed names (f'{module}_{class}_{method}') growing past 64 chars; names embedding UUIDs or long slugs; copy-pasted fully-qualified identifiers.
Related errors
- Invalid name: {name}. Only letters, numbers, '_' and '-' are
- Unsupported config type {config.GetType()}
- Messages should not be provided in options
- Parameter name cannot be null
- Unknown message type: {m.GetType()}
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/fe04962b838f38d4.
Report an issue: GitHub.