adk-web icon indicating copy to clipboard operation
adk-web copied to clipboard

Gracefully handle Gemini's failure to generate a response due to MAX_TOKEN finish reason

Open slilichenko opened this issue 6 months ago • 0 comments

Sometimes Gemini models generate a response like this:

{
  "candidates": [
    {
      "content": {
        "role": "model"
      },
      "finishReason": "MAX_TOKENS"
    }
  ],
  "createTime": "2025-06-12T20:56:46.627184Z",
  "modelVersion": "gemini-2.5-pro-preview-05-06",
  "responseId": "Dj9LaPCjJsCvgLUPgeGuqAU",
  "usageMetadata": {
    "billablePromptUsage": {
      "textCount": 5080
    },
    "promptTokenCount": 1706,
    "promptTokensDetails": [
      {
        "modality": "TEXT",
        "tokenCount": 1706
      }
    ],
    "thoughtsTokenCount": 2999,
    "totalTokenCount": 4705,
    "trafficType": "ON_DEMAND"
  }
}

Notice, there is no text parts being produced by the model in this case. ADK Web UI in this case doesn't show anything, just the indicator that it's waiting for the response from the model.

Suggestion - add an indictor to the UI that the model did respond, but that the response is a failure and, ideally, the steps that the user can do to address it.

slilichenko avatar Jun 12 '25 21:06 slilichenko