Skip to content

fix(vertex): pass system messages as SystemInstruction - #7

Merged
ntauth merged 2 commits into
ntauth:mainfrom
intx4:fix/vertex-system-instruction
Nov 6, 2026
Merged

ntauth merged 2 commits into
ntauth:mainfrom
intx4:fix/vertex-system-instruction

Conversation

@intx4

@intx4 intx4 commented Nov 6, 2026 •

Copy link
Copy Markdown

Problem

The Vertex client rejects any system-role message with system role isn't supporeted yet, so every [system, human] call fails.

Change

  • Split system messages out of the message list in GenerateContent.
  • Join their text with newlines and send it as GenerateContentConfig.SystemInstruction.
  • Generate from the remaining messages. A system message plus one human message takes the single-message path.
  • Passing only system messages returns the new ErrNoNonSystemMessages.
  • Remove ErrSystemRoleNotSupported, which nothing else used.
  • Add offline unit tests for the splitting logic.
  • Honor llms.WithJSONMode(): set ResponseMIMEType to application/json so Gemini no longer wraps JSON in markdown code fences.

Notes

  • System messages are always lifted out, wherever they sit in the list.
  • googleai.go is unchanged: the pinned generative-ai-go v0.5.0 has no system-instruction field on GenerativeModel.
  • vertex.go is marked as generated from googleai.go; regenerating it would overwrite this change.
  • The branch also carries fix(vertex): set user role on single-message GenerateContent (5025b90), which is not yet on main.
  • Not tested against the live Gemini API.

🤖 Generated with Claude Code

intx4 added 2 commits November 6, 2026 12:24
convertContent rejected system-role messages, so any [system, human]
call failed. Split system messages out in GenerateContent, concatenate
their text (newline separated) into GenerateContentConfig.SystemInstruction
and generate from the remaining messages. A lone system message plus a
human one now takes the single-message path; only system messages
returns ErrNoNonSystemMessages. ErrSystemRoleNotSupported is removed.
llms.WithJSONMode() was ignored by the Vertex client, so Gemini could
wrap JSON replies in markdown code fences. Set
GenerateContentConfig.ResponseMIMEType to application/json when JSONMode
is on, in both the single-message and multi-message paths.
@ntauth
ntauth merged commit 91c7cd6 into ntauth:main Nov 6, 2026
0 of 3 checks passed
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