Skip to content

feat(gateway): map content filter types - #1345

Merged
steebchen merged 1 commit into
mainfrom
terragon/handle-content-filter-gateway-nxx3bd
Dec 22, 2025
Merged

steebchen merged 1 commit into
mainfrom
terragon/handle-content-filter-gateway-nxx3bd

Conversation

@steebchen

@steebchen steebchen commented Dec 21, 2025

Copy link
Copy Markdown
Member

Summary

  • Extend content filter handling in gateway finish reason to include IMAGE_RECITATION and IMAGE_OTHER.
  • Update tests to cover new mappings.

Changes

Gateway Logs

  • Update getUnifiedFinishReason to treat IMAGE_RECITATION and IMAGE_OTHER as content-filter finish reasons (mapping to UnifiedFinishReason.CONTENT_FILTER).

Tests

  • Extend logs.spec.ts with new test cases:
    • getUnifiedFinishReason("IMAGE_RECITATION", "google-ai-studio") => UnifiedFinishReason.CONTENT_FILTER
    • getUnifiedFinishReason("IMAGE_OTHER", "google-ai-studio") => UnifiedFinishReason.CONTENT_FILTER

Files touched

  • apps/gateway/src/lib/logs.ts
  • apps/gateway/src/lib/logs.spec.ts

Test plan

  • Run unit tests locally
  • Verify new mappings for IMAGE_RECITATION and IMAGE_OTHER
  • Ensure no regressions for existing finish reason mappings

🌿 Generated by Terry


ℹ️ Tag @terragon-labs to ask questions and address PR feedback

📎 Task: https://www.terragonlabs.com/task/26e3b6bf-98a2-44a0-b57e-84e6aa8145cd

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced content filter detection for Google AI Studio and Vertex AI providers to properly classify additional image-related response types.

✏️ Tip: You can customize this high-level summary in your review settings.

Add the finish reason "IMAGE_RECITATION" to the list of reasons unified under CONTENT_FILTER in getUnifiedFinishReason. Also update corresponding tests to cover this new case.

Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
Copilot AI review requested due to automatic review settings December 21, 2025 15:34
@github-actions github-actions Bot changed the title Gateway: Map content filter types to unified finish reason feat(gateway): map content filter types Dec 21, 2025
@coderabbitai

coderabbitai Bot commented Dec 21, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This PR adds support for two new Google AI finish reasons ("IMAGE_RECITATION" and "IMAGE_OTHER") for google-ai-studio and google-vertex providers, mapping them to the CONTENT_FILTER unified finish reason. Test coverage is expanded to validate the new mappings.

Changes

Cohort / File(s) Summary
Finish reason mapping expansion
apps/gateway/src/lib/logs.ts
Added conditional branches to map "IMAGE_RECITATION" and "IMAGE_OTHER" finish reasons to UnifiedFinishReason.CONTENT_FILTER for Google providers.
Test coverage
apps/gateway/src/lib/logs.spec.ts
Expanded getUnifiedFinishReason test suite with two new test cases covering the IMAGE_RECITATION and IMAGE_OTHER finish reasons.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5–10 minutes

  • Verify that the new finish reason strings ("IMAGE_RECITATION", "IMAGE_OTHER") correctly map to CONTENT_FILTER
  • Confirm test cases comprehensively cover the new mappings
  • Ensure no unintended side effects on existing finish reason handling

Possibly related PRs

  • PR #561: Modifies getUnifiedFinishReason with new finish-reason string mappings using the same pattern.
  • PR #1340: Adds additional Google finish-reason mappings to UnifiedFinishReason.CONTENT_FILTER in the same function.
  • PR #1117: Adds Google content-filter finish reasons to the logs.ts provider finish-reason mapping logic.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(gateway): map content filter types' directly reflects the main change—mapping additional finish reasons (IMAGE_RECITATION and IMAGE_OTHER) to UnifiedFinishReason.CONTENT_FILTER in the gateway service.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch terragon/handle-content-filter-gateway-nxx3bd

📜 Recent review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30f9158 and 944c204.

