Skip to main content

AI Prompt Plugin

Updated Feb 26, 2023 ·

Overview

The AI Prompt Guard plugin helps monitor and filter AI-generated or user-submitted content for compliance or security purposes.

  • Detects and blocks harmful or prohibited prompts.
  • Integrates AI models to analyze and validate input data.

Lab Environment

This lab tests a Kong API Gateway deployment using a FastAPI endpoint. To simplify, both the containerized Kong API Gateway and the FastAPI endpoint are installed locally on a Windows 10 machine. A Docker Compose file is used to deploy Kong, along with other applications like Prometheus, Zipkin, the ELK Stack, and more.

info

Make sure that you have installed Docker Desktop.

Simply installing Docker in WSL2 without Docker Desktop may introduce some issue when configuring the communication between the containerized Kong API Gateway and the FastAPI application that is installed on the local host.

Pre-requisites

Enable AI Prompt Guard Plugin

To enable the plugin, go to Kong Manager > Plugins > New Plugin > Traffic Control > Select AI Prompt Guard. As an example, we can allow any prompts related to Python while blocking prompts pertaining to Java. To do this, specify them in the Allow and Deny Patterns:

FieldValue
Allow Pattern.*Python.*
Deny Patterns.*Java.*

info

You can disable all other plugins for now.

Test the plugin via Postman

Setup Postman

To setup Postman, please see Testing with Postman

Open Postman and create a new request. Rename it to FastAPI via Kong - AI Prompt Guard. Enter the URL below:

http://localhost:8000/kong/healthy 

In the Body tab, select raw and add the prompt:

{
"messages": [
{
"role": "user",
"content": "How do you run a Python script?"
}
]
}

Click Send. Note that it doesn't return any answer to the question/prompt, it will just return "healthy".

If we change the prompt to ask about Java, we'll get Bad Request error.