npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@intflows/genkit-guard

v0.0.7

Published

Intflows Genkit Guard

Readme

@intflows/genkit-guard

Lightweight Intent, PII, and Safety Guardrails for Genkit

@intflows/genkit-guard provides a modular guardrail layer for Genkit flows.
It adds semantic intent validation, PII masking/unmasking, and prompt‑injection detection with minimal configuration.

This library is designed for developers who want practical, production‑ready safety controls without heavy dependencies or complex setup.


✨ Features

  • Semantic Intent Guarding
    Uses MiniLM embeddings to ensure prompts match allowed intents.

  • PII Detection & Masking
    Detects emails, phone numbers, names, and AU‑specific identifiers.
    Replaces PII with reversible tokens before sending to the LLM.

  • Automatic Unmasking
    Restores original PII in the model’s response, even inside structured JSON.

  • Prompt Injection Detection
    Blocks jailbreak attempts using pattern‑based heuristics.

  • Model‑Light Architecture
    The package uses local all-MiniLM-L6-v2 and bert-base-NER Models, these Models are downloaded once and cached locally.

  • Drop‑in Genkit Middleware
    Works with ai.generate, ai.generateStream, and Genkit flows.


📦 Installation

## Install the package
npm install @intflows/genkit-guard

This library uses lightweight transformer models (MiniLM + BERT‑NER).

Download them once.

## Download the transformer models (MiniLM + BERT‑NER)
node node_modules/@intflows/genkit-guard/scripts/download-model.js

Models are cached locally and reused across runs.


🚀 Quick Start

1. Initialize Local folder

# 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

2. Update genkit

import { guard, initGuard } from "@intflows/genkit-guard";

await initGuard();

const response = await ai.generate({
  prompt: "How do I integrate with Azure Blob Storage?",
  use: [
    guard({
      intent: {
        mode: "semantic",
        allowedIntent: "integration",
        semantic: {
          threshold: 0.7,
          intents: {
            integration: "Azure Blob, APIs, workflows"
          }
        }
      },
      pii: { reversible: true }
    })
  ]
});

You Can also check the full step by step guide here:

Intflows Wiki

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"

Image showing Generation Blocked

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 [email protected]"

Image showing PII data masked


🧠 How It Works

1. Intent Guard

  • Embeds the user prompt + intent descriptions using MiniLM
  • Computes cosine similarity
  • Blocks prompts below threshold
  • Detects jailbreak patterns like:
    • “ignore previous instructions”
    • “you are a hacker”
    • “export the API key”

2. PII Masking

Before the LLM sees the prompt:

"Email [email protected]" → "Email [[EMAIL_0]]"

Detected PII includes:

  • Emails
  • Phone numbers
  • Names (NER)
  • AU identifiers (Medicare, TFN, ABN, etc.)

3. LLM Call

The masked prompt is sent to the model.

4. Response Unmasking

After the LLM responds:

"Send a confirmation email to [[EMAIL_0]]" → "Send a confirmation email to [email protected]"

⚙️ Configuration

Intent Guard

intent: {
  mode: "semantic",
  allowedIntent: "intent_question",
  semantic: {
    threshold: 0.7,
    intents: {
      intent_question: "Description of allowed intent"
    }
  }
}

PII Guard

pii: {
  reversible: true
}

🛡️ Why This Library Exists

Genkit provides a powerful LLM framework, but production systems need:

  • intent boundaries
  • PII protection
  • jailbreak resistance
  • predictable behavior

This library adds those guardrails without heavy dependencies or complex setup.


Contributing

We plan to:

  1. Extend the utility by adding Auth and Tool Middleware in further stages.
  2. Add more filter types for common malicious prompts.
  3. Add more patterns for custom PII masking.

Contributions are welcome — whether it’s bug reports, new guard modules, model improvements or enhancements. This project aims to stay lightweight, modular, and production‑ready, so thoughtful contributions are appreciated.

📄 License

Apache‑2.0