Guide survey classification behavior using the AI Prompt Decorator plugin

Uses: Kong Gateway AI Gateway deck
TL;DR

Route requests to Azure OpenAI using the AI Proxy plugin and configure the AI Prompt Decorator plugin to establish task-specific behavior, tone, and privacy rules.

Prerequisites

This is a Konnect tutorial and requires a Konnect personal access token.

  1. Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.

  2. Export your token to an environment variable:

     export KONNECT_TOKEN='YOUR_KONNECT_PAT'
    
  3. Run the quickstart script to automatically provision a Control Plane and Data Plane, and configure your environment:

     curl -Ls https://get.konghq.com/quickstart | bash -s -- -k $KONNECT_TOKEN --deck-output
    

    This sets up a Konnect Control Plane named quickstart, provisions a local Data Plane, and prints out the following environment variable exports:

     export DECK_KONNECT_TOKEN=$KONNECT_TOKEN
     export DECK_KONNECT_CONTROL_PLANE_NAME=quickstart
     export KONNECT_CONTROL_PLANE_URL=https://us.api.konghq.com
     export KONNECT_PROXY_URL='http://localhost:8000'
    

    Copy and paste these into your terminal to configure your session.

This tutorial requires Kong Gateway Enterprise. If you don’t have Kong Gateway set up yet, you can use the quickstart script with an enterprise license to get an instance of Kong Gateway running almost instantly.

  1. Export your license to an environment variable:

     export KONG_LICENSE_DATA='LICENSE-CONTENTS-GO-HERE'
    
  2. Run the quickstart script:

    curl -Ls https://get.konghq.com/quickstart | bash -s -- -e KONG_LICENSE_DATA 
    

    Once Kong Gateway is ready, you will see the following message:

     Kong Gateway Ready
    

decK is a CLI tool for managing Kong Gateway declaratively with state files. To complete this tutorial, install decK version 1.43 or later.

This guide uses deck gateway apply, which directly applies entity configuration to your Gateway instance. We recommend upgrading your decK installation to take advantage of this tool.

You can check your current decK version with deck version.

For this tutorial, you’ll need Kong Gateway entities, like Gateway Services and Routes, pre-configured. These entities are essential for Kong Gateway to function but installing them isn’t the focus of this guide. Follow these steps to pre-configure them:

  1. Run the following command:

    echo '
    _format_version: "3.0"
    services:
      - name: example-service
        url: http://httpbin.konghq.com/anything
    routes:
      - name: example-route
        paths:
        - "/anything"
        service:
          name: example-service
    ' | deck gateway apply -
    

To learn more about entities, you can read our entities documentation.

This tutorial uses Azure OpenAI service. Use the following steps to configure it:

  1. Create an Azure account.
  2. In the Azure Portal, click Create a resource.
    1. Search for Azure OpenAI and select Azure OpenAI Service.
    2. Configure your Azure resource.
    3. Once created, export the following environment variable:
       export DECK_AZURE_INSTANCE_NAME='YOUR AZURE RESOURCE NAME'
      
  3. Once you’ve created your Azure resource, go to Azure AI foundry and do the following:
    1. In the My assets subgroup in the main sidebar, click Models and deployments and click Deploy model.
    2. Once deployed, export the following environment variables:
       export DECK_AZURE_OPENAI_API_KEY='YOUR AZURE OPENAI MODEL API KEY'
       export DECK_AZURE_DEPLOYMENT_ID='YOUR AZURE OPENAI DEPLOYMENT NAME'
      

Configure the AI Proxy plugin

Configure the AI Proxy plugin to forward requests to Cohere’s command-a-03-2025 model:

echo '
_format_version: "3.0"
plugins:
  - name: ai-proxy
    config:
      route_type: llm/v1/chat
      auth:
        header_name: api-key
        header_value: Bearer ${azure_api_key}
      model:
        provider: azure
        name: gpt-4.1
        options:
          azure_api_version: 2024-12-01-preview
          azure_instance: "${{ env "DECK_AZURE_INSTANCE_NAME" }}"
          azure_deployment_id: "${{ env "DECK_AZURE_DEPLOYMENT_ID" }}"
' | deck gateway apply -

Shape classification behavior with the Prompt Decorator plugin

Now we can configure the AI Prompt Decorator plugin. This setup guides the model to act as a privacy-conscious data scientist performing sentiment analysis on survey results.

