Skip to content

fix: add system prompt to google gen-ai request - #10

Merged
isaacs merged 1 commit into
mainfrom
isaacschlueter/google-genai-add-system-prompt
Dec 9, 2025
Merged

isaacs merged 1 commit into
mainfrom
isaacschlueter/google-genai-add-system-prompt

Conversation

@isaacs

@isaacs isaacs commented Dec 8, 2025

Copy link
Copy Markdown
Member

Current versions of google's genai SDK allow passing the system prompt separate from the user messages.

Update test to accurately track that we're including this in the span.

Related to JS-1218

@linear

linear Bot commented Dec 8, 2025

Copy link
Copy Markdown
JS-1218 JS Google GenAI - response model missing

Error: Fixture validation failed:
llm_call (gen_ai.models):
   gen_ai.response.model: missing
   gen_ai.request.messages: mismatch (expected: {"type":"json_array","min_length":2,"items_have":["role","content"]}, got: "You are a helpful math assistant. Your anwser only with the final result.\n\nWhat is 69 + 96?")
  "dependencies": {
    "@sentry/node": "10.24.0",
    "@google/genai": "1.29.0"
  }

@isaacs
isaacs requested a review from obostjancic December 8, 2025 21:03
isaacs added a commit to getsentry/sentry-javascript that referenced this pull request Dec 8, 2025
isaacs added a commit to getsentry/sentry-javascript that referenced this pull request Dec 8, 2025
isaacs added a commit to getsentry/sentry-javascript that referenced this pull request Dec 8, 2025
isaacs added a commit to getsentry/sentry-javascript that referenced this pull request Dec 8, 2025
isaacs added a commit to getsentry/sentry-javascript that referenced this pull request Dec 8, 2025
@isaacs
isaacs force-pushed the isaacschlueter/google-genai-add-system-prompt branch from a586bee to e26bc8c Compare December 9, 2025 20:55
Current versions of google's genai SDK allow passing the system prompt
separate from the user messages.

Update test to accurately track that we're including this in the span.
@isaacs
isaacs force-pushed the isaacschlueter/google-genai-add-system-prompt branch from e26bc8c to a36f2e9 Compare December 9, 2025 20:55
contents,
contents: prompt,
config: {
systemInstruction: [ system ],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The systemInstruction in config is incorrectly passed as an array [system] instead of a string.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The generateContent() call will fail at runtime because the systemInstruction parameter within the config object is incorrectly passed as an array [system] instead of a string. The Google GenAI JavaScript SDK expects systemInstruction to be a string, which will lead to either a validation error from the API or an SDK error during parameter processing. This prevents the system instruction from being properly applied, causing the API call to fail.

💡 Suggested Fix

Change systemInstruction: [ system ] to systemInstruction: system in the config object to pass the system string directly, aligning with SDK documentation.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: sdks/js/google-genai/cases/1-simple.js#L23

Potential issue: The `generateContent()` call will fail at runtime because the
`systemInstruction` parameter within the `config` object is incorrectly passed as an
array `[system]` instead of a string. The Google GenAI JavaScript SDK expects
`systemInstruction` to be a string, which will lead to either a validation error from
the API or an SDK error during parameter processing. This prevents the system
instruction from being properly applied, causing the API call to fail.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 6609577

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This actually can be a PartListUnion, so a Part object, string, or array of Part objects and strings. (Annoying, I know, but including it this way helped flush out a bug in the JS SDK, actually.)

@isaacs
isaacs merged commit 1d2f7e5 into main Dec 9, 2025
2 checks passed
isaacs added a commit to getsentry/sentry-javascript that referenced this pull request Dec 9, 2025
Move the message reformatting into a separate util for google-genai, and
add unit test coverage for that file.

Add an integration test scenario to ensure that the system message will
be included if provided in the config params.

Related to getsentry/testing-ai-sdk-integrations#10

Fix JS-1218
isaacs added a commit to getsentry/sentry-javascript that referenced this pull request Dec 9, 2025
Move the message reformatting into a separate util for google-genai, and
add unit test coverage for that file.

Add an integration test scenario to ensure that the system message will
be included if provided in the config params.

Related to getsentry/testing-ai-sdk-integrations#10

Fix JS-1218
isaacs added a commit to getsentry/sentry-javascript that referenced this pull request Dec 10, 2025
Move the message reformatting into a separate util for google-genai, and
add unit test coverage for that file.

Add an integration test scenario to ensure that the system message will
be included if provided in the config params.

Related to getsentry/testing-ai-sdk-integrations#10

Fix JS-1218
isaacs added a commit to getsentry/sentry-javascript that referenced this pull request Dec 11, 2025
Move the message reformatting into a separate util for google-genai, and
add unit test coverage for that file.

Add an integration test scenario to ensure that the system message will
be included if provided in the config params.

Related to getsentry/testing-ai-sdk-integrations#10

Fix JS-1218
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