Sub topic 12
Data privacy and compliance constraints
This chapter assumes you have called a hosted model API before and know that a prompt is sent over the network to a provider. It covers what privacy and compliance rules change about your model choice. It does not cover legal advice. Ask your legal or security team for the final call.
Where your data goes
With a hosted API, every prompt and response leaves your network and is processed on the provider's servers. With a self-hosted open-weight model, the data stays on machines you control. That difference is often the first filter in model selection.
Questions to ask about any provider
Read the provider's data terms before you send real data. Find answers to these questions:
- Is my data used to train or improve models? Many providers say no for paid API use, but check the exact wording.
- How long are prompts and outputs retained, and who can read them (for example for abuse monitoring)?
- In which region is the data processed and stored?
- Does the provider sign the agreements you need, such as a data processing agreement?
- Which certifications does the provider hold, such as SOC 2 or ISO 27001?
Common constraints
| Constraint | What it usually means for model choice |
|---|---|
| Personal data (for example GDPR) | You need a lawful basis, a data processing agreement, and control over where data is processed. |
| Health data (for example HIPAA) | The provider must agree to specific terms before you send protected data. |
| Data residency rules | Data must stay in a country or region. Check the provider's regional endpoints, or self-host. |
| Customer contract limits | Your clients may forbid sending their data to third parties. |
| Trade secrets and source code | Policy may require that the data never leaves your network. |
Reduce what you send
Privacy is not only a hosting decision. You can lower risk by sending less. Remove or mask identifiers before the prompt leaves your system.
import re
EMAIL = re.compile(r"[\w.+-]+@[\w-]+\.[\w.-]+")
PHONE = re.compile(r"\+?\d[\d\s().-]{7,}\d")
def redact(text: str) -> str:
text = EMAIL.sub("[EMAIL]", text)
return PHONE.sub("[PHONE]", text)
print(redact("Contact [email protected] or +44 20 7946 0958 about the refund."))
# Contact [EMAIL] or [PHONE] about the refund.Regular expressions miss names, addresses, and free-form identifiers. Treat this as one layer, not a guarantee.
How this affects the choice
Self-hosting is not automatically compliant. You become responsible for access control, encryption, patching, and audit trails. A large hosted provider with strong certifications and a signed agreement can be safer than a poorly run local server.
A practical order of decision:
- List the data classes your app handles and the rules that apply to each.
- If a rule forbids third-party processing, restrict yourself to open-weight models you host.
- If hosted use is allowed, get the contract terms in writing and pick the matching region.
- Redact data you do not need to send, whichever option you pick.
Exercise
Your app summarizes support tickets that contain customer emails and phone numbers. A client contract forbids sending their data to third parties. Name two options that satisfy the contract.
Show answer
Self-host an open-weight model so the data stays inside your network. Alternatively, check whether the contract allows a provider under a signed data processing agreement and regional processing, and redact the identifiers before sending. The first option is safe under a strict reading. The second needs the client's approval.