Skip to content
Open
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
3 changes: 2 additions & 1 deletion core/changelog.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- feat: added azure passthrough support
[fix]: propagate safety filtering info for Vertex AI and Gemini responses [@astralhpi](https://github.com/astralhpi)
- feat: added azure passthrough support
15 changes: 14 additions & 1 deletion core/providers/gemini/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func (response *GenerateContentResponse) ToBifrostChatResponse() *schemas.Bifros

// Handle empty candidates (filtered/malformed responses)
if len(response.Candidates) == 0 {
// If promptFeedback is present, the prompt was blocked by safety filters
if response.PromptFeedback != nil && response.PromptFeedback.BlockReason != "" {
return createErrorResponse(response, "content_filter", false)
}
Comment on lines +89 to +92
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.

⚠️ Potential issue | 🟠 Major

Don’t require BlockReason to classify prompt-blocked empty responses.

When Candidates is empty, PromptFeedback itself already indicates prompt blocking. Requiring BlockReason != "" can still fall back to malformed-function-call handling and return "stop" instead of "content_filter".

Suggested fix
-		if response.PromptFeedback != nil && response.PromptFeedback.BlockReason != "" {
+		if response.PromptFeedback != nil {
 			return createErrorResponse(response, "content_filter", false)
 		}
-		if response.PromptFeedback != nil && response.PromptFeedback.BlockReason != "" {
+		if response.PromptFeedback != nil {
 			return createErrorResponse(response, "content_filter", true), nil, true
 		}

Also applies to: 306-309

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/providers/gemini/chat.go` around lines 89 - 92, The current check in
core/providers/gemini/chat.go uses response.PromptFeedback != nil &&
response.PromptFeedback.BlockReason != "" to mark prompt-blocked responses as
"content_filter", but that misses cases where PromptFeedback exists and
Candidates is empty; change the condition(s) (both the one around response
handling and the later occurrence at lines ~306-309) to detect prompt-blocking
when response.PromptFeedback != nil AND (len(response.Candidates) == 0 ||
response.PromptFeedback.BlockReason != ""), then call
createErrorResponse(response, "content_filter", false) as before so
empty-candidate prompt feedback is classified correctly.

finishReason := ConvertGeminiFinishReasonToBifrost(FinishReasonMalformedFunctionCall)
return createErrorResponse(response, finishReason, false)
}
Expand Down Expand Up @@ -299,6 +303,10 @@ func (response *GenerateContentResponse) ToBifrostChatCompletionStream(state *Ge

// Handle empty candidates (filtered/malformed responses)
if len(response.Candidates) == 0 {
// If promptFeedback is present, the prompt was blocked by safety filters
if response.PromptFeedback != nil && response.PromptFeedback.BlockReason != "" {
return createErrorResponse(response, "content_filter", true), nil, true
}
finishReason := ConvertGeminiFinishReasonToBifrost(FinishReasonMalformedFunctionCall)
return createErrorResponse(response, finishReason, true), nil, true
}
Expand Down Expand Up @@ -504,7 +512,12 @@ func isErrorFinishReason(reason FinishReason) bool {
reason == FinishReasonProhibitedContent ||
reason == FinishReasonSPII ||
reason == FinishReasonImageSafety ||
reason == FinishReasonUnexpectedToolCall
reason == FinishReasonUnexpectedToolCall ||
// Vertex AI-specific
reason == FinishReasonModelArmor ||
reason == FinishReasonImageProhibitedContent ||
reason == FinishReasonImageRecitation ||
reason == FinishReasonImageOther
}

// createErrorResponse creates a complete BifrostChatResponse for error cases
Expand Down
Loading