← All news

News / Learn / Production & LLMOps

How should AI apps handle private data?

You'll be able to find where private data leaks in an AI app and cut that exposure before users are hurt.

An AI app sends text to a model, and that text often includes personal or confidential data. Every place the text travels, rests, or gets logged is a possible leak. Handling private data well means knowing what you send, where it goes, and how long it stays.

Users trust you with names, emails, health details, contracts, and code. A leak can break that trust, break the law in some places, and break your contracts with customers. Founders often add AI features quickly, so data flows get built without anyone mapping them.

Start by listing the data your app touches. Separate what the user typed, what your system added (account IDs, documents pulled from a database), and what the model returns. Mark each item as private or not. Private includes anything that identifies a person or reveals a business secret.

Next, trace the path. Data goes from the user's browser to your server, then to a model provider, sometimes to a vector database or a logging tool, and back. Each hop is a place where a third party might see it, a log might store it, or a backup might keep it. Read each provider's data terms. Check whether they use API inputs for training, how long they retain them, and where they process them.

Then reduce what you send. Remove fields the model does not need. Replace names and emails with placeholder tokens, and restore them after the response if needed. Filter retrieved documents so a user only sees chunks they are allowed to see. Enforce access control in your own code before retrieval, not inside the prompt. A model asked not to reveal something can still reveal it.

Finally, control storage. Decide what you log. Logs of full prompts and responses are useful for debugging but often hold the most sensitive text. Redact before writing, set short retention periods, and restrict who can read logs. Encrypt data at rest and in transit. Give users a way to delete their data, and make sure that deletion reaches your logs, vector stores, and caches.

A simple redaction step that replaces emails and phone numbers before a prompt leaves your server.

import re

EMAIL = re.compile(r"[\w.+-]+@[\w-]+\.[\w.]+")
PHONE = re.compile(r"\+?\d[\d\s().-]{7,}\d")

def redact(text: str) -> tuple[str, dict]:
    mapping = {}
    def swap(match, label):
        key = f"[{label}_{len(mapping)}]"
        mapping[key] = match.group(0)
        return key
    text = EMAIL.sub(lambda m: swap(m, "EMAIL"), text)
    text = PHONE.sub(lambda m: swap(m, "PHONE"), text)
    return text, mapping

def restore(text: str, mapping: dict) -> str:
    for key, value in mapping.items():
        text = text.replace(key, value)
    return text

safe, mapping = redact("Contact jane@example.com or +1 555 010 2030.")
# send `safe` to the model, then call restore() on the reply

A short sketch to show the idea. Check the official docs of the tool you use.

  • Assuming the provider never keeps your data Read the provider's current data use and retention terms for your plan. Turn off any setting that allows training on your inputs, and record what you chose.
  • Enforcing permissions only in the prompt Filter documents by the user's permissions in your own code before they reach the model. Models can be talked into ignoring instructions.
  • Logging full prompts and responses Redact sensitive fields before writing logs, keep retention short, and limit who can read them.
  • Forgetting caches, embeddings, and backups Include vector stores, caches, and backups in your deletion process so a user's data does not survive in them.

Learn about data processing agreements, the principle of least privilege, and how your region's privacy law defines personal data. Also study prompt injection, since an attacker can try to pull private data out of your system through the model.

Can I send customer data to a model API at all?

Often yes, under the right terms. Check the provider's data use policy, sign any required data processing agreement, minimize what you send, and tell users what you do with their data.

Does redacting data break the model's answers?

It can if you remove context the model needs. Replace values with consistent placeholders so meaning stays intact, then restore them in the output.

Is self-hosting a model automatically private?

It keeps data off third-party servers, which helps. You still need access control, logging discipline, and secure storage on your own infrastructure.

Should I log prompts for debugging?

Log what you need, with sensitive fields redacted. Full raw logs are a common source of leaks.

Written with AI by CapyLaunch. Spotted a mistake? Email hello@capylaunch.com.