> ## Documentation Index
> Fetch the complete documentation index at: https://docs.magpiedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Magpie is a trace store for AI agents, used as a library (crate `magpiedb`, npm `magpiedb`, PyPI `magpiedb`) or as `magpie-server`, which takes OpenTelemetry (OTLP over HTTP on 127.0.0.1:4318 and gRPC on 127.0.0.1:4317 by default).
> Use only the commands, flags, routes and JSON shapes that these pages show. Do not guess a flag or a query field: if a page does not show it, say that the docs do not show it.
> Packages and server binaries are not published yet: build from source, as the quick start shows. Check the status note on the introduction page before you suggest `cargo add`, `npm install` or `pip install`.
> Only one process may write to a store folder at a time. For many apps, send traces to one `magpie-server`.

# Masking private data

> Replace private data in every span and score before it is stored, with --mask.

With `--mask`, the server replaces private data in every span and score **before** it is stored. No file of the store holds the original text, and no search finds it. It is off by default.

```sh theme={null}
cat > mask.json <<'EOF'
{
  "rules": [
    {"builtin": "email"},
    {"builtin": "secret"},
    {"builtin": "credit_card", "replace": "<card>"},
    {"name": "order", "pattern": "ORD-[0-9]{8}"}
  ],
  "dropAttributes": ["customer.address"]
}
EOF
printf 'Card 4111 1111 1111 1111, mail bob@example.com, order ORD-12345678\n' | magpie-server mask-test --mask mask.json 2> /dev/null
```

```text theme={null}
Card <card>, mail [EMAIL], order [ORDER]
```

`mask-test` tries a policy on a text and stores nothing. Then start the server with it:

```sh theme={null}
magpie-server --dir ./masked --mask mask.json
```

```sh theme={null}
"$REPO/scripts/send-trace.sh" --url http://127.0.0.1:4318 --text "My mail is bob@example.com" > /dev/null
sleep 2
curl -s localhost:4318/v1/count -d '{"filter": {"text": {"phrase": "bob example com"}}}'; echo
curl -s localhost:4318/v1/count -d '{"filter": {"text": {"words": "EMAIL"}}}'; echo
curl -s localhost:4318/v1/mask
```

```text theme={null}
{"count":0}
{"count":2}
{"droppedAttributes":0,"enabled":true,"rules":[{"masked":2,"name":"email"},{"masked":0,"name":"secret"},{"masked":0,"name":"credit_card"},{"masked":0,"name":"order"}]}
```

`send-trace.sh` puts the text into two spans (the agent run and the model call): two matches of `email`, and the address is found by no search.

* Built-in rules: `email`, `credit_card` (with the Luhn check), `ipv4`, `phone` (only numbers that start with `+`), `secret` (key shapes such as `sk-...`, AWS key ids, GitHub and Slack tokens, JWTs, `Bearer ...`, PEM keys). Each is narrow on purpose. None finds names of people. A `pattern` is a regex of the Rust `regex` crate.
* A wrong policy stops the start, with the name of the rule. A write never fails because of the policy.
* `GET /v1/mask` gives counts only. It gives no value.
* What each rule does not find, and the other limits: [Server reference, "Masking"](https://docs.magpiedb.com/reference/server.md).

> [!WARNING]
>
> Masked: `input`, `output`, `error`, every text value in `attributes` and `events`, and the `label` and `comment` of a score. **Not masked:** ids (also `userId` and `sessionId`), `name`, `kind`, `model`, `service`, `environment`, `tags`, attribute keys, numbers. Do not put private data there.

> [!WARNING]
>
> A new policy changes new writes only. For old data, use the [deletes](https://docs.magpiedb.com/operations/data-lifecycle.md#deletes-for-privacy-and-purge).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.