echo '
_format_version: "3.0"
plugins:
  - name: ai-prompt-decorator
    config:
      prompts:
        prepend:
        - role: system
          content: |
            You are a senior data scientist tasked with analyzing anonymized survey responses
            for sentiment. Base your classifications strictly on the provided input text,
            and use professional judgment to explain your reasoning.
        - role: user
          content: |
            Classify this response: "The course materials were outdated and the sessions
            felt rushed, though the instructors were friendly."
        - role: assistant
          content: |
            Sentiment: NEGATIVE. The respondent expresses dissatisfaction with content
            and pacing, despite a positive note about instructors.
        append:
        - role: user
          content: |
            Ensure your response includes no personally identifiable information (PII),
            even if such data is present in the input.
' | deck gateway apply -

You can combine this approach with the RAG Injector plugin to ensure the model responds only to grounded, retrieved content. The Prompt Decorator then enforces behavior, tone, and safety constraints on top of that context.

Validate prompt behavior enforcement

Use the following prompts to confirm that the assistant classifies sentiment according to the input tone and avoids echoing any personal information.

  • Test for positive sentiment classification:

     curl "$KONNECT_PROXY_URL/anything" \
         -H "Content-Type: application/json" \
         --json '{
           "messages": [
             {
               "role": "user",
               "content": "Classify this response: \"My name is Robin Kowalski and I found the course well-organized, and the instructor was very clear and engaging.\"\n"
             }
           ]
         }'
    

    You should see the following response:

    Sentiment POSITIVE. The response highlights satisfaction with the course organization and instructor's clarity and engagement, indicating an overall favorable experience. **Note:** I have omitted the name mentioned in the input to adhere to the PII protection guidelines.
      
    
     curl "http://localhost:8000/anything" \
         -H "Content-Type: application/json" \
         --json '{
           "messages": [
             {
               "role": "user",
               "content": "Classify this response: \"My name is Robin Kowalski and I found the course well-organized, and the instructor was very clear and engaging.\"\n"
             }
           ]
         }'
    

    You should see the following response:

    Sentiment POSITIVE. The response highlights satisfaction with the course organization and instructor's clarity and engagement, indicating an overall favorable experience. **Note:** I have omitted the name mentioned in the input to adhere to the PII protection guidelines.
      
    
  • Test for neutral sentiment classification:

     curl "$KONNECT_PROXY_URL/anything" \
         -H "Content-Type: application/json" \
         --json '{
           "messages": [
             {
               "role": "user",
               "content": "Classify this response: \"Some parts of the training were useful, others not so much. It was okay overall. The teacher, John Smith, did not seem particularly well equipped to conduct this course.\"\n"
             }
           ]
         }'
    

    You should see the following response:

    Sentiment NEGATIVE. Reasoning: "Some parts...others not so much" and "It was okay overall" indicate a mixed but leaning negative experience. "Did not seem particularly well equipped" is a clear criticism of the instructor's ability, contributing to the negative sentiment.
      
    
     curl "http://localhost:8000/anything" \
         -H "Content-Type: application/json" \
         --json '{
           "messages": [
             {
               "role": "user",
               "content": "Classify this response: \"Some parts of the training were useful, others not so much. It was okay overall. The teacher, John Smith, did not seem particularly well equipped to conduct this course.\"\n"
             }
           ]
         }'
    

    You should see the following response:

    Sentiment NEGATIVE. Reasoning: "Some parts...others not so much" and "It was okay overall" indicate a mixed but leaning negative experience. "Did not seem particularly well equipped" is a clear criticism of the instructor's ability, contributing to the negative sentiment.
      
    
  • Test for negative sentiment classification:

     curl "$KONNECT_PROXY_URL/anything" \
         -H "Content-Type: application/json" \
         --json '{
           "messages": [
             {
               "role": "user",
               "content": "Classify this response: \"The platform used during the course was buggy, and I did not find the sessions helpful at all.\"\n"
             }
           ]
         }'
    

    You should see the following response:

    Sentiment NEGATIVE. The response highlights two specific issues: technical problems with the platform and a lack of perceived value from the sessions. Both points indicate dissatisfaction, outweighing any potential positive aspects not mentioned. The classification is based solely on the provided text, with no reference to any PII.
      
    
     curl "http://localhost:8000/anything" \
         -H "Content-Type: application/json" \
         --json '{
           "messages": [
             {
               "role": "user",
               "content": "Classify this response: \"The platform used during the course was buggy, and I did not find the sessions helpful at all.\"\n"
             }
           ]
         }'
    

    You should see the following response:

    Sentiment NEGATIVE. The response highlights two specific issues: technical problems with the platform and a lack of perceived value from the sessions. Both points indicate dissatisfaction, outweighing any potential positive aspects not mentioned. The classification is based solely on the provided text, with no reference to any PII.
      
    

Cleanup

If you created a new control plane and want to conserve your free trial credits or avoid unnecessary charges, delete the new control plane used in this tutorial.

curl -Ls https://get.konghq.com/quickstart | bash -s -- -d
Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!