Data security for AI agents and databases

AI data security on the access path. Formal labels sensitive columns, masks them in each query result based on who or what is asking, and redacts values such as SSNs from prompts before they reach a model provider, with one log for all of it.

logs · acmeexample
# customers.ssn labeled social_security_number by data discovery
ALLOW   dana (pii_access)     SELECT name, ssn FROM customers
MASKED  metabase for leo      SELECT name, ssn FROM customers
AGENT   claude-code for leo   prompt to the model provider, SSN redacted

The problem

Where sensitive data leaks when AI reads it

At runtime, sensitive data reaches AI systems in three places. Database permissions only see the first one.

  1. Query results

    Agents, dashboards and engineers read the same production tables. The database sees a service account or a shared BI login, so everyone behind it gets the same columns.

  2. Prompts and tool results

    A coding agent pulls a query result into its context window, or a support integration sends a ticket to a model provider. The SSN leaves in an HTTPS request body.

  3. Logs and transcripts

    The log that proves who sent a prompt also stores what was in it. Every audit copy of AI traffic is one more copy of the data to protect.

today · no policy on the pathexample
01
metabase · shared loginSELECT email, ssn FROM customersALLOWED
02
claude-code · leoPOST /v1/messages tool_result: 123-45-6789ALLOWED
03
log pipelinelog.llm.messages … 123-45-6789ALLOWED

# With no policy on the path, all three go through.

Solutions

Data security solutions

Find the sensitive columns first, then decide what each reader sees. Each page covers one of those two jobs in depth.

Why one policy layer

Data security for AI: one policy layer for every reader

Formal’s Connector reads each query result inside your network before a person, a BI tool or an AI agent sees it. Prompts bound for a model provider pass through Formal too: from laptops and agent sandboxes through the Endpoint, and from your own services through a Connector LLM resource. Data security for AI, the way we build it, is the policy that runs at those two points.

Every request carries an identity

People sign in through your identity provider. Agents and services connect as machine users, and cloud agents such as Cursor and Devin can authenticate with their own OIDC tokens.

The end user behind a BI login

BI tools like Metabase, Looker and Omni pass the logged-in end user with their queries, so a shared database login stops collapsing everyone behind it into one reader.

Agents get the rule of the person they work for

We first built that end-user propagation for Metabase. It turned out to fit cloud agents almost unchanged: the agent platform signs a token saying who started the session, and the policy that masks a column for a Metabase viewer applies to the agent working for that person (cloud agents and OIDC).

Columns labeled on a schedule

The Data Discovery Satellite scans your schemas every 6, 12, 18 or 24 hours, or on your own cron. It labels columns with more than 50 built-in labels such as email_address, social_security_number and medical_record_number, plus any regex or prompt labels you add.

Matchers, label locking and scan schedules ›

Rego that matches labels, not tables

Policies are Rego, and they match on data labels instead of table names. When a new table with an SSN column ships, the next scan labels it and the masking policy you already run covers it.

One log for queries and prompts

Both decisions land in one log, with the person or agent behind each query and each prompt.

On the access path

How Formal secures data on the access path

Connector

Masking in the result, inside your network

The Connector runs in your network, on ECS, any Kubernetes cluster or Docker. It injects the database credential, so people and agents connecting through it never hold one.

  • Masks columns in Postgres, MySQL, MariaDB, Redshift, Snowflake and BigQuery results
  • Masks MongoDB fields by path, and CSV objects read from S3
  • Who can reach which database at all, with approvals and query-level rules, is database access management
Database access management ›
postgres · customersexample
metabase for leo> SELECT name, ssn FROM customers
namessn
Ana Ruiz[REDACTED]
Tom Berg[REDACTED]
Lea Moss[REDACTED]
3 rows · policy mask-ssnMASKED
Endpoint

Prompts checked on the machine where they start

