Skip to content

Issue with Google structured response #44

@rsJames-ttrpg

Description

@rsJames-ttrpg

To Reproduce:
A request with the schema property fails with a 400
One without succeeds.
Same API Key same code just removed the schema property on the request

        let builder = LLMBuilder::new()
            .backend(self.model.provider())
            .api_key(&self.api_key)
            .model(self.model.to_string())
            .max_tokens(self.max_tokens)
            .temperature(self.temperature)
            .stream(false)
            .system("DO thing")
            .schema(output_schema);

fails with 400

        let builder = LLMBuilder::new()
            .backend(self.model.provider())
            .api_key(&self.api_key)
            .model(self.model.to_string())
            .max_tokens(self.max_tokens)
            .temperature(self.temperature)
            .stream(false)
            .system("DO thing");

That does the thing.
This is using gemini-2.0-flash with which I have verified works with curl.

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=$GOOGLE_KEY" -H 'Content-Type: application/json' -d '{
      "contents": [{
        "parts":[
          { "text": "List a few popular cookie recipes, and include the amounts of ingredients." }
        ]
      }],
      "generationConfig": {
        "responseMimeType": "application/json",
        "responseSchema": {
          "type": "ARRAY",
          "items": {
            "type": "OBJECT",
            "properties": {
              "recipeName": { "type": "STRING" },
              "ingredients": {
                "type": "ARRAY",
                "items": { "type": "STRING" }
              }
            },
            "propertyOrdering": ["recipeName", "ingredients"]
          }
        }
      }
}' 2> /dev/null | head

It works for Anthropic and Deepseek v3-coder
Not tried with Open AI

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions