# Hide private data before a call to a model, and put it back in the answer

> When your code sends a customer's ticket to a model, the provider receives the whole ticket. The model needs the problem. It does not need the name, the email

1.  [Home](/)
2.  [Blog](/blog)
3.  Hide private data before a call to a model, and put it back in the answer

How-to

# Hide private data before a call to a model, and put it back in the answer

[![](/img/greg-stoos-portrait.jpg)**Greg Stoos**Founder of Opami](/authors/greg-stoos)

-   3 Dec 2026
-   4 min read

![A developer compares two terminal windows on a monitor, with a notebook diagram beside the keyboard.](/img/blog/hide-private-data-before-a-call-to-a-model-and-put-it-back.jpg?v=4)

In this article

1.  [The four steps](#the-four-steps)
2.  [Set up](#set-up)
3.  [Send and hide](#send-and-hide)
4.  [Call the model on the badges](#call-the-model-on-the-badges)
5.  [Put the real details back](#put-the-real-details-back)
6.  [Run it](#run-it)
7.  [What is kept, and where](#what-is-kept-and-where)
8.  [Limits](#limits)
9.  [Try it on your own prompts](#try-it-on-your-own-prompts)

Share this article

-   [](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.opami.ai%2Fblog%2Fhide-private-data-before-a-call-to-a-model-and-put-it-back "LinkedIn")
-   [](https://x.com/intent/post?url=https%3A%2F%2Fwww.opami.ai%2Fblog%2Fhide-private-data-before-a-call-to-a-model-and-put-it-back&text=Hide%20private%20data%20before%20a%20call%20to%20a%20model%2C%20and%20put%20it%20back%20in%20the%20answer "X")
-   [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.opami.ai%2Fblog%2Fhide-private-data-before-a-call-to-a-model-and-put-it-back "Facebook")
-   [](https://bsky.app/intent/compose?text=Hide%20private%20data%20before%20a%20call%20to%20a%20model%2C%20and%20put%20it%20back%20in%20the%20answer%20https%3A%2F%2Fwww.opami.ai%2Fblog%2Fhide-private-data-before-a-call-to-a-model-and-put-it-back "Bluesky")
-   [](https://www.threads.net/intent/post?text=Hide%20private%20data%20before%20a%20call%20to%20a%20model%2C%20and%20put%20it%20back%20in%20the%20answer%20https%3A%2F%2Fwww.opami.ai%2Fblog%2Fhide-private-data-before-a-call-to-a-model-and-put-it-back "Threads")
-   [](https://wa.me/?text=Hide%20private%20data%20before%20a%20call%20to%20a%20model%2C%20and%20put%20it%20back%20in%20the%20answer%20https%3A%2F%2Fwww.opami.ai%2Fblog%2Fhide-private-data-before-a-call-to-a-model-and-put-it-back "WhatsApp")
-   [](mailto:?subject=Hide%20private%20data%20before%20a%20call%20to%20a%20model%2C%20and%20put%20it%20back%20in%20the%20answer&body=https%3A%2F%2Fwww.opami.ai%2Fblog%2Fhide-private-data-before-a-call-to-a-model-and-put-it-back "Email")
-   Link copied

In this article

1.  [The four steps](#the-four-steps)
2.  [Set up](#set-up)
3.  [Send and hide](#send-and-hide)
4.  [Call the model on the badges](#call-the-model-on-the-badges)
5.  [Put the real details back](#put-the-real-details-back)
6.  [Run it](#run-it)
7.  [What is kept, and where](#what-is-kept-and-where)
8.  [Limits](#limits)
9.  [Try it on your own prompts](#try-it-on-your-own-prompts)

When your code sends a customer's ticket to a model, the provider receives the whole ticket. The model needs the problem. It does not need the name, the email address or the account number. Below, Opami Protect finds those details and two short Python functions do the rest: one hides them before the call, one puts them back in the answer. Where Opami Protect finds a detail, the model reads a badge such as `[PERSON_A]` in its place; a detail it misses reaches the model as written, which is why the Limits section asks you to check a sample.

## The four steps

-   **Send.** Your code sends the text to Opami Protect. It returns each private or sensitive piece it found, with a type and a position.
-   **Hide.** Your code swaps each piece for a badge and keeps a table from badge to real value.
-   **Call.** The model works on the text with badges in it.
-   **Restore.** Your code puts the real details back in the answer.

Opami Protect does the finding. The swap, the call and the restore are yours, so you decide what the model sees and what your user sees.

## Set up

Register at console.opami.ai and create a key. There is no sales call. Opami Protect costs €2.00 per 1 million characters, up to 1 billion characters a month, and less above that.

bashCopy

```
pip install requests openai
export OPAMI_PROTECT_KEY="opk_..."
export OPENAI_API_KEY="sk-..."
export OPENAI_MODEL="..."   # the model you use today
```

We wrote the example against an OpenAI model and have not run it against other providers; with another provider, only `ask_model()` changes.

## Send and hide

pythonCopy

```
import os
from string import ascii_uppercase

import requests
from openai import OpenAI

URL = "https://api-protect.opami.ai/v1/detect"
HEADERS = {"Authorization": f"Bearer {os.environ['OPAMI_PROTECT_KEY']}"}

def hide(text):
    resp = requests.post(URL, headers=HEADERS, json={"model": "protect-v1", "text": text})
    resp.raise_for_status()
    found = sorted(resp.json()["detections"], key=lambda d: d["start"])

    badge_for = {}
    for d in found:
        if d["text"] not in badge_for:
            kind, _, _ = d["type"].partition(".")
            kind = kind.upper()
            n = sum(b.startswith(f"[{kind}_") for b in badge_for.values())
            badge_for[d["text"]] = f"[{kind}_{ascii_uppercase[n]}]"

    hidden = text
    for d in reversed(found):
        hidden = hidden[: d["start"]] + badge_for[d["text"]] + hidden[d["end"]:]

    return hidden, {badge: real for real, badge in badge_for.items()}
```

Each detection carries the `text` found, a `type` such as `person.name.full`, and its `start` and `end` in your text. Print `resp.json()` once on your first call and check those names before you build on them. The badge takes the first part of the type: a name becomes `[PERSON_A]`.

Why go backwards? Every swap changes the length of the text, so a forward pass would leave each later position pointing at the wrong characters after the first replacement. Start from the last piece and the earlier positions never move.

This sketch matches on exact text. "Ana Silva" twice is `[PERSON_A]` twice, while a shorter "Ana" gets a badge of its own, and you can merge the two in your table if your prompts need it. Letters stop at Z for one kind of data; if a text can hold more, switch to numbers and restore the longest badges first, or a short badge will eat the start of a longer one.

## Call the model on the badges

pythonCopy

```
client = OpenAI()

def ask_model(hidden):
    resp = client.responses.create(
        model=os.environ["OPENAI_MODEL"],
        instructions="You draft short, polite support replies. "
        "Copy placeholders such as [PERSON_A] exactly as written.",
        input=hidden,
    )
    return resp.output_text
```

Keep the instruction to copy badges. A model that writes "Person A" instead breaks the restore, because nothing in the table matches it.

## Put the real details back

pythonCopy

```
def restore(answer, real_for):
    for badge, real in real_for.items():
        answer = answer.replace(badge, real)
    return answer
```

## Run it

pythonCopy

```
ticket = (
    "Hi, this is Ana Silva from Lusomar. My invoice went to the wrong address. "
    "Please write back to ana.silva@lusomar.pt. Thanks, Ana Silva"
)

hidden, real_for = hide(ticket)
print(hidden)
print(restore(ask_model(hidden), real_for))
```

The first print is what your provider receives: the ticket with the details Opami Protect found swapped for badges. We show no sample output here. The badges you get follow the types Opami Protect returns for your text, so the output of your own first run is the one to read. The second print is the reply your user sees, with the real name and address back in place.

## What is kept, and where

The table `real_for` lives in your process for one request. Opami Protect keeps no text and no log of requests. If you need a record of what was hidden, keep it on your side.

## Limits

Opami Protect does not catch everything, so read the hidden text for a sample of your own requests before you ship.

It hides who and what is private, not the facts around it. A wrong address on an invoice is still a wrong address when the model reads it.

The restore works on a complete answer. We have nothing to state yet about streamed answers, where a badge can arrive split across chunks.

## Try it on your own prompts

With a key from console.opami.ai, run `hide()` on a few of your real prompts and print what your model would receive, before you touch production code. If a name gets through, tell us: a miss on a real prompt is the bug report we want.

Share this article

-   [](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.opami.ai%2Fblog%2Fhide-private-data-before-a-call-to-a-model-and-put-it-back "LinkedIn")
-   [](https://x.com/intent/post?url=https%3A%2F%2Fwww.opami.ai%2Fblog%2Fhide-private-data-before-a-call-to-a-model-and-put-it-back&text=Hide%20private%20data%20before%20a%20call%20to%20a%20model%2C%20and%20put%20it%20back%20in%20the%20answer "X")
-   [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.opami.ai%2Fblog%2Fhide-private-data-before-a-call-to-a-model-and-put-it-back "Facebook")
-   [](https://bsky.app/intent/compose?text=Hide%20private%20data%20before%20a%20call%20to%20a%20model%2C%20and%20put%20it%20back%20in%20the%20answer%20https%3A%2F%2Fwww.opami.ai%2Fblog%2Fhide-private-data-before-a-call-to-a-model-and-put-it-back "Bluesky")
-   [](https://www.threads.net/intent/post?text=Hide%20private%20data%20before%20a%20call%20to%20a%20model%2C%20and%20put%20it%20back%20in%20the%20answer%20https%3A%2F%2Fwww.opami.ai%2Fblog%2Fhide-private-data-before-a-call-to-a-model-and-put-it-back "Threads")
-   [](https://wa.me/?text=Hide%20private%20data%20before%20a%20call%20to%20a%20model%2C%20and%20put%20it%20back%20in%20the%20answer%20https%3A%2F%2Fwww.opami.ai%2Fblog%2Fhide-private-data-before-a-call-to-a-model-and-put-it-back "WhatsApp")
-   [](mailto:?subject=Hide%20private%20data%20before%20a%20call%20to%20a%20model%2C%20and%20put%20it%20back%20in%20the%20answer&body=https%3A%2F%2Fwww.opami.ai%2Fblog%2Fhide-private-data-before-a-call-to-a-model-and-put-it-back "Email")
-   Link copied

![Greg Stoos](/img/greg-stoos-portrait.jpg)

Written by

[Greg Stoos](/authors/greg-stoos), founder of Opami

Greg Stoos founded Opami in Lisbon and builds Opami Protect, an API that finds and hides private and sensitive data in a text before an AI model reads it.

[His articles →](/authors/greg-stoos)

## Try it on your own data

Opami Protect is open to anyone. Register at the console, run a sample of your own text, and see what it hides. No sales call.

[→ Protect console](https://console.opami.ai)[Read the quickstart](https://console.opami.ai/docs)

## Keep reading

[All articles →](/blog)

-    [![](/img/blog/open.jpg?v=4) Launch**Opami Protect is open: what other tools let through**6 min read_Read →_](/blog/opami-protect-is-open)
-    [![](/img/blog/flow.jpg?v=4) How-to**How to remove private and sensitive data from a prompt before it reaches OpenAI or Claude**4 min read_Read →_](/blog/remove-private-data-before-openai-or-claude)

## Get the answers in your inbox

Each week, the three articles, one thing we learned and one number, in one email.

Email

What do you want to hear? Tick any The weekly letter: three articles, one thing we learned, one number The day Opami Chat opens The day Opami Bot opens The day Opami Brain opens

I agree to receive these emails. I can stop them with one click in each email.

Sign up
