Summarize Topic with AI loads indefinitely, Invalid JSON Payload Received?

AI-generated summary

Users reported that the Topic summary AI feature on their Discourse forum was hanging indefinitely, while other AI tools like Summarization Gists and AI Composer Helper worked fine. KhoiUSA shared logs showing a 400 error from Google’s Gemini API, citing an invalid JSON payload due to an unrecognized field json_schema in the request. After Falco asked which model was in use, KhoiUSA confirmed using Gemini 2.0 Flash (free tier). Falco suggested switching the provider to OpenAI and using the endpoint https://generativelanguage.googleapis.com/v1beta/chat/completions, which resolved the issue for KhoiUSA. sam noted this still indicates a bug, suggesting the system should gracefully fallback to plain text if JSON is expected but not returned. Falco agreed and confirmed the issue was isolated to the Google API. Roman later confirmed the bug was fixed in PR #1340, which corrected the JSON schema format expectation and added fallback behavior to treat malformed JSON responses as plain text. The fix ensures resilience when models fail to return valid JSON as requested.

Hello, recently I have noticed that the Topic summary function on my forum has seemingly stopped working entirely, with requests to generate a topic summary hanging indefenitely. It is notable that the other AI tools on the site are working properly such as Summarization Gists and AI Composer Helper.

Below is an image of the Topic summary modal seemingly hanging:

Here is a log entry that appears to be related:

DiscourseAi::Completions::Endpoints::Gemini: status: 400 - body: {
  "error": {
    "code": 400,
    "message": "Invalid value at 'generation_config.response_schema.type' (type.googleapis.com/google.ai.generativelanguage.v1beta.Type), \"json_schema\"\nInvalid JSON payload received. Unknown name \"json_schema\" at 'generation_config.response_schema': Cannot find field.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "generation_config.response_schema.type",
            "description": "Invalid value at 'generation_config.response_schema.type' (type.googleapis.com/google.ai.generativelanguage.v1beta.Type), \"json_schema\""
          },
          {
            "field": "generation_config.response_schema",
            "description": "Invalid JSON payload received. Unknown name \"json_schema\" at 'generation_config.response_schema': Cannot find field."
          }
        ]
      }
    ]
  }
}

Has anyone else encountered this issue or have an idea on how to resolve this? Thanks in advance.

What model are you using?

1 Like

I am currently using Gemini 2.0 Flash, free tier.

1 Like

Can you try setting provider to “OpenAI” and the endpoint to https://generativelanguage.googleapis.com/v1beta/chat/completions ?

1 Like

I have done the steps you gave and I can confirm the LLM is now working as expected. Thanks!

1 Like

Very happy it is sorted, but I still think there is a bug here we should sort out @Falco / @Roman

Stuff should maybe fallback if for any reason a model says it will return JSON but does not. This is one area we should eval.

1 Like

Oh definitely, I wanted to help isolate it to the Google API instead of the model so we can work on a fix this week.

4 Likes

The Gemini error was fixed in:

https://github.com/discourse/discourse-ai/pull/1340

It was expecting a slightly different format for the JSON schema. Also, we’ll now treat the completion as plain text if the model doesn’t return valid JSON when asked to.

5 Likes

This topic was automatically closed after 2 days. New replies are no longer allowed.