Skip to content

.Net: ResponseSchema not working with ForJsonSchema in GeminiPromptExecutionSettings #12313

Open
@RogerBarreto

Description

@RogerBarreto

Discussed in #12234

Originally posted by VladyslavLishchyna May 22, 2025
Hi community! I try to get response from Gemini as JSON object and use like this

GeminiPromptExecutionSettings executionSettings = new()
{
    FunctionChoiceBehavior = FunctionChoiceBehavior.None(),
    ResponseMimeType = "application/json",
    ResponseSchema = ChatResponseFormat.ForJsonSchema(jsonSchema)
};

And have 400 status code

Exception while start application - Microsoft.SemanticKernel.HttpOperationException: Response status code does not indicate success: 400 (Bad Request).
 ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()

Schema looks like:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Response",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "FirstProperty": {
      "type": "integer",
      "format": "int32"
    },
    "Summary": {
      "type": "string"
    }
  }
}

If I run without ResponseSchema parameter I receive response successfully

Metadata

Metadata

Assignees

Labels

.NETIssue or Pull requests regarding .NET codeai connectorAnything related to AI connectors

Type

No type

Projects

Status

Bug

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions