google / google/adk-web

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

Open
#67 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1k
Forks
267
Avg merge
1d 12h
Merged PRs (30d)
9

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.