Skip to content

fix(ai): classify Gemini terms-of-use refusals as content policy - #64910

Merged
neriousy merged 1 commit into
devfrom
classify-tos-refusal
Nov 19, 2026
Merged

neriousy merged 1 commit into
devfrom
classify-tos-refusal

Conversation

@neriousy

Copy link
Copy Markdown
Member

Issue for this PR

Closes #64557

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

when google refuses a request with "Request rejected in accordance with our terms of use and policies" it comes back as a 403, and we classify every 403 as Authentication unless it matches a known content policy message. google's wording wasn't in CONTENT_POLICY_TEXT, so users got "Authentication error" even though their auth was fine

added the phrase to CONTENT_POLICY_TEXT in packages/ai/src/provider-error.ts, so these now classify as ContentPolicy and surface as provider.content-filter. the content policy check runs before the 403 → auth fallback, so nothing else changes

the refusal itself is upstream (google flagging a vertex project for a stretch), not something we can fix client side

no flag, it's a classification fix

How did you verify your code works?

  • new test in packages/ai/test/provider-error.test.ts covers the direct gemini 403 body and the zen-wrapped Upstream request failed: [403] ... message
  • test fails without the fix (Authentication), passes with it
  • bun test + bun typecheck in packages/ai, test/session-error.test.ts in packages/core

Screenshots / recordings

n/a

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@opencodejr opencodejr Bot 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.

Looks good. I ran the #64557 mock-gateway reproduction with the CLI built from source. On the base, the zen-wrapped Gemini 403 (Request rejected in accordance with our terms of use and policies) comes back as provider.auth. With this change it comes back as provider.content-filter. provider-error.test.ts and core's session-error.test.ts pass, and tsc type-checks packages/ai cleanly.

The content-policy check runs before the 403 → authentication fallback and only on 4xx messages, so other 401/403 cases still classify as authentication.

Public API is unchanged.

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.

zen/go: Gemini 4 Argon returns upstream 403 "Request rejected in accordance with our terms of use and policies"

1 participant