microsoft/semantic-kernel · error · ArgumentException
A function name can contain only ASCII letters, digits, dash
Error message
A function name can contain only ASCII letters, digits, dashes and underscores: '{name}' is not a valid name. What it means
Thrown by MistralFunction.ValidFunctionName when the function name does not match the pattern ^[0-9A-Za-z_-]*$ or exceeds 64 characters. Mistral's tool/function API only accepts names containing ASCII letters, digits, dashes, and underscores. This is an ArgumentException during tool registration.
Source
Thrown at dotnet/src/Connectors/Connectors.MistralAI/Client/MistralFunction.cs:114
#region private
#if NET
[GeneratedRegex("^[0-9A-Za-z_-]*$")]
private static partial Regex AsciiLettersDigitsUnderscoresRegex();
#else
private static Regex AsciiLettersDigitsUnderscoresRegex() => s_asciiLettersDigitsUnderscoresRegex;
private static readonly Regex s_asciiLettersDigitsUnderscoresRegex = new("^[0-9A-Za-z_-]*$");
#endif
private static void ValidFunctionName(string name)
{
Verify.NotNull(name, nameof(name));
Verify.True(name.Length <= 64, "The name of the function must be less than or equal to 64 characters.", nameof(name));
if (!AsciiLettersDigitsUnderscoresRegex().IsMatch(name))
{
throw new ArgumentException($"A function name can contain only ASCII letters, digits, dashes and underscores: '{name}' is not a valid name.");
}
}
private static MistralParameters ToMistralParameters(KernelFunctionMetadata metadata)
{
var parameters = new MistralParameters();
if (metadata.Parameters is { Count: > 0 })
{
foreach (var parameter in metadata.Parameters)
{
parameters.Properties.Add(parameter.Name, parameter.Schema ?? GetDefaultSchemaForTypelessParameter(parameter.Description));
if (parameter.IsRequired)
{
parameters.Required.Add(parameter.Name);
}
}
}View on GitHub (pinned to c028a0c7dc)
Solutions
- Rename the KernelFunction to use only [A-Za-z0-9_-] and keep it under 64 characters.
- Use the KernelFunction attribute or method overloads to override the exposed name: [KernelFunction("get_user_info")].
- Sanitize function names before registering the plugin with Mistral.
Example fix
// before
[KernelFunction("Get User Info")]
public string GetUserInfo() { ... }
// after
[KernelFunction("get_user_info")]
public string GetUserInfo() { ... } Defensive patterns
Strategy: validation
Validate before calling
static readonly Regex ValidName = new(@"^[0-9A-Za-z_-]{1,64}$");
if (!ValidName.IsMatch(functionName))
throw new InvalidOperationException($"Invalid function name: {functionName}"); Type guard
static bool IsValidMistralFunctionName(string name) =>
!string.IsNullOrEmpty(name) && name.Length <= 64 &&
Regex.IsMatch(name, @"^[0-9A-Za-z_-]*$"); Prevention
- Use snake_case or kebab-case for function names exposed to LLMs.
- Apply [KernelFunction("sanitized_name")] when C# method names are unsuitable.
- Sanitize auto-generated function names before registration.
When it happens
Trigger: Registering a KernelFunction whose name contains spaces, dots, parentheses, non-ASCII (Unicode) characters, or is longer than 64 characters; importing a plugin with C# method names that include special characters.
Common situations: Plugin method names with dots like 'Get.User.Info'; localized function names with accented characters; auto-generated function names from descriptions or prompts that include spaces; very long descriptive method names.
Related errors
- Auto-invocation of tool calls may only be used with a {nameo
- The specified {nameof(EnabledFunctions)} function {func.Full
- Function description is required. Please provide a descripti
- Chat history must contain at least one message
- The first message in chat history must have either the syste
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/0b86cb7c3b36ea89.
Report an issue: GitHub.