Repository navigation
Description
Observed Behavior
When Gemini blocks the prompt itself (for example for safety), the API returns no candidates and sets prompt_feedback.block_reason. GeminiChatClient turns that into an empty assistant message with finish_reason=None, so it looks like the model just answered with nothing. With streaming, usage is lost too, because usage is only attached to a chunk that has a finish reason.
Expected Behavior
finish_reason should be content_filter, the same as when a candidate stops with SAFETY, and streaming should keep the usage.
Steps to Reproduce
- Get a response from Gemini where the prompt is blocked (no candidates,
prompt_feedback.block_reasonset) - Call
get_responsewith and withoutstream=True - Look at
finish_reasonandusage_details
Minimal Reproduction
import asyncio
from unittest.mock import AsyncMock, MagicMock
from agent_framework import Message
from google.genai import types
from agent_framework_gemini import GeminiChatClient
# What Gemini returns when it blocks the prompt itself: no candidates, only prompt_feedback.
blocked = types.GenerateContentResponse.model_validate({
"promptFeedback": {"blockReason": "SAFETY"},
"usageMetadata": {"promptTokenCount": 8, "totalTokenCount": 8},
})
async def stream():
yield blocked
async def main():
genai = MagicMock()
genai.aio.models.generate_content = AsyncMock(return_value=blocked)
genai.aio.models.generate_content_stream = AsyncMock(return_value=stream())
client = GeminiChatClient(client=genai, model="gemini-2.5-flash")
messages = [Message(role="user", contents=["..."])]
r = await client.get_response(messages)
print("non-streaming:", repr(r.text), r.finish_reason, r.usage_details)
r = await client.get_response(messages, stream=True).get_final_response()
print("streaming: ", repr(r.text), r.finish_reason, r.usage_details)
asyncio.run(main())Error Messages and Stack Traces
non-streaming: '' None {'input_token_count': 8, 'total_token_count': 8}
streaming: '' None None
Package Versions
agent-framework-core 1.25.0, agent-framework-gemini 1.0.0b261106 (main at 13956ad), google-genai 2.32.0
Python Version
Python 3.12
Operating System
macOS
Regression
No
Additional Context
_process_generate_response and _process_chunk in _chat_client.py only look at the candidate's finish_reason, and never at prompt_feedback. The same happens when a later automatic-continuation hop is blocked: the SDK keeps the earlier candidate, clears its finish_reason and sets prompt_feedback. A fix could be to return content_filter when prompt_feedback.block_reason is set and the candidate has no finish reason. I have a fix with tests and will open a PR.
AI assistance: I used an AI assistant to help find the cause and write this up. I ran the repro myself.
Acknowledgements
- I searched existing issues and did not find a duplicate.
- I personally verified this behavior and the reproduction details are authentic.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
github-actions commentedon Nov 9, 2026
Reproduced on main (13956ad) with the reporter's scenario, rebuilt independently with a mocked client: both modes return
finish_reason=None, and streamingusage_details=None(run)._process_generate_responseand_process_chunkinpython/packages/gemini/agent_framework_gemini/_chat_client.pyonly read the candidate's finish reason, neverprompt_feedback.Support boundary: unclear. I found no maintained spec or docs setting it, so a maintainer should confirm. Fix PR #10213 is open and not merged or released.