Skip to content

[Bug] google-genai plugin deletes "falsy" parameters (e.g. addWatermark: false) #4016

@CatoPaus

Description

@CatoPaus

Bug Report: google-genai Plugin Deletes "Falsy" Parameter Values (False / 0)

Package: @genkit-ai/google-genai
Version: 1.27.0 (and earlier)
Source File: js/plugins/google-genai/src/vertexai/converters.ts
Compiled File: lib/vertexai/converters.js
Function: toImagenParameters

Issue Description

The toImagenParameters function in the google-genai plugin sanitizes the config object by deleting any keys with "falsy" values. This is incorrect behavior for boolean flags (where false is a meaningful value) and numeric parameters (where 0 might be valid).

Specifically for Imagen, the addWatermark parameter defaults to true on the Vertex AI API side. To disable it, the client must send addWatermark: false.
However, because false is falsy in JavaScript, the current plugin logic deletes this parameter entirely. The API then receives a request without addWatermark, triggering the default true, making it impossible to disable watermarks (and consequently making it impossible to use seed, which conflicts with watermarks).

Code location

File: src/vertexai/converters.ts (approx line 97)

function toImagenParameters(request: any) {
  const params = {
    sampleCount: request.candidates ?? 1,
    ...request?.config,
  };
  for (const k in params) {
    // BUG: This deletes false, 0, undefined, null, ""
    if (!params[k]) delete params[k];
  }
  return params;
}

Recommended Fix

Update the filter condition to only remove keys that are strictly undefined or null.

function toImagenParameters(request: any) {
  const params = {
    sampleCount: request.candidates ?? 1,
    ...request?.config,
  };
  for (const k in params) {
    // FIX: Only delete if undefined or null
    if (params[k] === undefined || params[k] === null) delete params[k];
  }
  return params;
}

Impact

  • Watermarks: Users cannot disable watermarks (addWatermark: false is stripped).
  • Deterministic Generation: Users cannot use seed because it requires watermarks to be disabled.
  • Zero Values: Any future parameter expecting a 0 index or value will differ from intent.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions