---
title: "Keep personal data out of search logs · Agent Wranglers"
url: https://agentwranglers.se/playbook/search/access-and-limits/search-log-privacy
id: SRH-12
level: Required
risk: data
updated: 2026-10-27
build: a2a6bdfed830
tokens: 885
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Keep personal data out of search logs

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Access and limits](https://agentwranglers.se/playbook/search/access-and-limits.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: SRH-12
- Level: Required
- Chapter: [Access and limits](https://agentwranglers.se/playbook/search/access-and-limits.md)
- Rule: Log searches without user, account or session IDs, and drop queries that look like an email address, a phone number or an ID number. Delete raw search logs after a fixed time, such as 90 days.
- Check: Search for `anna@example.com` and `19840512-1234` on staging. The search log holds neither, and no log row has a user or session ID. A query finds no raw log row older than the stated period.
- Risk: Data leaked or lost
- How: People paste names, order numbers and addresses into search boxes, so a search log fills with personal data nobody planned for. The logs still serve their purpose without the person, since quality work needs only the query text, the hit count and the clicked position. Mask anything matching an email or a run of 8 or more digits before it is written. Keep counts per query longer, without IDs. Build the [fixed query set](https://agentwranglers.se/playbook/search/relevance/search-quality-tests.md) from these cleaned logs. The general rule is [keep personal data out of logs](https://agentwranglers.se/playbook/operations/logs/logs-without-personal-data.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JavaScript example

```js
const PERSONAL = /[^\s@]+@[^\s@]+|\d[\d -]{7,}\d/g;
export const cleanQuery = query => query.replace(PERSONAL, '[removed]').slice(0, 200);

export function logSearch(query, hitCount) {
  searchLog.write({ query: cleanQuery(query), hits: hitCount, at: new Date().toISOString() });
}
```

### Python example

```python
import re

PERSONAL = re.compile(r"[^\s@]+@[^\s@]+|\d[\d -]{7,}\d")

def clean_query(query: str) -> str:
    return PERSONAL.sub("[removed]", query)[:200]
```

## Sources

- [OWASP Logging Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html)
- [GDPR Recital 26 on identifiable persons](https://eur-lex.europa.eu/eli/reg/2016/679/oj)

## Related rules

- SRH-17 [Test search results with a fixed query set](https://agentwranglers.se/playbook/search/relevance/search-quality-tests.md) in Search
- OPS-9 [Keep personal data out of logs](https://agentwranglers.se/playbook/operations/logs/logs-without-personal-data.md) in Operations and observability
- SRH-19 [Watch searches that find nothing or get no click](https://agentwranglers.se/playbook/search/relevance/zero-result-searches.md) in Search

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/search/access-and-limits/search-log-privacy">Agent Wranglers search playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Cap the size of every search](https://agentwranglers.se/playbook/search/access-and-limits/search-limits.md)
- [Access and limits](https://agentwranglers.se/playbook/search/access-and-limits.md)
