{"record":{"id":"09099edc599ef8e2","repo":"microsoft/autogen","slug":"invalid-key-value-pair-format-kvstring-expecti","errorCode":null,"errorMessage":"Invalid key-value pair format: {kvString}; expecting \"{keyName}/{valueName}\"","messagePattern":"Invalid key-value pair format: (.+?); expecting \"(.+?)/(.+?)\"","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Microsoft.AutoGen/Contracts/KVStringParseHelper.cs","lineNumber":50,"sourceCode":"    /// </exception>\n    /// <example>\n    /// Example usage:\n    /// <code>\n    /// string input = \"agent1/12345\";\n    /// var result = input.ToKVPair(\"Type\", \"Key\");\n    /// Console.WriteLine(result.Item1); // Outputs: agent1\n    /// Console.WriteLine(result.Item2); // Outputs: 12345\n    /// </code>\n    /// </example>\n    public static (string, string) ToKVPair(this string kvString, string keyName, string valueName)\n    {\n        var match = KVPairRegex.Match(kvString);\n        if (match.Success)\n        {\n            return (match.Groups[\"key\"].Value, match.Groups[\"value\"].Value);\n        }\n\n        throw new FormatException($\"Invalid key-value pair format: {kvString}; expecting \\\"{{{keyName}}}/{{{valueName}}}\\\"\");\n    }\n}\n\n","sourceCodeStart":32,"sourceCodeEnd":54,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/Microsoft.AutoGen/Contracts/KVStringParseHelper.cs#L32-L54","documentation":"KVStringParseHelper.ToKVPair (a string extension) throws FormatException when the input does not match the expected \"key/value\" single-slash format captured by KVPairRegex. It is the standard parser for encoded AgentId/TopicId strings, so any malformed identifier string surfaces here.","triggerScenarios":"Calling kvString.ToKVPair(keyName, valueName) on strings like \"keyvalue\" (no slash), \"a/b/c\" (extra segments, depending on regex), \"/value\", \"key/\", or leading/trailing whitespace variants that fail KVPairRegex.","commonSituations":"Parsing AgentId.ToString() output that was hand-edited or truncated; reading agent/topic identifiers from URLs, query strings, or logs where the separator got mangled (URL encoding turning '/' into %2F); joining type and key with a different separator ('.', ':') by mistake.","solutions":["Fix the producer so the string is exactly type/key with both parts matching the AgentId rules.","If input may be URL-encoded, decode before parsing.","Validate with the same key/value pattern (printable ASCII, no extra slashes) before calling ToKVPair."],"exampleFix":"// before\nvar (type, key) = \"weather_agent%2Fdefault\".ToKVPair(\"type\", \"key\"); // throws: no literal '/'\n\n// after\nvar (type, key) = Uri.UnescapeDataString(\"weather_agent%2Fdefault\").ToKVPair(\"type\", \"key\");","handlingStrategy":"try-catch","validationCode":"static readonly Regex KVPairRx = new(\"^[^/]+/[^/]+$\");\nbool IsParsableKV(string? s) => s is not null && KVPairRx.IsMatch(s);","typeGuard":"static bool IsParsableKV(string? s) => s is not null && Regex.IsMatch(s, \"^[^/]+/[^/]+$\");","tryCatchPattern":"try { var (k, v) = s.ToKVPair(\"key\", \"value\"); }\ncatch (FormatException) { /* log and reject the identifier at the boundary */ }","preventionTips":["URL-decode identifier strings before parsing.","Generate identifiers only via AgentId/TopicId ToString so the format is guaranteed."],"tags":["parsing","format-exception","agent-id","topic-id"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}