The Endpoint covers the machines where prompts start: laptops, servers and agent sandboxes.

  • On macOS and Linux, Transparent Mode intercepts LLM traffic with no client changes
  • Also runs as a Kubernetes sidecar
Formal Endpoint ›
endpoint · leo's laptopexample
14:02:11claude-code for leoPOST /v1/messages tool_result: [REDACTED-SSN]MASKED
14:02:30claude-code for leoPOST /v1/messagesALLOWED
Logs

Logs that don't become a second copy

The Control Plane manages configuration and can’t interact with your data. Logs do reach it, and that’s why log schemas can drop prompt text from logs or encrypt it with your own key.

  • Start with one labeled column and the identities that read it
  • Run the masking policy in dry-run first: the log shows which people, dashboards and agents would have received masked values, before anyone does
policy · mask-ssnexample
dry runmetabase for leoSELECT name, ssn FROM customersDRY RUN
dry runclaude-code for leoSELECT ssn FROM customersDRY RUN
enforcemetabase for leoSELECT name, ssn FROM customersMASKED

In the database

An SSN in a column: mask it by data label

A Social Security number shows why each path needs its own rule. In the database it sits in a labeled column, and this response-stage policy from the masking docs replaces it in every result.

  • Matches the social_security_number label, whatever the table
  • Other mask types: hashing, fake values and partial redaction
  • Per-viewer rules for BI tools, and Postgres and Snowflake walkthroughs, are on the data masking page
Data masking software ›
mask-ssn.regorego
package formal.v2

import future.keywords.if

response := {
  "action": "mask",
  "type": "redact.constant_characters",
  "sub_type": "redact.constant_characters",
  "redact": "[REDACTED]",
  "columns": columns
} if {
  columns := [col |
    col := input.row[_]
    col["data_label"] == "social_security_number"
  ]
  count(columns) > 0
}

In a prompt

An SSN in a prompt: rewrite the request body

In a prompt there’s no column, so there’s no label to match. The request-stage rewrite from the same docs page looks for the pattern in message text and tool results and rewrites the body before it goes upstream, without ending the agent’s session.

  • Checks text and tool_result parts of each message
  • Applies to LLM resources only
  • Prompts and tool results get the channel-by-channel treatment on AI data loss prevention
AI data loss prevention ›
redact-ssn-in-prompts.regorego
package formal.v2

import future.keywords.if
import future.keywords.in

ssn_pattern := `\b\d{3}-\d{2}-\d{4}\b`

request := {
  "action": "rewrite",
  "body": regex.replace(input.http.body, ssn_pattern, "[REDACTED-SSN]"),
  "reason": "Redact SSNs from LLM request messages",
} if {
  input.resource.technology == "llm"
  some msg in input.llm.messages
  some part in msg.content_parts
  part.type in {"text", "tool_result"}
  regex.match(ssn_pattern, part.text)
}

Definition

What is AI data security?

AI data securitynoun

AI data security is the work of keeping sensitive data (PII, PHI, credentials, payment data) from being exposed by the AI systems that train on it, query it at runtime, send it to model providers or keep it in logs.
  • Training-time controls

    They deal with dataset provenance and poisoning, and have solid public guidance: CISA, the NSA and the FBI published best practices for securing data used to train and operate AI systems in May 2025.

  • Runtime controls

    They decide what an agent can read, what a prompt carries out of your network and what the audit trail stores. Formal works on the runtime half.

  • An access decision

    Training guidance doesn’t change what happens when a coding agent with a read-only role selects every customer email in a table. That one is an access decision: who or what is asking, which columns come back, and where the result goes next.

  • Least privilege and redaction

    The OWASP entry on sensitive information disclosure lists least-privilege access and pattern-based redaction among its mitigations, and Formal enforces both on the network, outside the agent and outside the database. Our Academy guides on database security and LLM security cover each side more broadly.

Coverage

Databases and LLM paths covered

Masking runs on results from these databases. Prompts are covered from your own services through a Connector LLM resource, and from machines running the Endpoint.

