Socket
Book a DemoInstallSign in
Socket

@langchain/google-vertexai

Package Overview
Dependencies
Maintainers
0
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@langchain/google-vertexai

LangChain.js support for Google Vertex AI

latest
Source
npmnpm
Version
2.1.7
Version published
Maintainers
0
Created
Source

LangChain google-vertexai

This package contains resources to access Google AI/ML models and other Google services via Vertex AI. Authorization to these services use service account credentials stored on the local file system or provided through the Google Cloud Platform environment it is running on.

If you are running this on a platform where the credentials cannot be provided this way, consider using the @langchain/google-vertexai-web package instead. You do not need to use both packages. See the section on Authorization below.

Installation

$ pnpm install @langchain/google-vertexai

Authorization

Authorization is done through a Google Cloud Service Account.

To handle service accounts, this package uses the google-auth-library package, and you may wish to consult the documentation for that library about how it does so. But in short, classes in this package will use credentials from the first of the following that apply:

  • An API Key that is passed to the constructor using the apiKey attribute
  • Credentials that are passed to the constructor using the authInfo attribute
  • An API Key that is set in the environment variable API_KEY
  • The Service Account credentials that are saved in a file. The path to this file is set in the GOOGLE_APPLICATION_CREDENTIALS environment variable.
  • If you are running on a Google Cloud Platform resource, or if you have logged in using gcloud auth application-default login, then the default credentials.

Tool Schema Limitations

When using tools with Gemini models through Vertex AI, be aware of the following Zod schema limitations:

Unsupported Schema Features

  • Discriminated Unions - .discriminatedUnion() is not supported

    // ❌ This will throw an error
    z.discriminatedUnion("type", [
      z.object({ type: z.literal("a"), value: z.string() }),
      z.object({ type: z.literal("b"), value: z.number() }),
    ]);
    
    // ✅ Use a flat object with optional fields instead
    z.object({
      type: z.enum(["a", "b"]),
      stringValue: z.string().optional(),
      numberValue: z.number().optional(),
    });
    
  • Union Types - z.union() is not supported

    // ❌ This will throw an error
    z.union([z.string(), z.number()]);
    
    // ✅ Consider using separate optional fields
    z.object({
      stringValue: z.string().optional(),
      numberValue: z.number().optional(),
    });
    
  • Positive Refinement - .positive() is automatically converted

    // ⚠️ This is automatically converted to .min(0.01)
    z.number().positive();
    
    // ✅ Prefer using .min() directly
    z.number().min(0.01);
    

Error Messages

If you use unsupported schema features, you'll receive descriptive error messages:

  • For union types: "Gemini cannot handle union types (discriminatedUnion, anyOf, oneOf)"
  • For tool conversion failures: "Failed to convert tool '[toolName]' schema for Gemini"

Best Practices

  • Use simple, flat object structures when possible
  • Replace discriminated unions with enums and optional fields
  • Use .min() instead of .positive() for number constraints
  • Test your tool schemas before deploying to production

FAQs

Package last updated on 08 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts