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

  1. Add the missing city as a new switch arm with appropriate weather data or a live weather API call.
  2. Return a user-friendly 'weather data unavailable for {cityName}' string instead of throwing, so the conversation can continue.
  3. Replace the hardcoded switch with a call to a real weather API (e.g., OpenWeatherMap) so all cities are supported.
  4. 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

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


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/1345d4f19664e129. Report an issue: GitHub.