📒 Files selected for processing (2)
  • apps/gateway/src/lib/logs.spec.ts (1 hunks)
  • apps/gateway/src/lib/logs.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Never use any or as any unless absolutely necessary in TypeScript code
For database reads: Use db().query.<table>.findMany() or db().query.<table>.findFirst()

Files:

  • apps/gateway/src/lib/logs.ts
  • apps/gateway/src/lib/logs.spec.ts
**/*.{ts,tsx,js,jsx,json,md}

📄 CodeRabbit inference engine (CLAUDE.md)

Always use tabs for indentation

Files:

  • apps/gateway/src/lib/logs.ts
  • apps/gateway/src/lib/logs.spec.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js,jsx}: Always use top-level import, never use require or dynamic imports
No unnecessary code comments

Files:

  • apps/gateway/src/lib/logs.ts
  • apps/gateway/src/lib/logs.spec.ts
apps/{gateway,api}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use Hono framework with Zod validation and OpenAPI documentation for backend APIs

Files:

  • apps/gateway/src/lib/logs.ts
  • apps/gateway/src/lib/logs.spec.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Always use top-level import, never use require or dynamic imports

Files:

  • apps/gateway/src/lib/logs.ts
  • apps/gateway/src/lib/logs.spec.ts
{apps/api,apps/gateway,packages/db}/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

{apps/api,apps/gateway,packages/db}/**/*.ts: Use Drizzle ORM with latest object syntax for database operations
For database reads: Use db().query.<table>.findMany() or db().query.<table>.findFirst()

Files:

  • apps/gateway/src/lib/logs.ts
  • apps/gateway/src/lib/logs.spec.ts
apps/{gateway,api}/src/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

apps/{gateway,api}/src/**/*.ts: Use Hono for backend framework in Gateway and API services
Use Zod schemas for validation in Hono services

Files:

  • apps/gateway/src/lib/logs.ts
  • apps/gateway/src/lib/logs.spec.ts
**/*.spec.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Unit tests should use *.spec.ts file naming convention

Files:

  • apps/gateway/src/lib/logs.spec.ts
⏰ 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)
  • GitHub Check: e2e-shards (3)
  • GitHub Check: e2e-shards (4)
  • GitHub Check: e2e-shards (5)
  • GitHub Check: e2e-shards (1)
  • GitHub Check: e2e-shards (2)
  • GitHub Check: build / run
  • GitHub Check: lint / run
  • GitHub Check: test / run
  • GitHub Check: generate / run
  • GitHub Check: autofix
🔇 Additional comments (2)
apps/gateway/src/lib/logs.spec.ts (1)

63-68: LGTM! Good test coverage for new image-related content filters.

The test cases correctly validate the mapping of IMAGE_RECITATION and IMAGE_OTHER to CONTENT_FILTER, following the established pattern for other Google AI Studio finish reasons.

apps/gateway/src/lib/logs.ts (1)

56-70: Implementation is correct.

The finish reasons IMAGE_RECITATION and IMAGE_OTHER are valid documented finish reasons in the Google Gen AI SDK. The mapping to UnifiedFinishReason.CONTENT_FILTER is appropriate for all safety and content-related finish reasons, including image-specific ones.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the gateway's finish reason mapping to properly handle two additional Google AI image-related content filter types: IMAGE_RECITATION and IMAGE_OTHER. These are now correctly mapped to the unified CONTENT_FILTER finish reason.

Key changes:

  • Added IMAGE_RECITATION to the content filter condition chain for Google providers
  • Added comprehensive test coverage for both IMAGE_RECITATION and IMAGE_OTHER mappings

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
apps/gateway/src/lib/logs.ts Added IMAGE_RECITATION to the content filter finish reason mapping for Google providers
apps/gateway/src/lib/logs.spec.ts Added test cases to verify IMAGE_RECITATION and IMAGE_OTHER correctly map to CONTENT_FILTER

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@steebchen
steebchen added this pull request to the merge queue Dec 22, 2025
Merged via the queue into main with commit eb22cbb Dec 22, 2025
19 of 20 checks passed
@steebchen
steebchen deleted the terragon/handle-content-filter-gateway-nxx3bd branch December 22, 2025 21:24
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