Skip to content

Conversation

@jxnl
Copy link
Collaborator

@jxnl jxnl commented Jan 16, 2026

fix: filter Google GenAI HARM_CATEGORY_IMAGE_* to prevent 400 INVALID_ARGUMENT

Describe your changes

This PR resolves a critical production blocker where Google GenAI's generateContent endpoint would return 400 INVALID_ARGUMENT errors when safety_settings included HARM_CATEGORY_IMAGE_* categories, especially with multimodal requests.

The fix defensively filters out all HARM_CATEGORY_IMAGE_* categories from the safety_settings before they are sent to the Google GenAI API. A new regression test ensures these categories are never included, even if provided by the user. This prevents the API from rejecting valid requests due to unsupported safety settings.

Issue ticket number and link

Linear: 567-264
GitHub: #1773

Checklist before requesting a review

  • I have performed a self-review of my code
  • If it is a core feature, I have added thorough tests.
  • If it is a core feature, I have added documentation.

Linear Issue: 567-264

Open in Cursor Open in Web

cursoragent and others added 2 commits January 16, 2026 17:28
Filter out HARM_CATEGORY_IMAGE_* defensively to avoid 400 INVALID_ARGUMENT errors from Google GenAI (issue #1773).

Adds a regression test to ensure IMAGE categories never get sent.

Co-authored-by: jason <[email protected]>
Moves the IMAGE harm category regression test out of llm-only GenAI tests so it runs without GOOGLE_API_KEY.

Guards against sending HARM_CATEGORY_IMAGE_* in safety_settings (issue #1773).

Co-authored-by: jason <[email protected]>
@cursor
Copy link

cursor bot commented Jan 16, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 16, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
instructor cb54f34 Commit Preview URL

Branch Preview URL
Jan 16 2026, 05:35 PM

@github-actions github-actions bot added bug Something isn't working priority:critical Critical issue affecting production size:M This PR changes 30-99 lines, ignoring generated files. type:regression Regression from previous version labels Jan 16, 2026
@jxnl
Copy link
Collaborator Author

jxnl commented Jan 16, 2026

@cursoragent fix the ci issues

@cursor
Copy link

cursor bot commented Jan 16, 2026

CI’s Ruff job was failing because ruff format --check wanted to reformat instructor/providers/gemini/utils.py (not because of the cache warning).

  • Fix: ran Ruff formatter on instructor/providers/gemini/utils.py
  • Verified locally: uv run ruff format --check instructor examples tests and uv run ruff check instructor examples tests both pass
  • Shipped: committed (style(genai): format safety settings filter) and pushed to cursor/567-264-safetysettings-invalid-arguments-d6a1 so CI reruns green

Open in Cursor Open in Web

Apply Ruff formatting to keep CI green.

Co-authored-by: jason <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working priority:critical Critical issue affecting production size:M This PR changes 30-99 lines, ignoring generated files. type:regression Regression from previous version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants