{"record":{"id":"ce4888f0f6778d6e","repo":"microsoft/semantic-kernel","slug":"property-schema-is-not-initialized-in-json-schem","errorCode":null,"errorMessage":"Property 'schema' is not initialized in JSON schema response format.","messagePattern":"Property 'schema' is not initialized in JSON schema response format\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.OpenAI/Helpers/OpenAIChatResponseFormatBuilder.cs","lineNumber":39,"sourceCode":"        {\n            DisallowAdditionalProperties = true,\n            RequireAllProperties = true,\n            MoveDefaultKeywordToDescription = true,\n        }\n    };\n\n    /// <summary>\n    /// Gets instance of <see cref=\"ChatResponseFormat\"/> object for JSON schema format for structured outputs from <see cref=\"JsonElement\"/>.\n    /// </summary>\n    internal static ChatResponseFormat GetJsonSchemaResponseFormat(JsonElement responseFormatElement)\n    {\n        const string DefaultSchemaName = \"JsonSchema\";\n\n        if (responseFormatElement.TryGetProperty(\"type\", out var typeProperty) &&\n            typeProperty.GetString()?.Equals(\"json_schema\", StringComparison.Ordinal) is true &&\n            responseFormatElement.TryGetProperty(\"json_schema\", out var jsonSchemaProperty))\n        {\n            string schema = jsonSchemaProperty.TryGetProperty(\"schema\", out var schemaProperty) ? schemaProperty.ToString() : throw new ArgumentException(\"Property 'schema' is not initialized in JSON schema response format.\");\n            string? schemaName = jsonSchemaProperty.TryGetProperty(\"name\", out var nameProperty) ? nameProperty.GetString() : DefaultSchemaName;\n            bool? isStrict = jsonSchemaProperty.TryGetProperty(\"strict\", out var isStrictProperty) && isStrictProperty.ValueKind == JsonValueKind.True ? true : null;\n\n            BinaryData schemaBinaryData = new(Encoding.UTF8.GetBytes(schema));\n\n            return ChatResponseFormat.CreateJsonSchemaFormat(schemaName, schemaBinaryData, jsonSchemaIsStrict: isStrict);\n        }\n\n        return ChatResponseFormat.CreateJsonSchemaFormat(\n            DefaultSchemaName,\n            new BinaryData(Encoding.UTF8.GetBytes(responseFormatElement.ToString())));\n    }\n\n    /// <summary>\n    /// Gets instance of <see cref=\"ChatResponseFormat\"/> object for JSON schema format for structured outputs from type.\n    /// </summary>\n    internal static ChatResponseFormat GetJsonSchemaResponseFormat(Type formatObjectType)\n    {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.OpenAI/Helpers/OpenAIChatResponseFormatBuilder.cs#L21-L57","documentation":"When building a ChatResponseFormat for structured outputs, the connector looks for a json_schema object containing a 'schema' property. If type is 'json_schema' but the nested json_schema object lacks a 'schema' key, ArgumentException is thrown — the schema definition is mandatory for structured-output mode. The 'name' and 'strict' properties are optional.","triggerScenarios":"Providing a response format JSON element with {\"type\":\"json_schema\",\"json_schema\":{\"name\":\"MySchema\"}} but no actual \"schema\" field defining the JSON Schema. Common when building the format programmatically and forgetting the schema body.","commonSituations":"Constructing a JSON-schema response format from partial configuration where only name/strict are set. Migrating from a response_format that used a bare schema at the top level to the nested json_schema envelope. Schema validation libraries producing a different property name.","solutions":["Ensure the json_schema object includes a 'schema' property whose value is the full JSON Schema definition object.","Validate the structure before passing: type must be 'json_schema', and json_schema.schema must be present and non-empty.","If you don't need strict structured outputs, use a simpler response format instead."],"exampleFix":"// before — missing schema body\nvar format = JsonSerializer.SerializeToElement(new {\n    type = \"json_schema\",\n    json_schema = new { name = \"MyResponse\" }  // no schema!\n});\n\n// after — include the schema definition\nvar format = JsonSerializer.SerializeToElement(new {\n    type = \"json_schema\",\n    json_schema = new {\n        name = \"MyResponse\",\n        schema = new {\n            type = \"object\",\n            properties = new { answer = new { type = \"string\" } },\n            required = new[] { \"answer\" }\n        }\n    }\n});","handlingStrategy":"validation","validationCode":"void ValidateJsonSchemaFormat(JsonElement element)\n{\n    if (element.TryGetProperty(\"type\", out var t) &&\n        t.GetString() == \"json_schema\" &&\n        element.TryGetProperty(\"json_schema\", out var js) &&\n        !js.TryGetProperty(\"schema\", out _))\n    {\n        throw new ArgumentException(\"json_schema response format requires a 'schema' property.\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try { var format = OpenAIChatResponseFormatBuilder.GetJsonSchemaResponseFormat(element); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"schema\"))\n{\n    // Log and provide a fallback schema or use a non-schema response format\n    logger.LogError(\"JSON schema response format missing 'schema' property: {Msg}\", ex.Message);\n    throw;\n}","preventionTips":["When constructing json_schema formats programmatically, always include the 'schema' body.","Unit-test the response-format JSON structure before sending it to the API.","Treat 'name' as optional but 'schema' as mandatory in structured-output configs."],"tags":["structured-output","json-schema","validation","chat-completions"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}