Skip to content

ChatBase.validateHistory fails for response with finishReason SAFTY #750

@joerg1985

Description

@joerg1985

Environment details

  • Programming language: Java
  • OS: Windows 11
  • Language runtime version: 21
  • Package version: 1.30.0
  • Model: gemini-2.5-flash

Steps to reproduce

  1. Trigger a response with finishReason SAFETY while using the com.google.genai.Chat
  2. The com.google.genai.ChatBase.validateHistory will fail with java.util.NoSuchElementException: No value present as the role of the response is empty. There is no chance for the custom logic to handle the response.
java.util.NoSuchElementException: No value present
java.base/java.util.Optional.get (Optional.java:143)
com.google.genai.ChatBase.validateHistory (ChatBase.java:130)
com.google.genai.ChatBase.recordHistory (ChatBase.java:55)
com.google.genai.ChatBase.updateHistoryNonStreaming (ChatBase.java:258)
com.google.genai.Chat.privateSendMessage (Chat.java:149)
com.google.genai.Chat.sendMessage (Chat.java:104)

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.status:awaiting user responsestatus:staletype: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions