Skip to content

Add truncated response handling for Google empty content#171

Merged
Ken Jiang (knjiang) merged 2 commits intomainfrom
04-01-fix_errors_from_when_max_tokens_is_lower_than_1_character_response
Apr 1, 2026
Merged

Add truncated response handling for Google empty content#171
Ken Jiang (knjiang) merged 2 commits intomainfrom
04-01-fix_errors_from_when_max_tokens_is_lower_than_1_character_response

Conversation

@knjiang
Copy link
Copy Markdown
Contributor

@knjiang Ken Jiang (knjiang) commented Apr 1, 2026

your max_tokens value can go lower than the minimum length for responses which generates "empty" responses

@knjiang Ken Jiang (knjiang) marked this pull request as ready for review April 1, 2026 18:35
Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@knjiang Ken Jiang (knjiang) changed the title fix errors from when max_tokens is lower than 1 character response fix errors from when max_tokens is lower than minimum character for response Apr 1, 2026
@knjiang Ken Jiang (knjiang) changed the title fix errors from when max_tokens is lower than minimum character for response Add truncated response handling for Google empty content Apr 1, 2026
Comment on lines +1 to +3
{
"error": "Error: 400 Invalid 'max_output_tokens': integer below minimum value. Expected a value >= 16, but got 1 instead."
} No newline at end of file
Copy link
Copy Markdown
Contributor Author

@knjiang Ken Jiang (knjiang) Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chat completions + responses set a minimum value for max_tokens so you can't go below the minimum value for a single character response.

field: "parts".to_string(),
})?;
let parts = content.parts.unwrap_or_default();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was causing the error:

FAILED test_openai.py::test_max_tokens - Failed: gemini-2.5-flash: BadRequestError: Conversion to universal format failed: Missing required field: parts

the new response is now:

{
  "choices": [
    {
      "finish_reason": "length",
      "index": 0,
      "message": {
        "annotations": [],
        "role": "assistant",
      },
    },
  ],
  "created": 0,
  "id": "chatcmpl-transformed",
  "model": "gemini-2.5-flash",
  "object": "chat.completion",
  "usage": {
    "completion_tokens": 0,
    "prompt_tokens": 10,
    "total_tokens": 10,
  },
}
`;

@knjiang Ken Jiang (knjiang) merged commit 4f8c678 into main Apr 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants