Skip to content

Python: map Vertex AI RECITATION/BLOCKLIST/PROHIBITED_CONTENT/SPII finish reasons to CONTENT_FILTER - #14712

Open
alexcastgonz (pcbeingused333) wants to merge 1 commit into
microsoft:mainfrom
pcbeingused333:c0566-vertex-finish-reasons
Open

alexcastgonz (pcbeingused333) wants to merge 1 commit into
microsoft:mainfrom
pcbeingused333:c0566-vertex-finish-reasons

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Motivation and Context

The Vertex AI connector's finish_reason_from_vertex_ai_to_semantic_kernel only mapped SAFETY to FinishReason.CONTENT_FILTER. When Gemini on Vertex AI stopped a response for RECITATION, BLOCKLIST, PROHIBITED_CONTENT or SPII, the result came back with finish_reason=None, so callers could not tell a content stop from an unknown one. The Google AI connector already maps these reasons to CONTENT_FILTER; this brings the Vertex AI connector in line.

Description

Add a _VERTEX_AI_CONTENT_FILTER_REASONS set (SAFETY, RECITATION, BLOCKLIST, PROHIBITED_CONTENT, SPII) and map any member to CONTENT_FILTER. STOP, MAX_TOKENS and unrelated reasons behave as before.

Added a parametrized test in test_vertex_ai_utils.py covering the five reasons. It fails on main (4 of the new cases) and passes with the change; the file passes (15), and ruff format --check / ruff check are clean.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the SK Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • I didn't break anyone 😄

This pull request was prepared with the assistance of an AI coding agent (Claude Code) and submitted by Alex Castillo, who is responsible for its content.

…nish reasons to CONTENT_FILTER

The Vertex AI connector only mapped SAFETY to CONTENT_FILTER, so responses
Gemini stopped for recitation, blocklist, prohibited content or SPII came
back with finish_reason=None. Map them the same way the Google AI connector
already does.
Copilot AI balanced review requested due to automatic review settings November 3, 2026 03:30
@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Nov 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the Vertex AI finish-reason mapping update.

No open issues 🎉

What changed in this PR

Aligns the Vertex AI connector with the Google AI connector by mapping additional content-related finish reasons to CONTENT_FILTER.

Changes:

  • Maps SAFETY, RECITATION, BLOCKLIST, PROHIBITED_CONTENT, and SPII through a shared immutable set.
  • Preserves existing handling of STOP, MAX_TOKENS, and unrelated reasons.
  • Adds parametrized tests covering all five content-filter reasons.
File Description
python/​tests/​unit/​connectors/​ai/​google/​vertex_ai/​services/​test_vertex_ai_utils.py Adds coverage for all five content-filter finish reasons.
python/​semantic_kernel/​connectors/​ai/​google/​vertex_ai/​services/​utils.py Expands the Vertex AI content-filter mapping using a shared set.

Review effort: Balanced

This branch was successfully deployed

1 active deployment
github-app-auth — 8f8572e6 Deployed Nov 3, 2026 by pcbeingused333 via add_label #29565
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants