Capture & Privacy

Input and output capture is disabled by default. Enable it globally with configure() or for a single observed function:

from bir import configure, observe

configure(capture_inputs=True, capture_outputs=True)

@observe(capture_inputs=True, capture_outputs=True)
def answer(question: str) -> str:
    return question

Capture stays disabled unless an environment variable, a configure() call, or a per-observation/per-event argument explicitly enables it.

To stop recording entirely — no traces, spans, generations, tool calls, retrievals, or scores written at all — use the master switch configure(enabled=False) or set BIR_DISABLED=1. Your code still runs and still raises; Bir simply becomes a no-op. See Disabling tracing for how it relates to sampling.

Redaction

Which fields are scanned

Redaction is pointed at what your application passed as content, not at what identifies the record. Everything below was measured by sweeping one sk-live-… credential through every public surface that accepts a string and writes it to the store:

scanned recorded as given
metadata — keys and values, on every event type the event name — trace, span, generation, tool_call, retrieval, score
captured input and output, including @observe() arguments and return values model on a generation
a retrieval's query and each add_document(text=...) service_name, environment, and source from configure()
a prompt's template, variables, and rendered text
the message of an exception a traced call raised

The split is deliberate rather than incidental. A name and a model are how you find a record and read it back: bir traces --name, the tree bir show prints, and the model_prices table that fills in a generation's cost all key on them. Replacing one with [redacted] would not un-leak the value — it would destroy the record it belongs to while the credential stayed wherever it actually came from.

Two of those fields are worth knowing about specifically, because the SDK fills them in from a third party rather than from your code. A generation's model is whatever the provider echoed back, and an event name from a framework bridge is whatever the framework announced — a LangChain tool name is the tool the model chose. Neither is scanned. A credential arriving in either one means it was already sent to that third party, so the place to fix it is the call, not the trace. service_name, environment, and source are constants you set; they are recorded exactly as given.

If you need an identity field scanned in your setup, put the value in metadata as well and read it from there — metadata is scanned, keys and values alike.

What is recognized

Before captured events are written, Bir redacts common secret-like fields such as api_key, authorization, password, secret, and token.

Captured strings, fallback object representations, captured error messages, and mapping keys are also scanned for common secret-like text patterns, including:

  • Labeled secrets (api_key=…, password: …, and the other names above).
  • Authorization headers, in either the Authorization: … or authorization=… spelling. The authentication scheme is kept and the credential after it is replaced, so Authorization: Basic dXNlcjpwYXNz records as Authorization: Basic [redacted] — the trace still tells you which authentication the call used. Bearer, Basic, Token, ApiKey, NTLM, Negotiate, and SSWS carry a single credential; Digest, Hawk, Signature, and AWS4-HMAC-SHA256 carry a comma-separated parameter list, and the whole list is replaced because the secret part of it comes last. A header with no scheme at all has its value replaced.
  • sk-... tokens and JWTs.
  • AWS access key IDs (AKIA... and ASIA...).
  • Google API keys (AIza...).
  • Slack xox* tokens.
  • GitHub tokens: the classic ghp_, gho_, ghs_, ghu_, and ghr_ prefixes and the fine-grained github_pat_ form.
  • Cookie and Set-Cookie headers. Every cookie's value is replaced and the cookie names are kept, so Cookie: session=abc123; auth_token=xyz789 records as Cookie: session=[redacted]; auth_token=[redacted] and the trace still says which cookies a request carried. Cookie attributes are kept because they describe the cookie rather than authenticate anything, so Set-Cookie: sid=9f8e7d; Path=/; HttpOnly records as Set-Cookie: sid=[redacted]; Path=/; HttpOnly. The attributes recognized by name are Domain, Expires, Max-Age, Partitioned, Path, Priority, SameSite, Secure, Version, and HttpOnly; a bare flag with no value is kept whatever it is called.
  • Passwords inside a connection string. In a URI carrying user:password@, the password is replaced and the scheme, user, and host are kept, so postgres://admin:hunter2@db.internal:5432/prod records as postgres://admin:[redacted]@db.internal:5432/prod and the trace still says which database the call was reaching. A URL with no password (https://user@example.com) and an ordinary host:port are left alone. A token placed in the user half instead — the <token>:x-oauth-basic@ convention — is covered by the token rules above rather than by this one.
  • Stripe secret and restricted keys (sk_live_, sk_test_, rk_live_, rk_test_).
  • Azure storage-style account keys (88-character base64 ending in ==).
  • PEM private-key blocks (-----BEGIN ... PRIVATE KEY----- ... -----END ... PRIVATE KEY-----). A block is a header and the nearest footer after it; a header with no footer is left alone, since nothing has been shown to be a key.
  • Credit-card / PAN numbers: 13-19 digit runs (optionally split into groups by single spaces or hyphens) that pass the Luhn checksum. The checksum gate keeps ordinary long integers, ids, and phone numbers from being redacted.

Warning

Redaction is best-effort, not a guarantee that every credential or sensitive value will be recognized. Keep capture opt-in for sensitive payloads and review what your application records.

File permissions

Bir creates the files it writes for itself readable only by the user who ran the process (0600): the trace store and its size-rotated siblings, the .sent upload sidecar, and experiment result and summary files. They hold captured inputs and outputs, and redaction is best-effort, so on a shared CI runner or a multi-user host the umask default of world-readable was the wrong one.

