Stephen Chu a99f8cb5de Fix dotted_order and trace_id when regenerating run IDs
The dotted_order field embeds run IDs in the format:
  TIMESTAMP+UUID.TIMESTAMP+UUID...

When regenerating run IDs, we must also:
- Replace all old IDs in dotted_order with their new mapped IDs
- Update trace_id to use the new root run ID

This fixes HTTP 400 validation errors about dotted_order mismatches.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-23 21:40:55 -05:00

LangSmith Trace Export & PII Scrubbing

Simple bash scripts to extract, scrub, and upload LangSmith traces.

Quick Start

Extract and Scrub PII

Extract a trace and scrub sensitive data before sharing:

# 1. Extract trace
export LANGSMITH_API_KEY='your-api-key'
./extract_trace.sh 00000000-0000-0000-f319-b36446ca3f23

# 2. Scrub PII (recursively redacts field names)
./scrub_trace.sh trace_00000000-0000-0000-f319-b36446ca3f23.json "content,email"

# 3. Review scrubbed file manually

# 4. Share trace_00000000-0000-0000-f319-b36446ca3f23.scrubbed.json

Upload

Upload a scrubbed trace to a tracing project:

export LANGSMITH_API_KEY='your-api-key'
./upload_trace.sh trace.scrubbed.json "debug-trace-123"

The script will create a new tracing project with the specified name. You can delete the project later if needed.

Note: The trace will be uploaded to the workspace associated with your API key. Make sure you're using the correct API key for the intended workspace.

Requirements

  • bash
  • curl
  • jq (install: brew install jq or apt-get install jq)

Scripts

extract_trace.sh

Extract a trace by ID.

./extract_trace.sh <trace_id> [output_file]

Output: trace_<id>.json

scrub_trace.sh

Redact PII fields from trace using recursive field name matching.

./scrub_trace.sh <trace_file> "<field1>,<field2>,..."

Output: <trace_file>.scrubbed.json

Common fields to redact:

  • content - Message content (finds all content fields)
  • email - Email addresses
  • messages - Entire message arrays
  • query - Search queries
  • text - Generated text
  • session_id - Session IDs
  • user_id - User IDs
  • api_key - API keys

Recursive matching: Field names are matched at any depth in the JSON structure, including inside arrays and nested objects. For example, specifying content will redact all fields named content anywhere in the trace.

upload_trace.sh

Upload scrubbed trace to a LangSmith tracing project.

./upload_trace.sh <trace_file> <project_name>

Creates a new tracing project with the specified name and uploads all runs to it. Run IDs are automatically regenerated to avoid conflicts while preserving parent-child relationships.

Complete Example

Extract and Scrub PII:

export LANGSMITH_API_KEY='lsv2_pt_...'

# Extract
./extract_trace.sh a1b2c3d4-5678-90ab-cdef-1234567890ab

# Scrub
./scrub_trace.sh trace_a1b2c3d4-5678-90ab-cdef-1234567890ab.json \
  "content,email,session_id"

# Review and share trace_a1b2c3d4-5678-90ab-cdef-1234567890ab.scrubbed.json

Upload (creates new tracing project):

export LANGSMITH_API_KEY='lsv2_pt_...'

./upload_trace.sh trace_a1b2c3d4-5678-90ab-cdef-1234567890ab.scrubbed.json \
  "debug-trace-2024-01"

# Creates a tracing project named "debug-trace-2024-01" with the uploaded runs

Help

Each script has a --help flag:

./extract_trace.sh --help
./scrub_trace.sh --help
./upload_trace.sh --help

EU Region

Set LANGSMITH_ENDPOINT for EU:

export LANGSMITH_ENDPOINT='https://eu.api.smith.langchain.com'

Troubleshooting

"jq required"

brew install jq  # macOS
apt-get install jq  # Linux

"No runs found"

  • Trace ID doesn't exist
  • Trace not fully ingested (wait a few seconds)
  • Wrong API key

"Failed to create project"

  • API key invalid or expired
  • No write permissions

Important

Always manually review scrubbed files before sharing to ensure all PII is removed.

S
Description
Bash scripts to extract, scrub, and upload LangSmith traces.
Readme MIT 48 KiB
Languages
Shell 100%