# Transform rules

Transform rules change lines on the way in: drop noise, keep a percentage, take out personal data, parse a JSON or logfmt message into fields, rename a field, add a fixed one. They belong to a source. Open the source's **Settings**, then **Transform rules**.

Rules run in the order listed. **Drop** and **keep a percentage** rules look at the line as it arrived and run first, before the line is counted or stored, so a line they discard does **not** use your quota. The other rules (**redact**, **rename**, **parse**, **add**) run afterwards, each on what the one before left.

## Choosing lines

A rule's **lines matching** box uses the [query language](https://tailcove.dev/docs/query-language): words, `"phrases"`, `level:error`, `host:web*`, `path:/api*`, `status>=500`, with `AND`, `OR`, `NOT` and parentheses. One difference: there are **no regular expressions** in rules, so a `~"…"` term is refused when you save. Contains, prefix and equality cover what rules need, and they cannot be made to run for a long time by a crafted line.

A message is matched on its first 16 KiB, and a context larger than 256 KiB is not read by a query, so a rule never matches a line it could not read.

## Rule types

| Rule | What it does |
|---|---|
| Drop lines | Discards matching lines. A drop rule needs a query: an empty one would drop everything. |
| Keep a percentage | Of the matching lines, keeps 1 to 99 percent. The same lines are kept every time, so a client's retry of a batch keeps the same ones. |
| Redact | Replaces **email addresses**, **card numbers**, **bearer / Basic credentials**, **IP addresses**, **secret fields** or **API keys and tokens**, in the message, host and context, or in one named field, with `[email]`, `[card]`, `Bearer [token]`, `[ip]`, `[redacted]` or `[key]`. |
| Rename a field | Moves a context field, such as `user.mail` to `contact`. |
| Parse the message | Turns a JSON or logfmt message into context fields, optionally under one name. It can take the message and the level from keys of the parsed text. Fields the line already has win. |
| Add a field | Sets a fixed context field (or the host). It does not overwrite a value unless you tick that. |

**Secret fields** looks at names. In the context, any key named like a secret loses its whole value, nested objects included: `password`, `db_password`, `token`, `csrf_token`, `api_key`, `x-api-key`, `client_secret`, `private_key`, `aws_secret_access_key`, `authorization`, `cookie`, `set-cookie` and the like, in any case and with `-`, `_` or `.`. Names that only contain the word, such as `max_tokens`, `token_count` or `password_changed_at`, are left alone, and so are `true`, `false` and empty values. In the message and host it masks `password=…`, `?token=…`, `"api_key": "…"` and header lines such as `Authorization: …` or `Cookie: …`. A bare `password: too short` in a sentence stays as it is.

**API keys and tokens** looks at shapes: JWTs, AWS access key ids, Stripe secret and webhook keys, GitHub tokens, Slack tokens, Google API keys, and whole `-----BEGIN … PRIVATE KEY-----` blocks. Publishable keys (Stripe's `pk_…`) and public keys are left.

Card numbers are found by their digits and the Luhn check, so a number that only looks like a card (an id that passes the check) is redacted too. That is on purpose: missing a real card is worse.

## Recommended masking

Every new source starts with **recommended masking** on: secret fields, API keys and tokens, bearer / Basic credentials and card numbers are masked before your own rules run, so a line is cleaned before anything is stored, shown in live tail or exported. It doesn't count toward your plan's rule limit. Emails and IP addresses are left, because they're often what you search for; add a redact rule if you want them gone too.

Sources created before 29 November 2026 have it off until you turn it on: the transform rules page says so and has a button. You can switch it off on the same page. Only team owners and admins can change it, and the audit log records who did. It changes lines that arrive after you switch it, not the ones already stored.

## Safety

- **A rule that fails on a line is skipped for that line and counted. It never drops the line.** The one exception is redaction: if a line's context cannot be read (it is not an object, or it is nested more than 64 levels), the context is removed rather than stored unredacted.
- Redaction happens before the line is stored, shown in live tail, counted in an issue or exported. Nothing downstream sees what a rule took out.
- Lines already waiting when you save are cleaned with the rules that were current when they arrived.
- **Preview** shows what your rules would do to the source's last 50 lines before you save. It changes nothing. For a percentage rule the preview is an estimate of which lines are kept.

## Limits

The number of rules per source depends on your plan (see Billing), counted across all types. At most 10 of them can be drop or percentage rules, and a source's rules together are limited in size. Only team owners and admins can change rules; any member can look at them and preview.

If your team moves to a smaller plan, the rules it has keep working, and the next save must fit the new limit.
