Skip to main content
When your traces don’t live in LangSmith, build trajectories directly from your own data. tj.build_trajectory_from_messages() takes a flat list of Message objects and produces a fully-formed Trajectory ready to upload — same shape as the provider-ingested ones. The SDK ships recipes (messages_from_*) for the most common formats. For anything else, construct Message objects yourself using the same primitives.

Quickstart

No provider credentials are needed — only trajectory_api_key.

Message Recipes

The SDK ships adapters for these source formats:
All recipes fail loud on unexpected input. Silent fallbacks turn parse bugs into silent data-quality bugs, so unrecognized shapes raise ValueError / TypeError with descriptive messages. Fix the input, or write a custom recipe (see Custom Formats).

messages_from_openai_chat

Handles role normalization (human → user, ai → assistant), multi-modal content arrays, modern tool_calls, legacy function_call, usage, finish_reason, and reasoning pass-through.

messages_from_anthropic_messages

Parallel tool_result blocks are fanned out into one role="tool" Message each so step builders and tool-failure metrics see every result individually.

messages_from_vercel_ai_sdk

Supports both UIMessage (parts) and CoreMessage (content) shapes, text / tool-invocation / tool-call / tool-result / reasoning parts.

messages_from_prompt_response

For the simplest case — a single prompt and response, optionally with a system message:

messages_from_role_content_pairs

For ad-hoc construction from tuples:

Building the Trajectory

The builder automatically computes cumulative steps, tool-call metrics (num_tool_calls / num_tool_failures / tool_error_rate), and content-hash / idempotency-key telemetry fields.

Custom Formats

If none of the shipped recipes fit your data, write your own. The public helpers cover the fiddly parts:

Pair With Telemetry

build_trajectory_from_messages accepts a trace_id so trajectories built this way participate in the same correlation story as provider-imported ones. Pair it with tj.start_trace() and tj.upload_trace() for the cleanest workflow:
See Linking Events to Trajectories for the full correlation walkthrough.

Core Concepts

Trajectories, Steps, Turns, Messages.

Linking Events to Trajectories

Correlate uploaded trajectories with telemetry via trace_id.

API Reference

Full signatures for builders, recipes, and helpers.

PII Redaction

Strip sensitive data before trajectories leave your environment.