> ## Documentation Index
> Fetch the complete documentation index at: https://traceroot.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> To set up traceroot in a repository, follow the setup prompt in https://traceroot.ai/docs/getting-started/coding-agents.md.

# Data Capture and Privacy

> Understand and control what traceroot records and exports

traceroot spans can contain application data. Review the defaults before tracing workloads that process personal data, credentials, or confidential content.

## What is captured by default

| Data | Default | How to limit it |
| - | - | - |
| Observed function arguments | Captured as span input | Set `capture_input=False` in Python or `captureInput: false` in TypeScript |
| Observed function return values | Captured as span output | Set `capture_output=False` in Python or `captureOutput: false` in TypeScript |
| Auto-instrumented LLM prompts and completions | Captured when the integration exposes content | Rewrite or blank values with [`redact`](#redact-personal-data-before-export); the TypeScript Pi integrations also expose a content filter (`captureContent`) |
| Tool arguments and results | Captured when the integration exposes tool I/O | Rewrite or blank values with [`redact`](#redact-personal-data-before-export); the TypeScript Pi integrations also expose a tool I/O capture option (`captureToolIo: false`) |
| Git repository and ref | Trace-level metadata when resolved | Automatically resolved even when not explicitly provided; there is no git-context opt-out. Disable tracing entirely to prevent export; see [Git Context](https://traceroot.ai/docs/tracing/git-context.md) |
| Source file, line, and function | Added by `observe` / `@observe` | Disable tracing entirely if source location must not leave the process |

Capture settings prevent the selected values from being written to spans. They do not modify what your application passes to an LLM provider or tool.

## Disable input and output for one function

> [tab] Python
>
> ```python theme={null}
> from traceroot import observe
>
> @observe(capture_input=False, capture_output=False)
> def verify_password(username: str, password: str) -> bool:
>     return check_credentials(username, password)
> ```

> [tab] TypeScript
>
> Pass the function's arguments after it so `observe` can invoke it; `captureInput: false` keeps those arguments off the span:
>
> ```typescript theme={null}
> import { observe } from '@traceroot-ai/traceroot';
>
> const authenticated = await observe(
>   { name: 'verify_password', captureInput: false, captureOutput: false },
>   verifyPassword,
>   username,
>   password,
> );
> ```

These flags apply only to the span created by that `observe` call. Auto-instrumented child calls can still capture their own inputs and outputs according to the integration's settings.

## Redact personal data before export

Requires `traceroot` 0.4.0 or later (Python) or `@traceroot-ai/traceroot` 0.6.0 or later (TypeScript, or 0.8.0 for an async `redact`).

Pass a `redact` function to `initialize()`. It receives each finished span's attributes and returns what to export, so anything it removes never reaches traceroot. This example blanks email addresses and phone numbers:

> [tab] Python
>
> ```python theme={null}
> import re
> import traceroot
>
> PII = re.compile(r"[\w.+-]+@[\w-]+\.[\w.]+|(?<![\w-])(?:\+\d{1,3}[\s.-]?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}(?![\w-])")
>
> def clean(value):
>     if isinstance(value, str):
>         return PII.sub("[REDACTED]", value)
>     if isinstance(value, (list, tuple)):
>         return [PII.sub("[REDACTED]", v) if isinstance(v, str) else v for v in value]
>     return value
>
> def redact(attributes: dict) -> dict:
>     return {key: clean(value) for key, value in attributes.items()}
>
> traceroot.initialize(redact=redact)
> ```

> [tab] TypeScript
>
> ```typescript theme={null}
> import { TraceRoot } from '@traceroot-ai/traceroot';
>
> const PII = /[\w.+-]+@[\w-]+\.[\w.]+|(?<![\w-])(?:\+\d{1,3}[\s.-]?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}(?![\w-])/g;
>
> const clean = (value: string) => value.replace(PII, '[REDACTED]');
>
> TraceRoot.initialize({
>   redact: (attributes) =>
>     Object.fromEntries(
>       Object.entries(attributes).map(([key, value]) => [
>         key,
>         typeof value === 'string'
>           ? clean(value)
>           : Array.isArray(value) && value.every((v): v is string => typeof v === 'string')
>             ? value.map(clean)
>             : value,
>       ]),
>     ),
> });
> ```

How it works:

* It runs in your app on every finished span, including spans from other libraries. In Python, keep it fast, synchronous, and thread-safe. In TypeScript, it runs at export, not during the request, and may be async; each batch gets 5 seconds.
* It receives span content: `observe` input, output, and metadata, LLM prompts, event attributes such as exception messages, and the status message. Structured values arrive as JSON text, so parse them if your detector misses names in JSON.
* It does not receive bookkeeping: user and session IDs, model name and token usage, tags, environment, span names, and similar. Those are sent as given, so keep personal data out of them and use an internal user ID, not an email address.
* Return every key you want to keep.
* Only traceroot's copy changes. Other exporters in your app still get the original span.

> [!WARNING]
>
> If the function raises or returns anything other than a dict (Python) or object (TypeScript), metadata is dropped and every value except numbers and booleans is sent as `[redaction failed]`. A TypeScript promise that rejects or does not settle within 5 seconds fails the same way. The SDK logs a warning. In TypeScript, pass `logLevel: 'warn'` to `initialize()` to see it.

Eval results are redacted too. Datasets and scorer definitions are not, so keep personal data out of them.

A regex will not catch names or addresses. For those, call a detection service you run, for example a small one in front of [Presidio](https://microsoft.github.io/presidio/). This example sends each string to a service that takes and returns `{ text }`:

```typescript theme={null}
import { TraceRoot } from '@traceroot-ai/traceroot';

TraceRoot.initialize({
  redact: async (attributes) => {
    const detect = async (text: string): Promise<string> => {
      const response = await fetch(process.env.PII_SERVICE_URL!, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ text }),
        signal: AbortSignal.timeout(4000),
      });
      if (!response.ok) throw new Error(`PII service returned ${response.status}`);
      return ((await response.json()) as { text: string }).text;
    };
    const entries = Object.entries(attributes).map(async ([key, value]) => [
      key,
      typeof value === 'string'
        ? await detect(value)
        : Array.isArray(value) && value.every((v): v is string => typeof v === 'string')
          ? await Promise.all(value.map(detect))
          : value,
    ]);
    return Object.fromEntries(await Promise.all(entries));
  },
});
```

> [!NOTE]
>
> From 0.8.0, TypeScript `redact` also receives keys derived from Vercel AI SDK attributes (`input.value`, `output.value`, `llm.*`), so if you drop specific `ai.*` keys, drop these too.

The trace view marks every span the function ran on as **Redacted by your app**.

![Span details for update\_shipping\_contact with a Redacted by your app label, and an input message whose email address and phone number show as \[REDACTED\]](https://mintcdn.com/tracerootai/kqejnfY8AIiTJVnt/images/span_redacted_v1.png?fit=max\&auto=format\&n=kqejnfY8AIiTJVnt\&q=85\&s=5e5d33471e6a4855d9a2d4bf1cef845f)

Span details: the Redacted by your app label and the redacted input

## Redact Pi content before export

The TypeScript Pi instrumentation accepts a `captureContent` callback. It runs before content is attached to a span and can return replacement text or `undefined` to omit that item.

```typescript theme={null}
import * as pi from '@earendil-works/pi-coding-agent';
import { TraceRoot, type ContentCaptureFn } from '@traceroot-ai/traceroot';

const EMAIL = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/gi;

const redactContent: ContentCaptureFn = (kind, value) => {
  if (kind === 'agent_input') {
    return value.text?.replace(EMAIL, '[redacted-email]');
  }

  // Do not record model inputs or response bodies.
  return undefined;
};

TraceRoot.initialize({
  instrumentModules: {
    piCodingAgent: {
      module: pi,
      config: {
        captureContent: redactContent,
        captureToolIo: false,
      },
    },
  },
});
```

The callback form is available in the TypeScript Pi instrumentation. For other integrations and for Python, use [`redact`](#redact-personal-data-before-export) above.

## Disable tracing entirely

Set `TRACEROOT_ENABLED` before the SDK initializes:

```bash theme={null}
TRACEROOT_ENABLED=false
```

The accepted values differ by SDK:

| SDK | Values treated as off |
| - | - |
| Python | `false`, `0`, `no`, or `off`, case-insensitive |
| TypeScript | The exact lowercase string `false` |

You can also pass `enabled=False` to Python's `initialize()` or `enabled: false` to `TraceRoot.initialize()` in TypeScript.

## Privacy checklist

* Classify prompts, completions, function arguments, tool I/O, metadata, tags, and source paths before enabling tracing in production.
* Disable capture as close as possible to the function or integration that handles sensitive data.
* Use `redact` to strip personal data that has to stay in captured content.
* Never attach secrets to metadata or manual span updates.
* Verify a representative exported trace in a non-production project before rollout.
* Apply your organization's retention, access-control, and data-processing requirements to the traceroot deployment you use.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.