microsoft/semantic-kernel · error · ArgumentException
Data is not available for {cityName}.
Error message
Data is not available for {cityName}. What it means
Thrown by GetWeatherForCity — a Semantic Kernel / OpenAI Realtime function-call handler — when the city name argument doesn't match any entry in the hardcoded switch expression. The function only recognizes eight cities (Boston, London, Miami, Paris, Tokyo, Sydney, Tel Aviv, San Francisco) and rejects everything else with an ArgumentException.
Source
Thrown at dotnet/samples/Demos/OpenAIRealtime/Program.cs:305
/// <summary>A sample plugin to get a weather.</summary>
private sealed class WeatherPlugin
{
[KernelFunction]
[Description("Gets the current weather for the specified city in Fahrenheit.")]
public static string GetWeatherForCity([Description("City name without state/country.")] string cityName)
{
return cityName switch
{
"Boston" => "61 and rainy",
"London" => "55 and cloudy",
"Miami" => "80 and sunny",
"Paris" => "60 and rainy",
"Tokyo" => "50 and sunny",
"Sydney" => "75 and sunny",
"Tel Aviv" => "80 and sunny",
"San Francisco" => "70 and sunny",
_ => throw new ArgumentException($"Data is not available for {cityName}."),
};
}
}
#region Helpers
/// <summary>Helper method to parse a function name for compatibility with Semantic Kernel plugins/functions.</summary>
private static (string FunctionName, string? PluginName) ParseFunctionName(string fullyQualifiedName)
{
const string FunctionNameSeparator = "-";
string? pluginName = null;
string functionName = fullyQualifiedName;
int separatorPos = fullyQualifiedName.IndexOf(FunctionNameSeparator, StringComparison.Ordinal);
if (separatorPos >= 0)
{
pluginName = fullyQualifiedName.AsSpan(0, separatorPos).Trim().ToString();View on GitHub (pinned to c028a0c7dc)
Solutions
- Add the missing city as a new switch arm with appropriate weather data or a live weather API call.
- Return a user-friendly 'weather data unavailable for {cityName}' string instead of throwing, so the conversation can continue.
- Replace the hardcoded switch with a call to a real weather API (e.g., OpenWeatherMap) so all cities are supported.
- Strengthen the function [Description] to list supported cities, reducing the chance the model calls it with an unsupported one.
Example fix
// before
_ => throw new ArgumentException($"Data is not available for {cityName}."),
// after — graceful fallback so the realtime conversation can recover
_ => $"Sorry, I don't have weather data for {cityName}.", Defensive patterns
Strategy: validation
Validate before calling
// Validate the city before calling, or handle the default case gracefully
static readonly HashSet<string> SupportedCities = new() { "Boston", "London", "Miami", "Paris", "Tokyo", "Sydney", "Tel Aviv", "San Francisco" };
if (!SupportedCities.Contains(cityName))
return $"Weather data is not available for {cityName}."; Type guard
bool IsCitySupported(string city) => city is "Boston" or "London" or "Miami" or "Paris" or "Tokyo" or "Sydney" or "Tel Aviv" or "San Francisco";
Try / catch
try { var weather = GetWeatherForCity(city); } catch (ArgumentException) { weather = $"Weather data unavailable for {city}."; } Prevention
- Document supported values in the function [Description] so the LLM is less likely to call with unsupported inputs.
- Prefer returning a string message over throwing for expected runtime variation.
- Consider an enum or validation set to constrain inputs.
When it happens
Trigger: The realtime model invokes GetWeatherForCity with a city string not present in the switch (e.g., 'Dublin', 'Seattle', or a city with extra qualifiers like 'Boston, MA'). Any default-case argument triggers the throw.
Common situations: The LLM hallucinates or invents a city name; the user asks for weather in an unsupported city; the model passes a city with a state/country suffix despite the [Description] hint; the function is reused in a context where more cities are expected.
Related errors
- OpenAI/Azure OpenAI configuration was not found.
- The input audio content is not readable.
- No function result provided in the tool message.
- {nameof(executionSettings.ToolCallBehavior)} and {nameof(exe
- Unsupported function choice '{config.Choice}'.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/1345d4f19664e129.
Report an issue: GitHub.