Skip to Content
Judgment Labs

Conversations

Record your agent's conversations as observations, one per model call.

A conversation is one context window of your agent: everything its model saw and produced, call by call. Conversations are derived from observations (LLM spans). Each observation records one model call, with everything the model was given and what it produced. Judgment groups observations that share a session ID into one conversation and shows it, exactly as the model saw it, under Conversations in Logs. When you already trace your model calls in a supported format, Judgment records observations from your traces. For any other model call, send the observation yourself.

Conversations are in beta. Judgment records them only for organizations where they're turned on. Contact support to turn them on.

Record observations from your existing telemetry

If you trace your agent with OpenTelemetry or a Judgment integration, you shouldn't need to change your code. Judgment reads each model-call span as it arrives and records it as an observation when the span uses one of these formats:

  • OpenAI Chat Completions
  • OpenAI Responses
  • Anthropic Messages
  • Anthropic SDK OpenTelemetry instrumentation
  • Vercel AI SDK v7
  • PydanticAI
  • Claude Code
  • Eve
  • OpenRouter Broadcast

Need another framework or provider? Contact us to add it, or send the observation yourself.

A span becomes an observation when:

  • It covers one model call, with the call's input and output.
  • It has a session ID (judgment.session_id or gen_ai.conversation.id) that represents one context window of your agent, shared by every call that continues it. See Session guidance.

When you write the span yourself, give each call's input the whole window the model was given, including earlier messages and tool results. Claude Code and Eve spans carry only part of the window, and Judgment records them as they are.

Spans from the frameworks above already follow a supported format, so they usually need nothing extra. If your conversations look inconsistent or calls are missing, see Conversation view checks in Trace health. When a span's recorded messages fail validation, its judgment.conversation.warnings attribute lists the problems.

Send an observation

Send each observation one of two ways:

  • On a span, when you trace the agent. The observation joins the call's span, and the span supplies its conversation, customer, user, and usage.
  • Without traces, when you only record model calls. You send each observation with the time the call completed.

On a span

Set the observation on the model call's span. It travels as JSON text under judgment.conversation.observation. One span holds one observation; setting it again replaces it.

Tracer.set_conversation_observation takes a typed ConversationObservation, so your type checker flags fields the format doesn't define before Judgment rejects them.

from judgeval import Tracer
from judgeval.trace import ConversationMessage, ConversationObservation

@Tracer.observe(span_type="llm", span_name="support_reply")
def reply(history: list[ConversationMessage]) -> str:
    response = my_model.generate(history)
    observation: ConversationObservation = {
        "model": "my-model-v2",
        "input": [
            {"type": "message", "role": "system", "content": [{"type": "text", "text": "You help customers with orders."}]},
            *history,
        ],
        "output": [
            {"type": "message", "role": "assistant", "content": [{"type": "text", "text": response.text}]},
        ],
        "finish_reason": "stop",
    }
    Tracer.set_conversation_observation(observation)
    return response.text

Without traces

Configure Trajectory once when your app starts, then record each model call. record returns at once and never raises: the SDK queues the call and sends it in the background, in batches. init reads JUDGMENT_API_KEY and JUDGMENT_ORG_ID unless you pass them (see Credentials). If one is missing or the project is not found, init logs a warning and recording stays off.

Trajectory.record takes a typed Observation. A background thread sends the queued calls, and sends what is left when the interpreter exits.

from judgeval import Trajectory
from judgeval.trajectory import Observation

Trajectory.init(project_name="support-bot", environment="production")

def reply(ticket_id: str, history: list) -> str:
    response = my_model.generate(history)
    observation: Observation = {
        "conversation_id": ticket_id,
        "model": "my-model-v2",
        "input": history,
        "output": [
            {"type": "message", "role": "assistant", "content": [{"type": "text", "text": response.text}]},
        ],
    }
    Trajectory.record(observation)
    return response.text

In a serverless handler, call Trajectory.flush() before the handler returns.

Each observation sent without traces needs:

  • conversation_id. Nothing supplies it from a span.
  • The time the call completed (observed_at). The SDKs set it to the time you call record. To set it yourself, pass it next to the observation, not inside it: Trajectory.record(observation, observed_at=completed_at) in Python, or Trajectory.record(observation, { observedAt: completedAt }) in TypeScript. It must be within the last 26 weeks and at most 5 minutes in the future. Judgment identifies a call by its content and this time, to the millisecond: two identical calls at different times are two calls, and a retry with the same time stores the call once.

