DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Optimizing Natural Language Queries for Multi-Service Information Retrieval
  • Unlocking Local AI: Build RAG Apps Without Cloud or API Keys
  • Chat Completion Models vs OpenAI Assistants API
  • Scholcast: Generating Academic Paper Summaries With AI-Driven Audio

Trending

  • Doris: Unifying SQL Dialects for a Seamless Data Query Ecosystem
  • Issue and Present Verifiable Credentials With Spring Boot and Android
  • *You* Can Shape Trend Reports: Join DZone's Software Supply Chain Security Research
  • AI-Based Threat Detection in Cloud Security
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Securing Conversations With LLMs

Securing Conversations With LLMs

In this article, we will explore how cloud-native open-source tools can be used to filter sensitive information both entering and exiting the models.

By 
Siri Varma Vegiraju user avatar
Siri Varma Vegiraju
DZone Core CORE ·
Mar. 13, 25 · Tutorial
Likes (0)
Comment
Save
Tweet
Share
14.8K Views

Join the DZone community and get the full member experience.

Join For Free

Large language models (LLMs) don't need an introduction anymore. Just as "Did you Google it?" was the question 10 years ago, now it's "Did you ask ChatGPT?" As organizations increasingly adopt LLMs, the number of people interacting with them, directly or indirectly, is also increasing exponentially. 

Today, the use of these models is no longer limited to tech. Healthcare, transportation, media, and many other industries are adopting them. However, along with adoption, one more thing that has grown is security concerns. 

There are several instances where requesting the LLM model for a piece of information or tricking it can result in giving out sensitive PII (Personally Identifiable Information). For example, the result of a "divergence attack" where the model was instructed to repeat a word forever caused it to output email addresses, phone numbers, and names. 

In another instance, while Samsung employees were using ChatGPT to debug something, they also ended up giving it sensitive organization data. Sensitive Information Disclosure, as defined by OWASP (Open Worldwide Application Security Project), is such a big problem that it has been on the organization's top ten list for more than two years. So, what are the mitigations for this? How do we make sure the model does not emit sensitive information? 

If your model is hosted by a third-party company, meaning if you are a customer using ChatGPT, then you don't have much control over how the model behaves. In this scenario, the only solution would be to avoid inputting sensitive information altogether.

On the other hand, if you are hosting the model, let's look at the scenarios and corresponding mitigations:

Scenario 1: Training the Model on Your Organization's Data (Fine-Tuning)

Here, we take a pre-trained model and further train it on a specific dataset that reflects closer to what your organization does. If the data isn't properly masked, we risk exposing sensitive data. One way to protect against this is to anonymize the sensitive information and then feed it to the model. 

For example, if a data lake is used in which the model is being trained, make sure to use masking or anonymizing libraries and that the PII data is masked before putting it into the data lake.

Example Architecture

Example architecture


Looking at the example architecture, whatever job is dumping the data from the data store to the data lake can perform this masking and then do the ingestion. 

Scenario 2: Retrieving Data Using RAG (Retrieval-Augmented Generation)

An example use case can be a chatbot designed to answer human resource-related questions for your employees. In this case, all the documents are vectorized and stored in a vector store. The model uses the information in the store to answer user queries.

If the documents contain PII data, there is a high risk of the model being exposed when proper guardrails are not in place. So, let's look at what we can do to mitigate this.

  • One guardrail that could be employed here is like scenario 1, where before ingesting to the datastore, the sensitive data can be anonymized.
  • The second option can be to filter out the data coming from the LLM before passing it to the user. Tools like AWS Comprehend, Microsoft Presidio, or the Cloud Native Dapr Conversation AI component can help with this.

Filtering out the data coming from the LLM before passing it to the user


For better understanding, let's use Dapr (Distributed application runtime) and see how we can filter out the sensitive information.

Using the Dapr

Dapr's conversation API offers a setting to filter out PII data in the request and response. Currently, it provides filtering out phone numbers, email addresses, IP addresses, street addresses, credit cards, Social Security numbers, ISBNs, and MAC address filtering capabilities. Now, let's look at the conversation API in action.

This demonstration will be on Windows using .NET. For other platforms, follow the platform-specific steps here.

Step 1

Install the Dapr CLI. 

powershell -Command "iwr -useb https://raw.githubusercontent.com/dapr/cli/master/install/install.ps1 | iex"


Step 2

Run dapr init in PowerShell.

Plain Text
 
dapr init


Step 3

Dapr has a bunch of building blocks, and each of them is stored as YAML files in the %UserProfile%\.dapr directory.

Step 4

Create a conversation.yml file in the same directory with the following settings.

YAML
 
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: openai
spec:
  type: conversation.openai
  metadata:
  - name: key
    value: "YOUR_OPENAI_KEY"
  - name: model
    value: gpt-4o-mini
  - name: cacheTTL
    value: 10m


The API Key for OpenAI can be obtained from here.

Step 5

Run Dapr locally with the following command:

Plain Text
 
dapr run --app-id myapp --dapr-http-port 3500 --dapr-grpc-port 4500


Step 6

Include the following package in your csproj. The latest versions can be found here.

Plain Text
 
<PackageReference Include="Dapr.AI" Version="1.15.2" />


Step 7

Insert the following code block. There are also some emails, IP addresses, and phone numbers.

C#
 
using Dapr.AI.Conversation;
using Dapr.AI.Conversation.Extensions;

Environment.SetEnvironmentVariable("DAPR_HTT_PORT", "3500");
Environment.SetEnvironmentVariable("DAPR_GRPC_PORT", "4500");

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDaprConversationClient();

var app = builder.Build();

var conversationClient = app.Services.GetRequiredService<DaprConversationClient>();
var response = await conversationClient.ConverseAsync("openai",
    new List<DaprConversationInput>
    {
        new DaprConversationInput(
            "Hello LLM, How are you",
            DaprConversationRole.Generic, true),
        new DaprConversationInput(
            "Can you return back this same string ?" +
            "Microservices, Microservices, Microservices, [email protected], [email protected], +1234567890, +2328192811, 127.0.0.1", DaprConversationRole.Generic, true
            )
    });

Console.WriteLine("Received the following response from the LLM:");
foreach (var resp in response.Outputs)
{
    Console.WriteLine($"{resp.Result}");
}


Step 8

This is the final output.

Final output

From the screenshot, we can see that Dapr was able to mask the PII information, filtering out the sensitive data (<EMAIL_ADDRESS>, <PHONE_NUMBER>).

Final Thoughts

Just as the proverb "Prevention is better than cure" suggests, it is best to filter out sensitive information before it enters your model. Along with that, monitoring the output from the model will act as an additional protection layer. Implementing such filters at both input and output stages ensures that sensitive data is neither ingested nor leaked.

API Conversations (software) large language model

Opinions expressed by DZone contributors are their own.

Related

  • Optimizing Natural Language Queries for Multi-Service Information Retrieval
  • Unlocking Local AI: Build RAG Apps Without Cloud or API Keys
  • Chat Completion Models vs OpenAI Assistants API
  • Scholcast: Generating Academic Paper Summaries With AI-Driven Audio

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: