Google Gemini Integration
Use Veto with Gemini function calling via provider adapters and optional guard preflight checks.
Veto integrates with Google Gemini function calling by converting tool definitions to Gemini function declarations and mapping function calls back to Veto tool calls.
TypeScript only.
Installation
npm install veto-sdk @google/genaiQuick start
import { GoogleGenAI } from '@google/genai';
import { Veto, ToolCallDeniedError } from 'veto-sdk';
import { toGoogleTool, fromGoogleFunctionCall } from 'veto-sdk/providers';
const genai = new GoogleGenAI({ apiKey: process.env.GOOGLE_API_KEY! });
const veto = await Veto.init();
const vetoTools = [
{
name: 'transfer_funds',
description: 'Transfer money between bank accounts',
inputSchema: {
type: 'object' as const,
properties: {
amount: { type: 'number' },
from_account: { type: 'string' },
to_account: { type: 'string' },
},
required: ['amount', 'from_account', 'to_account'],
},
},
];
const googleTool = toGoogleTool(vetoTools);
const response = await genai.models.generateContent({
model: 'gemini-2.0-flash',
contents: [{ role: 'user', parts: [{ text: 'Transfer $500 from ACC-1 to ACC-2' }] }],
config: { tools: [{ functionDeclarations: googleTool.functionDeclarations }] },
});
const parts = response.candidates?.[0]?.content?.parts ?? [];
for (const part of parts) {
if (!part.functionCall) continue;
const vetoCall = fromGoogleFunctionCall(part.functionCall);
// Optional preflight check (no execution, no ToolCallDeniedError throw)
const guard = await veto.guard(vetoCall.name, vetoCall.arguments, {
sessionId: 'gemini-session-1',
agentId: 'gemini-agent',
});
if (guard.decision !== 'allow') {
console.log(`Blocked at preflight: ${guard.decision} ${guard.reason ?? ''}`);
continue;
}
// Execution-time enforcement
const wrapped = veto.wrap([{
name: vetoCall.name,
handler: async (args: Record<string, unknown>) => ({ ok: true, args }),
}]);
try {
const result = await wrapped[0].handler(vetoCall.arguments);
console.log(result);
} catch (error) {
if (error instanceof ToolCallDeniedError) {
console.log(`Blocked by policy: ${error.reason}`);
} else {
throw error;
}
}
}Adapter functions
| Function | Purpose |
|---|---|
toGoogleTool(toolDefs) | Convert Veto tool definitions into Gemini functionDeclarations |
fromGoogleFunctionCall(functionCall) | Convert a Gemini function call into normalized ToolCall format |
Both are exported from veto-sdk/providers.
Runnable example
See the end-to-end example in:
packages/sdk/examples/google-gemini/gemini_agent.ts