Masking types ›

Limits

Where Formal's data security for AI fits

Some limits decide where this fits.

  • Only traffic through the Connector

    Masking applies only to traffic that goes through the Connector. A direct connection that skips it returns raw data, so the Connector has to be the only route to the database.

    Only route
  • Responses that aren't masked

    Formal doesn’t mask MCP, Redis or gRPC responses, and a column mask on ClickHouse fails closed.

    Not masked
  • Labels are for database columns

    Data labels only apply to database columns. On the prompt path you write the pattern yourself. Prompt labels need AWS Bedrock in your own account; regex labels need no model.

    Columns only
  • Windows without transparent interception

    On Windows the Endpoint is generally available, but it doesn’t intercept LLM traffic transparently yet.

    Not yet

Platform

The products behind it

Connector

Formal Connector

Runs in your network in front of Postgres, MySQL, Snowflake, BigQuery, MongoDB, S3 and LLM APIs. It masks labeled columns in each result and logs every query with the person or agent behind it. How the Connector works.

Endpoint

Formal Endpoint

Runs on laptops, servers and agent sandboxes. On macOS and Linux it intercepts LLM traffic with no client changes, so prompt policies apply before a request leaves the machine.

Customer proof

Businesses
300K+
Employees
2,400
Implementation
5 days
Requests secured
100K+
“With Formal, we quickly set up automated data protection in complex scenarios, allowing our Privacy Security team to agilely support business needs.”
Justin Collins
Justin Collins
Head of Security, Gusto
Read the Gusto story ›

FAQ

Questions buyers ask us

How do I protect my data from AI?

Decide which data no model or agent should see in the clear, find where it lives, and enforce that rule at the point where AI reads it. With Formal that means labeling sensitive columns, masking them for agent and BI identities, redacting matching values from prompts, and keeping logs that don’t turn into a second copy. Contract terms with model providers and training opt-outs matter too, and they sit outside anything a network proxy controls.

How is AI used in data security?

In two ways. AI data security usually means protecting data from AI systems, which is what this page covers. The other meaning is using a model to do security work: Formal’s prompt labels send a column’s name, data type and up to 10 sampled values to Claude Haiku on AWS Bedrock in your own account, and ask whether a label applies. Regex labels do the same job with no model involved.

What are the top AI data security risks?

At runtime: agents and BI tools with broad read access to production tables, sensitive values carried to model providers in prompts and tool results, and copies of both in logs and transcripts. OWASP ranks sensitive information disclosure second (LLM02) in its 2025 Top 10 for LLM applications. Training-time risks such as data poisoning and model inversion are real as well; Formal doesn’t address them.

Is Formal a data security platform?

Not in the analyst sense. A data security platform discovers and protects data at rest across clouds, SaaS apps, file shares and endpoints, often with encryption and key management. Formal secures data in motion on the access path: database queries and their results, prompts to model providers, and the logs of both, decided per identity. It discovers and classifies database columns, but it doesn’t scan file shares or SaaS apps, handle encryption at rest, manage backups or run email DLP.

Can you mask PII before it reaches an LLM?

Yes, for values you can describe with a pattern. For LLM data protection, Formal runs request-stage policies that find SSNs, card numbers or keys in message text and tool results and either rewrite the body before it leaves or block the request. There’s no built-in detector for free-form prompt text. Gusto runs a Formal HTTP Connector between Salesforce and its LLM provider so PII and PHI in support tickets are masked by policy first (case study).

Does Formal replace the masking built into my database?

It can sit next to it. Masking built into a warehouse lives in that one engine and follows its roles. Formal applies one label-based rule to Postgres, MySQL, MariaDB, Redshift, Snowflake and BigQuery results, MongoDB fields and CSV objects from S3, and it can decide on the end user behind a shared BI login, which database roles never see.

Mask one sensitive column for every reader

Label it, write one policy, and see who reads it in the logs.