In the SDKs, the environment passed to init applies to every call. Over HTTP, set environment on each observation. Judges limited to environments use it, as they use a span's environment.

Observation

FieldTypeMeaning
inputItem list, requiredEverything the model was given, in order.
outputItem listWhat the model produced, when recorded.
conversation_idStringThe thread of context the call belongs to. Defaults to the span's judgment.session_id. One of the two is required.
customer_idStringThe customer the call ran for. Defaults to the span's judgment.customer_id.
user_idStringThe user the call ran for. Defaults to the span's judgment.customer_user_id.
toolsTool listThe tools the model could call: name, and optional description, parameters (JSON Schema of the arguments), and metadata.
modelStringThe model that ran the call.
response_idStringThe ID for the call's response, such as OpenAI's resp_ or chatcmpl- ID or Anthropic's msg_ ID. Generated observations prefer the span's normalized judgment.response_id, falling back to an ID extracted from a supported response body. Explicitly supplied observations keep their own ID when present, otherwise they use the span's ID. Observation IDs are not copied back to span attributes. See Attribute normalization.
finish_reasonStringWhy the model stopped, as the provider reported it.
truncatedBooleanWhether the source cut the recorded content short, so the input or output is not all of the call.
usageUsageWhat the call consumed. Defaults to the span's judgment.usage.* attributes.
errorErrorA recorded model-call failure.
truncatedBooleanSet to true when your tracer cut the recorded content short, so input or output is not all of the call. Keep the cut text as it was recorded. Leave it out otherwise.
metadataObject of JSON valuesAny other facts about this call.

Set conversation_id (or the session ID) to the same value on every call that continues the same context. An observation sent without traces has no span, so conversation_id is required, and customer_id, user_id, and usage have no defaults. See Session guidance.

Items

input and output are flat, ordered lists of items. An assistant turn with text and two tool calls is one message item followed by two tool_call items.

typeFields
messagerole (system, user, or assistant), content (part list)
tool_callname, arguments (any JSON), optional call_id
tool_resultoutput (part list), optional call_id (the call it answers), optional error
reasoningtext
customkind (a name such as acme:handoff), data (any JSON)

Parts

typeFields
texttext
image, audio, filesource: {"type": "url", "url": ...} or {"type": "base64", "data": ...}; optional media_type, such as image/png
jsonvalue (any JSON)
customkind, data (any JSON)

Use custom items and parts for data observations do not define yet.

Usage

Every field is optional. Leave out what you don't know; don't send zero.

FieldMeaning
non_cached_input_tokensInput tokens charged at the normal rate.
non_cached_input_image_tokensImage input tokens charged at the normal rate.
cache_read_input_tokensInput tokens read from the prompt cache.
cache_creation_input_tokensInput tokens written to the prompt cache.
output_tokensGenerated tokens, excluding reasoning.
output_image_tokensGenerated image tokens.
reasoning_tokensTokens spent reasoning.
total_cost_usdThe call's cost in USD.

Each field means the same as the matching judgment.usage.* attribute in Attribute keys.

Errors

error on the observation records a failed model call. error on a tool_result records a failed tool. Both take optional type, message, and stacktrace; {} records a failure without details. Judgment never infers a failure from span status or a missing output.

Rules

  • Send the whole window. input holds every item the model was given, including history from earlier calls. Judgment stores each distinct item once per conversation, so resent history costs little storage. It still counts toward the span's size.
  • Keep per-call facts off items. An item must be exactly what is resent on later calls. Finish reason, usage, and latency belong on the observation.
  • No unknown fields. Every object is closed. A field this page does not define rejects the whole observation.

Validation and limits

An observation that does not fit this format is not stored. On a span, Judgment sets judgment.conversation.warnings on the span, listing each problem by field path. The span and its trace are stored as usual. Without traces, the request fails with 400 and lists each problem; nothing in the request is stored. The SDKs resend the other observations in a rejected batch, so one invalid observation does not drop the rest.

LimitValue
IDs, names, kinds, models, finish reasons, media types1 to 512 characters
Span attributes, including the observation8 MiB per span. See Ingest contract.
Observations per request, without traces1 to 100
Time the call completed, without tracesWithin the last 26 weeks, and at most 5 minutes ahead

On this page