DEV Community

Cover image for How to Stop PII and Secrets From Being Sent to AI Tools
Marco Rinaldi
Marco Rinaldi

Posted on

How to Stop PII and Secrets From Being Sent to AI Tools

How to Stop PII and Secrets From Being Sent to AI Tools

A multi-layered approach using data classification, AI gateways, and endpoint governance is the most effective way to prevent sensitive data from reaching third-party AI models. Bifrost, an open-source AI gateway, provides tools to implement these controls.

The adoption of AI tools, from large language models (LLMs) to specialized APIs, has introduced a significant security challenge: preventing sensitive data from leaving an organization's control. Employees regularly copy-paste internal documents, customer data, and even code snippets containing credentials into prompts. When this data is sent to a third-party AI provider, it can be stored, logged, or even used for model training, creating serious compliance and security risks.

Preventing this data leakage requires a deliberate, multi-layered strategy. It is not enough to simply write a policy document; engineering teams must implement technical controls to identify, block, and audit the flow of sensitive information. This article outlines a four-layer approach to secure AI adoption.

Layer 1: Identify and Classify Sensitive Data

You cannot protect data if you are not aware of its existence and location. The first step in any data protection strategy is to discover and classify the sensitive information within your systems. This process involves scanning data repositories, both structured (databases) and unstructured (documents, source code), to tag information that should never be sent to an external AI.

Common categories of sensitive data include:

  • Personally Identifiable Information (PII): Names, email addresses, phone numbers, government ID numbers. This is often regulated under laws like GDPR in Europe and various state-level privacy laws in the US.
  • Protected Health Information (PHI): Medical records and other patient data protected by regulations like HIPAA in the United States.
  • Secrets and Credentials: API keys, database passwords, private certificates, and authentication tokens.
  • Intellectual Property (IP): Proprietary source code, financial data, and internal strategy documents.

Automated data discovery tools can scan for patterns (like credit card numbers or API key formats) and use named entity recognition (NER) models to identify PII in unstructured text. The output of this process is an inventory of what data is sensitive and where it resides, which informs the policies you will enforce in the next layers.

A magnifying glass scanning a document, with icons representing PII (person icon), secrets (key icon), and intellectual

Layer 2: Intercept and Redact Traffic with an AI Gateway

An AI gateway is a centralized proxy that sits between your developers or internal applications and the external AI services they call. By routing all AI traffic through a single point, you can inspect every prompt and response, enforcing security policies before data leaves your network. This is the primary technical control for preventing data leakage from applications that are configured to use it.

Key capabilities for a gateway include:

Secrets and PII Detection

The gateway can use guardrails to scan outbound prompts for sensitive data. This is often done with a combination of techniques:

  • Regular Expressions (Regex): Effective for structured data like Social Security numbers, credit card numbers, or specific internal ID formats.
  • Named Entity Recognition (NER): Machine learning models that can identify entities like names, locations, and organizations in unstructured text.
  • Secrets Scanning: Algorithms that look for high-entropy strings and patterns characteristic of API keys and other credentials, similar to tools like Gitleaks.

The Bifrost AI gateway includes built-in guardrails for secrets detection and allows for the configuration of custom regex patterns to catch organization-specific data formats.

Redaction and Masking

When a guardrail detects sensitive data, the gateway can be configured to either block the request entirely or, more commonly, to redact or mask the data. Masking replaces the sensitive data with a generic placeholder (e.g., [REDACTED_EMAIL]) before forwarding the prompt to the AI model. This allows the user to get a useful response from the AI without exposing the underlying sensitive information.

Here is an example of a prompt before and after redaction by a gateway:

Original Prompt:

Summarize this customer support ticket for escalation. The user, Jane Doe (jane.doe@example.com), is reporting that her API key (sk-aBcdEfgH12345IjkLmnoPqrsTuvWxYz) is not working.
Enter fullscreen mode Exit fullscreen mode

Redacted Prompt Sent to AI:

Summarize this customer support ticket for escalation. The user, [REDACTED_NAME] ([REDACTED_EMAIL]), is reporting that her API key ([REDACTED_SECRET]) is not working.
Enter fullscreen mode Exit fullscreen mode

This ensures the AI model receives the context it needs without ever seeing the actual PII or secret.

Layer 3: Enforce Endpoint Governance

A gateway is effective for AI traffic from your servers and applications, but it does not cover "shadow AI"—the ungoverned use of AI tools on employee workstations. Developers using Claude Desktop, analysts using the ChatGPT web interface, or anyone using a CLI-based coding agent can easily send sensitive data to AI providers, completely bypassing your server-side gateway.

This is where endpoint governance becomes critical. An endpoint agent installed on employee machines can intercept AI-related traffic from any application and route it through your central gateway.

A laptop computer at one end, and cloud icons representing AI services at the other. A digital stream flows from the lap

This approach ensures that the same security policies, guardrails, and audit logs that apply to your production applications also apply to every employee's daily AI usage. A tool like Bifrost Edge is designed for this purpose, extending gateway governance to desktop apps, web browsers, and coding agents without requiring users to change their workflows. This closes the "last mile" security gap that most organizations miss.

Layer 4: Implement Strong Access Controls and Auditing

Finally, a robust security posture relies on strong access control and comprehensive auditing. Instead of sharing a single, powerful organizational API key, use a gateway that supports virtual keys.

Virtual keys allow you to provision unique credentials for each user, team, or application. Each virtual key can have its own budget, rate limits, and access rules (e.g., restricting it to a specific set of models). This follows the principle of least privilege and dramatically reduces the risk associated with a compromised key.

All actions, from prompt submission to blocked requests, should be recorded in immutable audit logs. These logs are essential for demonstrating compliance with regulations like SOC 2 and for investigating potential security incidents. An AI gateway provides a centralized point for generating these logs across all AI usage in the organization.

By combining these four layers—data classification, a central gateway with guardrails, endpoint governance, and strong access controls—organizations can confidently adopt AI tools while keeping their most sensitive data secure.

Sources

Top comments (0)