Mimir.Redact (Mimir v0.1.0)

Copy Markdown View Source

Helpers for masking secrets and gating payload capture.

Provides utilities to safely mask sensitive information in data structures and to conditionally enable/disable payload capture to prevent secret leaks.

Summary

Functions

Gate payload capture. Returns {request_payload, response_payload}.

Splits a "provider:model_id" model string into {provider, model_id}. If there is no : separator, returns {nil, model}.

Truncates a binary to at most max bytes, UTF-8-safely: if the byte cut lands mid-character, the trailing incomplete sequence is dropped so the result is always valid UTF-8 (and still ≤ max bytes). Non-binaries pass through.

Functions

payloads(request, response, bool)

@spec payloads(map() | nil, map() | nil, boolean()) :: {map() | nil, map() | nil}

Gate payload capture. Returns {request_payload, response_payload}.

When enabled? is false (the default), returns {nil, nil} — message content is never persisted, so no secrets can leak through the payload columns. When true, returns the payloads as maps (the gated path); scalar metadata is always safe and is captured regardless.

split_provider(model)

@spec split_provider(String.t()) :: {String.t() | nil, String.t() | nil}

Splits a "provider:model_id" model string into {provider, model_id}. If there is no : separator, returns {nil, model}.

iex> Mimir.Redact.split_provider("bedrock:nvidia.nemotron-super-3-120b")
{"bedrock", "nvidia.nemotron-super-3-120b"}

iex> Mimir.Redact.split_provider("claude-3")
{nil, "claude-3"}

truncate(bin, max)

@spec truncate(binary(), non_neg_integer()) :: binary()

Truncates a binary to at most max bytes, UTF-8-safely: if the byte cut lands mid-character, the trailing incomplete sequence is dropped so the result is always valid UTF-8 (and still ≤ max bytes). Non-binaries pass through.