Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Normalization rules

Requests often contain values that change on every run: timestamps in system prompts, UUIDs an agent generates, temporary paths, tool lists built from sets. Normalization rules make such requests match their recording. Takes stay raw; rules run at replay time on both the recorded and the incoming request, so changing a rule affects every existing take immediately.

A rule is a regex replacement applied to string values. Each match becomes a numbered placeholder: the first distinct value becomes <KIND_1>, the next <KIND_2>, and a repeated value reuses its number. Numbering is computed separately for each request, so two runs that generate different IDs still match, but a request that reuses one ID where the recording used two different ones does not.

Selectors

A rule applies to the parts of the request its select names. Selectors are provider-neutral; for the Anthropic Messages API they map as follows:

SelectorAnthropic Messages API
systemthe system field
user_messagesuser message content, except tool_result blocks
assistant_messagesassistant message content, except tool_use blocks
tool_resultsthe content of tool_result blocks
tool_call_argsthe input of tool_use blocks
tool_definitionsthe tools array
allthe whole body

A selector that starts with / is a raw-body path, for fields the selectors do not cover: a JSON Pointer where a * segment matches any key or index, e.g. /metadata/user_id or /messages/*/content. Raw paths are provider-specific. A rule applies to everything inside what it selects. except takes selectors in the same form and removes them from the selection.

Built-ins

Built-inDefaultMatchesPlaceholder
uuidon, everywhere123e4567-e89b-12d3-a456-426614174000<UUID_1>
iso-timestampon, except in user_messages2026-12-05T10:11:12Z, 2026-12-05 10:11, with optional seconds, fraction and offset<TIMESTAMP_1>
temp-pathon, everywhere/tmp/…, /var/folders/…, /private/var/folders/…, C:\Users\…\AppData\Local\Temp\…, C:\Windows\Temp\…<TEMP_PATH_1>
iso-dateoff2026-12-05<DATE_1>
unix-timestampoffany 10-digit number<UNIX_TIME_1>

Structural normalization, also on by default:

  • crlf: CRLF becomes LF in every string. Other whitespace is compared exactly.
  • embedded-json: a string in tool_results that parses as a JSON object or array is compared as parsed JSON (key order and whitespace ignored). Rules then apply to the strings and numbers inside it.
  • unordered-tool-definitions: the tools array is compared in any order.

Redaction (see Placeholders) runs as one more built-in rule. It is configured in [redact], not here, and is not counted or named in what replay reports.

[match] in retake.toml

[match]
unordered = ["/metadata/tags"]       # raw paths of arrays compared in any order

[match.builtins]
iso-date  = true                     # turn an off-by-default built-in on
temp-path = false                    # or one off (crlf, embedded-json and
                                     # unordered-tool-definitions too)
uuid = { select = ["tool_results", "tool_call_args"] }   # or re-scope it
# a table also takes `except`, `tests`, and `enabled = false`

[[match.rules]]
name    = "prompt-date"
select  = "system"                   # a selector, `all`, a raw path, or a list of them
pattern = '\d{4}-\d{2}-\d{2}'
replace = "DATE"                     # becomes <DATE_1>, <DATE_2>, ...
tests   = ["tests/agent/test_booking.py::*"]   # optional

[[match.rules]]
name      = "price-noise"
select    = "tool_results"
tolerance = 0.01                     # JSON numbers within 0.01 compare equal

[[match.rules]]
name   = "screenshots"
select = "user_messages"
media  = "image/*"                   # binary parts of this media range...
match  = "any"                       # ...match any content of the range
tests  = ["tests/test_screenshot_*"] # optional, as for any rule
  • name: a-z, 0-9 and -; it may not be a built-in’s name. replace: letters, digits, _ and -.
  • pattern uses the syntax of the Rust regex crate: matching is guaranteed linear-time; look-around and backreferences are not supported. Patterns are checked when the file loads. A rule that should ignore a value entirely replaces the whole value, e.g. pattern = '(?s).+'.
  • tolerance is an absolute difference, applies to JSON numbers only (including numbers in tool results parsed as JSON), and is never on by default.
  • media and match = "any" relax binary matching: in the selected locations, binary parts (withheld or in a blob) whose media type is in the media range (image/png, image/*) match any content of that range, e.g. screenshots or re-encoded uploads whose bytes change on every run. There is no perceptual (“visually similar”) matching. Such a rule can hide a real change in an image, so limit it with select and tests. Media rules are covered by the guard and counted in the summary like any rule.
  • A rule has exactly one of: pattern and replace, tolerance, or media and match.
  • tests limits a rule to takes whose test ID matches one of the globs (* matches any characters, ? one). Without it, a rule applies to every take; with it, it never applies to _main.take or _session.take.
  • Unknown keys are an error.

How rules combine

Every request goes through the same steps, on both sides:

  1. Structural: CRLF to LF; JSON in tool results parsed.
  2. Replace: each string is scanned once. At each position the match that starts earliest is used; among matches that start at the same position the longest wins; equal lengths go to user rules over built-ins, then to the rule earlier in the file. Rules never see each other’s output, so iso-timestamp takes a whole timestamp even when a date rule is also active.
  3. Sort: unordered arrays are sorted, comparing placeholders by kind only.
  4. Number: placeholders are numbered walking the body with object keys sorted.
  5. Compare: equality, with numeric tolerance where a rule sets one.

The guard

When a take is loaded, Retake normalizes every recorded request. If a rule makes two recorded requests with different bodies and different responses compare equal, replay could serve the wrong one, so it refuses: the run fails before the command starts (exit 2), or with a plugin, the test fails. The message names the rules and both exchanges:

retake: cannot load tests/takes/_main.take: normalization rule(s) any-order make recorded exchanges #0 and #1 indistinguishable: their requests differ but normalize to the same value, and their responses differ, so replay could serve the wrong one. Narrow the rule in retake.toml (e.g. with `select` or `tests`). The requests differ in:
  body system: #0 "Handle order 7", #1 "Handle order 8"

Redaction never triggers the guard: two recorded requests that differ only in which secret they carry are treated as identical requests, served in recorded order.

What replay reports

The run summary counts matches that were exact and matches that needed rules, per rule. A rule is counted for a match when the match fails without it. Rules that never made a difference are not listed. Redaction is not counted: recorded placeholders are numbered per take and incoming ones per request, so they often differ, and a match whose only difference is in redacted values counts as exact.

retake: replayed 7 exchange(s) from tests/takes/_main.take
retake: matches: 3 exact, 4 with rules (crlf 1, embedded-json 1, iso-timestamp 1, unordered-tool-definitions 1, uuid 1)

retake replay --verbose (RETAKE_VERBOSE=1) prints each difference rules hid, as the request is matched, in stored form with placeholders renumbered per request (secrets appear as placeholders, and placeholder numbers that differ only by numbering are not listed):

retake: POST /v1/messages: matched recorded exchange #0 with rule(s) iso-timestamp; differences hidden:
  body system: recorded "Now: 2026-12-01T09:00:00Z", request "Now: 2026-12-05T17:45:12Z"

Mismatch descriptions show normalized values only:

retake: no recorded response for POST /v1/messages (retake_no_match):
closest recorded exchange is #0 (first 2 of 3 message(s) identical); it differs in:
  body messages[2].content[0].content.⟨json⟩.parent: recorded "<UUID_2>", request "<UUID_1>"

⟨json⟩ in a path marks JSON parsed out of a tool result string.