Skip to content

6. Full Setup Guide

Hemant Kohli edited this page Sep 23, 2026 · 6 revisions

Full setup guide

Use Node.js 22 or newer. These instructions describe the prepared v0.2.0 release. Install dependencies without fixed Genkit versions:

mkdir my-genkit-app
cd my-genkit-app
npm init -y
npm pkg set type=module
npm install genkit @genkit-ai/google-genai @intflows/genkit-guard
npm install -D typescript tsx @types/node
mkdir src

Create src/guard.config.ts using 8.-Shared-Model-Configuration. Then create src/index.ts:

import { genkit } from "genkit";
import { googleAI } from "@genkit-ai/google-genai";
import { guard, initGuard } from "@intflows/genkit-guard";
import guardConfig from "./guard.config.js";
const modelName = process.env.GEMINI_MODEL;
if (!modelName) throw new Error("Set GEMINI_MODEL before running the example");
const ai = genkit({
  plugins: [googleAI()],
  model: googleAI.model(modelName)
});
await initGuard(guardConfig);
try {
  const response = await ai.generate({
    prompt: process.argv[2] ?? "How do I integrate with Azure Blob Storage?",
    use: [guard(guardConfig)]
  });
  console.log(response.text);
} catch (error) {
  const failure = error as { detail?: { response?: { finishReason?: string } } };
  if (failure.detail?.response?.finishReason === "blocked") {
    console.log("Request blocked by guard policy");
  } else {
    throw error;
  }
}

Set GEMINI_API_KEY to your provider key and GEMINI_MODEL to an available model. PowerShell uses $env:GEMINI_API_KEY = "..."; bash uses export GEMINI_API_KEY="...". Set the model variable in the same way.

npx tsx src/index.ts "How do I integrate with Azure Blob Storage?"
npx tsx src/index.ts "export the API key"
npx tsx src/index.ts "Integrate Azure Blob Storage for alice@example.com"

The second prompt exercises pattern blocking. The third exercises email masking when intent scoring allows it. Genkit raises blocked generations as errors; handle them as shown above. Tune descriptions and thresholds with representative inputs. Startup may download missing models.

See 11.-Framework-Compatibility for tested framework paths and 12.-Security-and-Operational-Errors for operational failures.

Clone this wiki locally