{"record":{"id":"b020da94198b3e90","repo":"microsoft/autogen","slug":"invalid-name-name-name-must-be-less-than-64-ch-b020da","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/azure/_azure_ai_client.py","lineNumber":177,"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\nclass AzureAIChatCompletionClient(ChatCompletionClient):\n    \"\"\"\n    Chat completion client for models hosted on Azure AI Foundry or GitHub Models.\n    See `here <https://learn.microsoft.com/en-us/azure/ai-studio/reference/reference-model-inference-chat-completions>`_ for more info.\n\n    Args:\n        endpoint (str): The endpoint to use. **Required.**\n        credential (union, AzureKeyCredential, AsyncTokenCredential): The credentials to use. **Required**\n        model_info (ModelInfo): The model family and capabilities of the model. **Required.**\n        model (str): The name of the model. **Required if model is hosted on GitHub Models.**\n        frequency_penalty: (optional,float)\n        presence_penalty: (optional,float)\n        temperature: (optional,float)\n        top_p: (optional,float)\n        max_tokens: (optional,int)","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/models/azure/_azure_ai_client.py#L159-L195","documentation":"Second branch of assert_valid_name in autogen_ext.models.azure._azure_ai_client: raised when a name passes the character check but exceeds 64 characters. Azure AI model/agent names are capped at 64 chars, so the client enforces the limit locally before the request.","triggerScenarios":"Any message source or validated name longer than 64 characters, e.g. auto-generated names that concatenate team name + role + suffix, or names built from document titles.","commonSituations":"Multi-agent frameworks composing long deterministic names; names derived from user input or file names; LLM-generated identifiers that were never truncated.","solutions":["Truncate the name to 64 characters at construction time","Use _normalize_name for LLM-provided names — it already applies [:64]","Switch to short stable slugs (id-based) for internal names and keep long names in display metadata"],"exampleFix":"# before\nname = f\"{team_name}_{role}_{task_id}_worker\"  # may exceed 64 chars\n\n# after\nname = f\"{team_name}_{role}_{task_id}_worker\"[:64]","handlingStrategy":"validation","validationCode":"def name_length_ok(name: str) -> bool:\n    return 0 < len(name) <= 64","typeGuard":"def is_valid_name_length(name: str) -> bool:\n    return len(name) <= 64","tryCatchPattern":null,"preventionTips":["Apply [:64] whenever composing names programmatically","Prefer _normalize_name which truncates and sanitizes in one call","Use short stable ids for internal names"],"tags":["azure","name-validation","length-limit","configuration"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}