35
Views
8
Comments
Agent Workbench - Error using Gemini with Structured Output
Question

Hi all,

I’ve recently built an agent using Agent Workbench, configured with Gemini Flash 2.5 as the underlying model. 

The agent works as expected when using unstructured output: prompts are processed correctly and the model returns valid, coherent responses. 

However, I’m encountering an issue when enabling structured output on the Call Agent. In this case, the request consistently fails with a Bad Request error from Gemini. The same prompt that works without structure fails immediately when structured output is enabled. 

Configuration:


So, basically, what I have is, for same system prompt, user message and grounding data: 

Gemini Flash 2.5 + Agent Workbench + unstructured output = works correctly 

Gemini Flash 2.5 + Agent Workbench + structured output = Bad Request 

I’m trying to understand whether this is: 

- A limitation or incompatibility with Gemini Flash 2.5 

- A schema or formatting requirement that’s being violated 

- Or a bug in Agent Workbench’s handling of structured outputs with this model 

If anyone has run into a similar issue or has guidance on using structured outputs in Agent Workbench, I’d really appreciate any insights.

Thank you.

2025-12-22 13-50-43
Sherif El-Habibi
Champion

Hello,

Did you try changing the structure to use text only, without including documents? You can test this to see if it works.

Another thing to check is the Gemini response. Look at how it’s structured and try to follow the same structure in your implementation.

2025-10-27 17-00-45
Francisco Melo

Hello,

The structure is text only. Documents is only the name of the field.

The thing is that, when I define a structure output on OS Agent, it fails right away, the Gemini response is a Bad Request. 

If I remove the structure output from OS Agent, works fine but I want to define the output structure. to make sure I get those fields from AI model.

I've also tested it directly in Google AI Studio, and a structured output with the prompt I have works fine.

Best,

Francisco


2025-12-22 13-50-43
Sherif El-Habibi
Champion

In that case, there’s one approach I’d take, even though it requires a bit of effort: trial and error.

I’d start with the simplest case. First, choose the shortest or simplest structure and try to debug it. You might get a quick error message that clearly explains what’s wrong. Since the only thing the structure can really cause here is a mapping error, there isn’t much else to consider.

If it still fails, I’d start manipulating the structure step by step. For example, remove the nested structure inside the main one and replace it with simple attributes, then test again. If the error persists, remove more fields and try again, perhaps keeping only something like a title and a date. The title is unlikely to be an issue, but the date could be.

If that works, then the nested structure is probably the problem. From there, you can gradually add things back until the error reappears.

I know it sounds a bit like “old-school” debugging, but honestly, it works.

2025-10-27 17-00-45
Francisco Melo

Done some of that "old-school" testing.

Apparently, from a quick test, Structured Output definition on Agent Workbench is limited to one level structures.

Works:

Doesn't work - Bad Request:


It's a little bit limiting, specially considering that Gemini itself allows for this type of structures to be defined. I think it should be fixed by OutSystems. 

(as well as the size of error messages it stores - it is cutting out most of the error response from Gemini: Failed to call AI model. Status code: BadRequest. The Google Gemini AI model provider returned this message: "GeminiException BadRequestError - {" (OS-ABRS-FM-40001)  )

Will have to work around it without Structured Outputs because a simple structure does not fit my use case.

Thanks for the help.


2025-12-22 13-50-43
Sherif El-Habibi
Champion

No problem, you’re very welcome.

You could make one final attempt, try making the description more accurate and explicit. For example, for ResponseStructText, you can describe it like: “This is a structure inside the main response structure for <specific purpose>.”

Sometimes being clearer in the description helps the platform or the AI model interpret it correctly, and it may handle the nested structure differently.

2025-10-27 17-00-45
Francisco Melo

I can try that, but it shouldn't change the outcome since the problem seems to be on the way OutSystems is processing and then formatting structures of type "object" for the OpenAPI schema.

However, it is not possible on Agent Workbench to see the request being sent to the AI model (which maybe should also be an improvement for OutSystems).

This is what should look like for Gemini (or any model adhering to OpenAI schema) to be able to process it, according to Google AI Studio:

{

  "type": "object",

  "properties": {

    "TestStructureOutput": {

      "type": "object",

      "properties": {

        "MainResponseText": {

          "type": "string"

        },

        "ResponseTextStruct": {

          "type": "object",

          "properties": {

            "Text": {

              "type": "string"

            }

          },

          "propertyOrdering": [

            "Text"

          ]

        }

      },

      "propertyOrdering": [

        "MainResponseText",

        "ResponseTextStruct"

      ]

    }

  },

  "propertyOrdering": [

    "TestStructureOutput"

  ]

}

UserImage.jpg
Jayaprakash Ramesh

Hi,

Thanks for sharing the screenshot, that helps clarify the setup.

Based on what’s shown, the configuration itself looks correct, and the behavior you’re seeing aligns with how Gemini Flash 2.5 currently handles structured outputs. When you enable Structured output in Agent Workbench, the platform sends a strict response schema to Gemini. With Flash models, schema validation is very strict, and even small issues can result in an immediate Bad Request.

2025-10-27 17-00-45
Francisco Melo

Hello,

Thanks you for your reply.

I manage to get a subscription to use ChatGPT 5-mini API and tried to use that one instead and indeed seems that with this model the Structured Output works.

Apparently, it really is a Agent Workbench struggle with Gemini Flash.

Thank you for the suggestion.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.