Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gemini-blocked-finish-reasons.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'manifest': patch
---

Report Gemini replies blocked for BLOCKLIST, PROHIBITED_CONTENT, SPII or IMAGE_SAFETY as `content_filter` instead of `stop`.
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,23 @@ describe('Google Adapter', () => {
expect(choices[0].finish_reason).toBe('content_filter');
});

it.each(['BLOCKLIST', 'PROHIBITED_CONTENT', 'SPII', 'IMAGE_SAFETY'])(
'maps %s finish reason to content_filter',
(finishReason) => {
const google = {
candidates: [
{
content: { parts: [{ text: '' }] },
finishReason,
},
],
};
const result = fromGoogleResponse(google, 'gemini-2.0-flash');
const choices = result.choices as Array<{ finish_reason: string }>;
expect(choices[0].finish_reason).toBe('content_filter');
},
);

it('maps unknown finish reason to stop', () => {
const google = {
candidates: [
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/routing/proxy/google-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ function mapFinishReason(candidate: Record<string, unknown>, hasToolCalls = fals
MAX_TOKENS: 'length',
SAFETY: 'content_filter',
RECITATION: 'content_filter',
BLOCKLIST: 'content_filter',
PROHIBITED_CONTENT: 'content_filter',
SPII: 'content_filter',
IMAGE_SAFETY: 'content_filter',
};
return map[reason] ?? 'stop';
}
Expand Down
Loading