fix(gateway): map google image safety finish reasons - #1340
Conversation
Add IMAGE_SAFETY, IMAGE_PROHIBITED_CONTENT, LANGUAGE, and NO_IMAGE to the content filter mapping for google-ai-studio and google-vertex providers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
WalkthroughExtends Google AI Studio finish-reason mappings by adding LANGUAGE, IMAGE_SAFETY, IMAGE_PROHIBITED_CONTENT, and NO_IMAGE cases that map to CONTENT_FILTER. Updates both production logic in logs.ts and corresponding test cases in logs.spec.ts. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Suggested labels
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Repository UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (8)**/*.{ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{ts,tsx,js,jsx,json,md}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
apps/{gateway,api}/**/*.{ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{js,ts,tsx,jsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
{apps/api,apps/gateway,packages/db}/**/*.ts📄 CodeRabbit inference engine (AGENTS.md)
Files:
apps/{gateway,api}/src/**/*.ts📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.spec.ts📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧬 Code graph analysis (1)apps/gateway/src/lib/logs.spec.ts (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes the handling of Google's image-related finish reasons by adding four new finish reason mappings (IMAGE_SAFETY, IMAGE_PROHIBITED_CONTENT, LANGUAGE, and NO_IMAGE) to the content filter classification for both google-ai-studio and google-vertex providers. This prevents these finish reasons from being incorrectly logged as "Unknown finish reason encountered" errors.
- Added four new Google finish reasons to the content filter mapping
- Added corresponding unit tests for the new finish reason mappings with google-ai-studio provider
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/gateway/src/lib/logs.ts | Added four new Google finish reasons (IMAGE_SAFETY, IMAGE_PROHIBITED_CONTENT, LANGUAGE, NO_IMAGE) to the content filter mapping in the google-ai-studio/google-vertex case |
| apps/gateway/src/lib/logs.spec.ts | Added unit tests for the four new finish reasons using google-ai-studio provider |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| expect(getUnifiedFinishReason("LANGUAGE", "google-ai-studio")).toBe( | ||
| UnifiedFinishReason.CONTENT_FILTER, | ||
| ); | ||
| expect(getUnifiedFinishReason("IMAGE_SAFETY", "google-ai-studio")).toBe( | ||
| UnifiedFinishReason.CONTENT_FILTER, | ||
| ); | ||
| expect( | ||
| getUnifiedFinishReason("IMAGE_PROHIBITED_CONTENT", "google-ai-studio"), | ||
| ).toBe(UnifiedFinishReason.CONTENT_FILTER); | ||
| expect(getUnifiedFinishReason("NO_IMAGE", "google-ai-studio")).toBe( | ||
| UnifiedFinishReason.CONTENT_FILTER, | ||
| ); |
There was a problem hiding this comment.
The new finish reason tests only cover the "google-ai-studio" provider, but the implementation in logs.ts applies these finish reasons to both "google-ai-studio" and "google-vertex" providers (lines 47-48 use a shared case statement). Test coverage should be added for the "google-vertex" provider to ensure these finish reasons work correctly for both Google provider types.
Summary
This PR fixes the handling of Google's image-related finish reasons by properly classifying them as content filters in the unified finish reason system. Previously, finish reasons like
IMAGE_SAFETYwould be logged as "Unknown finish reason encountered" errors.Changes
IMAGE_SAFETY,IMAGE_PROHIBITED_CONTENT,LANGUAGE, andNO_IMAGEto the content filter mapping for google-ai-studio and google-vertex providersTesting
All unit tests pass, including the new tests for the added finish reasons.
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.