{"record":{"id":"1345d4f19664e129","repo":"microsoft/semantic-kernel","slug":"data-is-not-available-for-cityname","errorCode":null,"errorMessage":"Data is not available for {cityName}.","messagePattern":"Data is not available for (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/Demos/OpenAIRealtime/Program.cs","lineNumber":305,"sourceCode":"\n    /// <summary>A sample plugin to get a weather.</summary>\n    private sealed class WeatherPlugin\n    {\n        [KernelFunction]\n        [Description(\"Gets the current weather for the specified city in Fahrenheit.\")]\n        public static string GetWeatherForCity([Description(\"City name without state/country.\")] string cityName)\n        {\n            return cityName switch\n            {\n                \"Boston\" => \"61 and rainy\",\n                \"London\" => \"55 and cloudy\",\n                \"Miami\" => \"80 and sunny\",\n                \"Paris\" => \"60 and rainy\",\n                \"Tokyo\" => \"50 and sunny\",\n                \"Sydney\" => \"75 and sunny\",\n                \"Tel Aviv\" => \"80 and sunny\",\n                \"San Francisco\" => \"70 and sunny\",\n                _ => throw new ArgumentException($\"Data is not available for {cityName}.\"),\n            };\n        }\n    }\n\n    #region Helpers\n\n    /// <summary>Helper method to parse a function name for compatibility with Semantic Kernel plugins/functions.</summary>\n    private static (string FunctionName, string? PluginName) ParseFunctionName(string fullyQualifiedName)\n    {\n        const string FunctionNameSeparator = \"-\";\n\n        string? pluginName = null;\n        string functionName = fullyQualifiedName;\n\n        int separatorPos = fullyQualifiedName.IndexOf(FunctionNameSeparator, StringComparison.Ordinal);\n        if (separatorPos >= 0)\n        {\n            pluginName = fullyQualifiedName.AsSpan(0, separatorPos).Trim().ToString();","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/Demos/OpenAIRealtime/Program.cs#L287-L323","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n_ => throw new ArgumentException($\"Data is not available for {cityName}.\"),\n\n// after — graceful fallback so the realtime conversation can recover\n_ => $\"Sorry, I don't have weather data for {cityName}.\",","handlingStrategy":"validation","validationCode":"// Validate the city before calling, or handle the default case gracefully\nstatic readonly HashSet<string> SupportedCities = new() { \"Boston\", \"London\", \"Miami\", \"Paris\", \"Tokyo\", \"Sydney\", \"Tel Aviv\", \"San Francisco\" };\nif (!SupportedCities.Contains(cityName))\n    return $\"Weather data is not available for {cityName}.\";","typeGuard":"bool IsCitySupported(string city) => city is \"Boston\" or \"London\" or \"Miami\" or \"Paris\" or \"Tokyo\" or \"Sydney\" or \"Tel Aviv\" or \"San Francisco\";","tryCatchPattern":"try { var weather = GetWeatherForCity(city); } catch (ArgumentException) { weather = $\"Weather data unavailable for {city}.\"; }","preventionTips":["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."],"tags":["realtime","openai","function-calling","weather","argument-exception"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}