Three deliberate limits on that:

  • The .bir directory keeps the umask's mode. A sibling process can still list the store; it just cannot read the files.
  • Existing files are never changed. The mode is applied as a file is created, so a file whose permissions you widened stays as you left it.
  • What you ask Bir to export is yours. dataset.to_jsonl(...) and bir experiment-report --output ... write to a path you named and keep the umask's mode, because those are deliberate handoffs rather than Bir's own store.

A umask can narrow this further and can never widen it. If you need the store readable by another user — a collector running under a different uid — widen the file once after it is created, or relax the umask of the process that creates it.

Secrets used as mapping keys

A mapping held by credential — a per-token rate-limit map, a token-to-session cache — has its keys redacted too, so {"sk-live-…": {"remaining": 3}} records as {"[redacted]": {"remaining": 3}}.

The key name is still what decides the value's fate, so {"api_key": "…"} keeps its readable key and replaces its value as before. When several keys redact to the same marker the entries are kept apart with a counted suffix — [redacted], [redacted] (2) — rather than overwriting one another, so a mapping never loses entries without saying so.

Adding custom rules

Organizations often have domain-specific credential names or text formats Bir cannot know in advance. configure() accepts two additive options for them:

import re
from bir import configure

configure(
    additional_secret_keys=["ssn", "badge-id"],
    additional_redaction_patterns=[r"CUST-\d+", re.compile(r"acct-\w+", re.IGNORECASE)],
)
  • additional_secret_keys redacts extra mapping keys by whole-name, case-insensitive match (- and _ are treated as equivalent), so "ssn" redacts a SSN field but not an unrelated session_id.
  • additional_redaction_patterns accepts regex strings and/or compiled re.Pattern objects, replacing every match with [redacted] in captured strings, repr fallbacks, error text, prompt and score metadata, integration inputs/outputs, and dataset/experiment files.

These options are purely additive: the built-in rules and the [redacted] marker always apply and can never be disabled, replaced, or reordered. Entries are validated and compiled once during configure(), so an empty key, empty pattern, invalid regex, non-string entry, bytes pattern, or an over-large list raises immediately. Passing either argument replaces the previously configured additional rules of that kind (an empty iterable clears them); omitting it leaves them unchanged.

Captured values are normalized to JSON-compatible data. Non-finite floats such as NaN and Infinity are stored as strings, and deeply nested values are truncated.

When a value cannot be captured

Capturing a value runs code Bir does not own: a mapping's items(), a sequence's __iter__, an object's __repr__, an exception's __str__. Those can fail — a config client whose backend is down, a result set whose next page is gone — and recording a value is never allowed to decide whether your call succeeds. So a capture that fails is recorded, not raised:

  • A value Bir could not read at all is recorded as [uncapturable].
  • A mapping or list whose walk fails part-way keeps the entries it read and adds one [uncapturable] entry for the rest, the same shape max_collection_items produces below.
  • An object whose __repr__ fails is recorded as <unrepresentable TypeName>, and so is an exception whose __str__ fails.

Your function still runs, still returns its own result, and the event still records its own status. The marker is a recorded value, so [uncapturable] is distinguishable from a field that was simply never captured (null).

Passing something that is not a mapping where a mapping belongs — for example trace(name, metadata=[1, 2]) — is a mistake in the call rather than a value misbehaving, and still raises TypeError immediately.

Limiting capture size

Capture is normally written whole, so a single large value — a base64 image, a megabyte of model output — can bloat .bir/traces.jsonl. Two opt-in configure() limits bound an individual captured value:

from bir import configure

configure(max_value_length=10_000, max_collection_items=100)
  • max_value_length truncates a captured string longer than it to that many characters and appends a visible …[truncated] marker.
  • max_collection_items keeps only the first that-many items of a captured list, tuple, set, or mapping and records a single …[truncated] marker for the rest, leaving the output valid JSON.

Both default to None (unlimited), so captured output is byte-for-byte unchanged unless you opt in. They apply to every capture path (inputs, outputs, metadata, repr fallbacks, and dataset/experiment capture) and compose with the nested-depth cap above. Truncation always runs after redaction, so a secret is replaced before any cut and these limits can never weaken redaction. A non-integer, boolean, or negative limit raises immediately at configure() time.

These limits bound a single captured value; to cap the whole trace file instead, see configure(max_bytes=...) size-based rotation.

Environment capture settings

export BIR_CAPTURE_INPUTS=true
export BIR_CAPTURE_OUTPUTS=true
export BIR_TRACE_PATH=/var/log/bir/traces.jsonl
export BIR_MAX_VALUE_LENGTH=10000
export BIR_MAX_COLLECTION_ITEMS=100

Boolean settings accept 1, true, yes, or on and 0, false, no, or off, case-insensitively. BIR_MAX_VALUE_LENGTH and BIR_MAX_COLLECTION_ITEMS take a non-negative integer and default to unlimited. Variables are read once at import time and explicit configure() arguments take precedence.

Prompt and dataset payloads

Prompt template text, variables, and rendered values require their own explicit capture flags. Dataset export redacts by default; use dataset.to_jsonl(..., redact=False) only when raw export is intentional.

Score metadata is always passed through the same redaction rules before it is written.