{"record":{"id":"34f94befaf740b57","repo":"microsoft/autogen","slug":"invalid-name-name-name-must-be-less-than-64-ch-34f94b","errorCode":null,"errorMessage":"Invalid name: {name}. Name must be less than 64 characters.","messagePattern":"Invalid name: (.+?)\\. Name must be less than 64 characters\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/models/llama_cpp/_llama_cpp_completion_client.py","lineNumber":79,"sourceCode":"def normalize_name(name: str) -> str:\n    \"\"\"\n    LLMs sometimes ask functions while ignoring their own format requirements, this function should be used to replace invalid characters with \"_\".\n\n    Prefer _assert_valid_name for validating user configuration or input\n    \"\"\"\n    return re.sub(r\"[^a-zA-Z0-9_-]\", \"_\", name)[:64]\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\n\ndef convert_tools(\n    tools: Sequence[Tool | ToolSchema],\n) -> List[ChatCompletionTool]:\n    result: List[ChatCompletionTool] = []\n    for tool in tools:\n        if isinstance(tool, Tool):\n            tool_schema = tool.schema\n        else:\n            assert isinstance(tool, dict)\n            tool_schema = tool\n\n        result.append(\n            ChatCompletionTool(\n                type=\"function\",\n                function=ChatCompletionToolFunction(","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/models/llama_cpp/_llama_cpp_completion_client.py#L61-L97","documentation":"Length branch of assert_valid_name in the llama.cpp client: raised when the name matches the allowed charset but is longer than 64 characters. Names validated by this module are capped at 64 chars because that is the limit the llama-cpp backend enforces.","triggerScenarios":"Auto-composed names (team + role + task id) exceeding 64 characters passed as message sources or tool names to LlamaCppChatCompletionClient; long function names generated by an LLM and passed through unmodified.","commonSituations":"Deterministic name builders in orchestration frameworks; names derived from prompts or file paths; concatenating namespaces into tool names.","solutions":["Truncate to 64 characters when constructing names","Use _normalize_name for any LLM-supplied name — it truncates and sanitizes in one step","Prefer short hashed slugs for long identifiers"],"exampleFix":"# before\nname = f\"{namespace}_{role}_{uuid4()}_executor\"  # >64 chars\n\n# after\nname = f\"{namespace}_{role}_{uuid4().hex[:8]}_executor\"[:64]","handlingStrategy":"validation","validationCode":"def truncate_name(name: str, limit: int = 64) -> str:\n    return name[:limit]","typeGuard":"def is_valid_name_len(name: str) -> bool:\n    return len(name) <= 64","tryCatchPattern":null,"preventionTips":["Apply [:64] wherever names are composed","Use _normalize_name for LLM-generated names","Prefer short generated slugs over descriptive long names"],"tags":["llama-cpp","name-validation","length-limit","tools"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}