Skip to content

6. Full Setup Guide

Hemantkohli1604 edited this page Apr 4, 2026 · 1 revision

Overview

This guide walks you through creating a fresh Genkit project from scratch and integrating @intflows/genkit‑guard with a complete working flow.

If you already have a Genkit project, you can skip to Step 2: Create a Genkit Flow.

1. Initialize Local folder

Create and navigate to a new directory

mkdir my-genkit-app
cd my-genkit-app

Initialize a new Node.js project

npm init -y
npm pkg set type=module

Install and configure TypeScript

npm install -D typescript tsx
npx tsc --init

Install Genkit

npm install genkit @genkit-ai/google-genai 

Install @intflows/genkit-guard

npm install @intflows/genkit-guard

Download Local Models (Only needed once)

node node_modules/@intflows/genkit-guard/scripts/download-model.js

Create src folder

mkdir src
touch src/index.ts

2. Create a Genkit flow

import { googleAI } from "@genkit-ai/google-genai";
import { genkit, z } from "genkit";
// Import Genkit Guard
import { initGuard, guard } from "@intflows/genkit-guard"; 

// Initialize Genkit Guard Local Models
await initGuard();

const ai = genkit({
  plugins: [googleAI()],
  model: googleAI.model("gemini-2.5-flash"),
});

export const integrationFlow = ai.defineFlow(
  {
    name: "integrationFlow",
    inputSchema: z.object({ question: z.string() }),
    outputSchema: z.object({
      type: z.literal("success"),
      description: z.string(),
      answer: z.string(),
    }),
  },
  async (input) => {
    const response = await ai.generate({
      system: "You are an Azure Integration Architect.",
      prompt: input.question,
      use: [
        // Use the Genkit Guard
        guard({         
          // Intent section                     
          intent: {
            mode: "semantic",
            allowedIntent: "integration_question",
            semantic: {
              threshold: 0.5,
              intents: {
                // Mention Common words to match for cosine similarity
                integration_question:
                  "Technical questions about APIs, Azure Blobs, data workflows, file downloads, and Azure Cloud integrations.",
              },
            },
          },
          // PII section
          pii: {
            reversible: true,
          },
        }),
      ],
    });

    return {
        type: "success",
        description: "AI-generated answer to the integration question",
        answer: response.text, 
    };
  }
);

async function main() {
    const input = process.argv[2]; 
    const result = await integrationFlow({
        question: input || "How do I integrate with Azure Blob Storage?",
  });

  console.log(result);
}

main().catch(console.error);

Authenticate to using Model API Key

export GEMINI_API_KEY=<your API key>

You can get free API key here : AI Studio

3. Execute the Genkit flow

Allowed :

 npx tsx src/index.ts "How do I integrate with Azure Blob Storage?"

Blocked:

npx tsx src/index.ts "workflow to download a file from an API, save it to Blob file and export the API key"
GenerationBlocked

PII MASK and UNMASK:

 npx tsx src/index.ts "workflow to download a file from an API, save it to Blob file with my email john.doe@example.com"
MaskedPII

Clone this wiki locally