Skip to content

Commit e164bc0

Browse files
Update log-llm-trace.mdx with LangChain v1 format documentation (#969)
Add expected v1 format to langsmith docs Preview: https://langchain-5e9cc07a-preview-logllm-1760939274-d1f4ce2.mintlify.app/langsmith/log-llm-trace
1 parent 69c8036 commit e164bc0

File tree

1 file changed

+156
-67
lines changed

1 file changed

+156
-67
lines changed

src/langsmith/log-llm-trace.mdx

Lines changed: 156 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -17,124 +17,176 @@ If you are using [LangChain OSS](https://python.langchain.com/docs/tutorials/llm
1717
The examples on this page use the `traceable` decorator/wrapper to log the model run (which is the recommended approach for Python and JS/TS). However, the same idea applies if you are using the [RunTree](/langsmith/annotate-code#use-the-runtree-api) or [API](https://api.smith.langchain.com/redoc) directly.
1818
</Note>
1919

20+
2021
## Messages Format
2122

2223
When tracing a custom model or a custom input/output format, it must either follow the LangChain format, OpenAI completions format or Anthropic messages format. For more details, refer to the [OpenAI Chat Completions](https://platform.openai.com/docs/api-reference/chat/create) or [Anthropic Messages](https://docs.claude.com/en/api/messages) documentation. The LangChain format is:
2324

24-
<Expandable title="LangChain format">
25+
26+
<Expandable title="LangChain format">
2527

2628
<ParamField path="messages" type="array" required>
2729
A list of messages containing the content of the conversation.
2830

29-
<ParamField path="role" type="string" required>
30-
Identifies the message type. One of: <code>system</code> | <code>user</code> | <code>assistant</code> | <code>tool</code>
31+
<ParamField path="type" type="string" required>
32+
Identifies the message type. One of: <code>system</code> | <code>reasoning</code> | <code>user</code> | <code>assistant</code> | <code>tool</code>
3133
</ParamField>
3234

33-
<ParamField path="content" type="string | array" required>
34-
Content of the message. Either a string or an array of structured parts. May be an empty string if `tool_calls` is present.
35+
<ParamField path="content" type="array" required>
36+
Content of the message. List of typed dictionaries.
3537

3638
<Expandable title="Content options">
3739
<ParamField path="type" type="string" required>
38-
One of: <code>text</code>, <code>image</code>, <code>file</code>, <code>audio</code>.
40+
One of: <code>text</code> | <code>image</code> | <code>file</code> | <code>audio</code> | <code>video</code> | <code>tool_call</code> | <code>server_tool_call</code> | <code>server_tool_result</code>.
3941
</ParamField>
4042

4143
<Expandable title="text">
4244
<ParamField path="type" type="literal('text')" required />
4345
<ParamField path="text" type="string" required>
4446
Text content.
4547
</ParamField>
48+
<ParamField path="annotations" type="object[]">
49+
List of annotations for the text
50+
</ParamField>
51+
<ParamField path="extras" type="object">
52+
Additional provider-specific data.
53+
</ParamField>
54+
</Expandable>
55+
56+
<Expandable title="reasoning">
57+
<ParamField path="type" type="literal('reasoning')" required />
58+
<ParamField path="text" type="string" required>
59+
Text content.
60+
</ParamField>
61+
<ParamField path="extras" type="object">
62+
Additional provider-specific data.
63+
</ParamField>
4664
</Expandable>
4765

4866
<Expandable title="image">
4967
<ParamField path="type" type="literal('image')" required />
50-
<ParamField path="source_type" type="string" required>
51-
One of: <code>base64</code> or <code>url</code>.
68+
<ParamField path="url" type="string">
69+
URL pointing to the image location.
5270
</ParamField>
53-
<ParamField path="data" type="string">
54-
Base64-encoded image bytes. Required when <code>source_type</code> is <code>base64</code>.
71+
<ParamField path="base64" type="string" required>
72+
Base64-encoded image data.
5573
</ParamField>
56-
<ParamField path="url" type="string">
57-
URL. Required when <code>source_type</code> is <code>url</code>.
74+
<ParamField path="id" type="string">
75+
Reference ID to an externally stored image (e.g., in a provider’s file system or in a bucket).
5876
</ParamField>
5977
<ParamField path="mime_type" type="string">
60-
MIME type (e.g., <code>image/jpeg</code>). Recommended for <code>base64</code>.
78+
Image [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml#image) (e.g., `image/jpeg`, `image/png`).
6179
</ParamField>
6280
</Expandable>
6381

6482
<Expandable title="file (e.g., PDFs)">
6583
<ParamField path="type" type="literal('file')" required />
66-
<ParamField path="source_type" type="string" required>
67-
One of: <code>base64</code> or <code>url</code>.
84+
<ParamField path="url" type="string">
85+
URL pointing to the file.
6886
</ParamField>
69-
<ParamField path="data" type="string">
70-
Base64-encoded file bytes. Required when <code>source_type</code> is <code>base64</code>.
87+
<ParamField path="base64" type="string" required>
88+
Base64-encoded file data.
7189
</ParamField>
72-
<ParamField path="url" type="string">
73-
Public URL. Required when <code>source_type</code> is <code>url</code>.
90+
<ParamField path="id" type="string">
91+
Reference ID to an externally stored file (e.g., in a provider’s file system or in a bucket).
7492
</ParamField>
75-
<ParamField path="mime_type" type="string" required>
76-
MIME type (e.g., <code>application/pdf</code>).
93+
<ParamField path="mime_type" type="string">
94+
File [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml#image) (e.g., `application/pdf`).
7795
</ParamField>
7896
</Expandable>
7997

8098
<Expandable title="audio">
8199
<ParamField path="type" type="literal('audio')" required />
82-
<ParamField path="source_type" type="string" required>
83-
One of: <code>base64</code> or <code>url</code>.
100+
<ParamField path="url" type="string">
101+
URL pointing to the audio file.
84102
</ParamField>
85-
<ParamField path="data" type="string">
86-
Base64-encoded audio bytes. Required when <code>source_type</code> is <code>base64</code>.
103+
<ParamField path="base64" type="string" required>
104+
Base64-encoded audio data.
87105
</ParamField>
106+
<ParamField path="id" type="string">
107+
Reference ID to an externally stored audio file (e.g., in a provider’s file system or in a bucket).
108+
</ParamField>
109+
<ParamField path="mime_type" type="string">
110+
Audio [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml#image) (e.g., `audio/mpeg`, `audio/wav`).
111+
</ParamField>
112+
</Expandable>
113+
114+
<Expandable title="video">
115+
<ParamField path="type" type="literal('video')" required />
88116
<ParamField path="url" type="string">
89-
Public URL. Required when <code>source_type</code> is <code>url</code>.
117+
URL pointing to the video file.
90118
</ParamField>
91-
<ParamField path="mime_type" type="string" required>
92-
MIME type (e.g., <code>audio/wav</code>).
119+
<ParamField path="base64" type="string" required>
120+
Base64-encoded video data.
121+
</ParamField>
122+
<ParamField path="id" type="string">
123+
Reference ID to an externally stored video file (e.g., in a provider’s file system or in a bucket).
124+
</ParamField>
125+
<ParamField path="mime_type" type="string">
126+
Video [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml#image) (e.g., `video/mp4`, `video/webm`).
93127
</ParamField>
94128
</Expandable>
95-
</Expandable>
96-
</ParamField>
97129

130+
<Expandable title="tool_call">
131+
<ParamField path="type" type="literal('tool_call')" required />
132+
<ParamField path="name" type="string" />
133+
<ParamField path="args" type="object" required>
134+
Arguments to pass to the tool.
135+
</ParamField>
136+
<ParamField path="id" type="string">
137+
Unique identifier for this tool call.
138+
</ParamField>
139+
</Expandable>
98140

99-
<ParamField path="tool_calls" type="array">
100-
Tools requested by the assistant. Only valid when <code>role</code> is <code>assistant</code>.
101-
<Expandable title="tool call object">
102-
<ParamField path="id" type="string" required>
103-
Unique identifier to correlate with tool results.
104-
</ParamField>
105-
<ParamField path="type" type="literal('function')" required>
106-
The tool call type (currently only <code>function</code>).
107-
</ParamField>
108-
<ParamField path="function" type="object" required>
109-
Name of the tool/function.
110-
<Expandable title="options">
111-
<ParamField path="name" type="string" required />
112-
<ParamField path="arguments" type="string" required>
113-
JSON-encoded string of arguments (e.g., <code>{"{"}"city":"SF"{"}"}</code>).
114-
</ParamField>
115-
116-
</Expandable>
117-
</ParamField>
141+
<Expandable title="server_tool_call">
142+
<ParamField path="type" type="literal('server_tool_call')" required />
143+
<ParamField path="id" type="string" required >
144+
Unique identifier for this tool call.
145+
</ParamField>
146+
<ParamField path="name" type="string" required>
147+
The name of the tool to be called.
148+
</ParamField>
149+
<ParamField path="args" type="object" required>
150+
Arguments to pass to the tool.
151+
</ParamField>
152+
</Expandable>
153+
154+
<Expandable title="server_tool_result">
155+
<ParamField path="type" type="literal('server_tool_result')" required />
156+
<ParamField path="tool_call_id" type="string" required>
157+
Identifier of the corresponding server tool call.
158+
</ParamField>
159+
<ParamField path="id" type="string">
160+
Unique identifier for this tool call.
161+
</ParamField>
162+
<ParamField path="status" type="string" required>
163+
Execution status of the server-side tool. One of: <code>success</code> | <code>error</code>.
164+
</ParamField>
165+
<ParamField path="output">
166+
Output of the executed tool.
167+
</ParamField>
168+
</Expandable>
118169

119170
</Expandable>
171+
120172
</ParamField>
121173

122174
<ParamField path="tool_call_id" type="string">
123175
Must match the <code>id</code> of a prior <code>assistant</code> message’s <code>tool_calls[i]</code> entry. Only valid when <code>role</code> is <code>tool</code>.
124176
</ParamField>
125177

126178
<ParamField path="usage_metadata" type="object">
127-
Use this field to send token counts and or costs with your model's output. See [this guide](/langsmith/log-llm-trace#provide-token-and-cost-information) for more details.
179+
Use this field to send token counts and/or costs with your model's output. See [this guide](/langsmith/log-llm-trace#provide-token-and-cost-information) for more details.
128180
</ParamField>
129181
</ParamField>
130182

131183
</Expandable>
132184

133-
### Examples
134185

135-
<CodeGroup>
186+
### Examples
187+
<CodeGroup>
136188

137-
```python Text input and output
189+
```python Text and reasoning
138190
inputs = {
139191
"messages": [
140192
{
@@ -157,6 +209,10 @@ outputs = {
157209
{
158210
"type": "text",
159211
"text": "The capital of France is Paris."
212+
},
213+
{
214+
"type": "reasoning",
215+
"text": "The user is asking about..."
160216
}
161217
]
162218
}
@@ -166,7 +222,7 @@ outputs = {
166222
```
167223

168224
```python Tool calls
169-
inputs = {
225+
input = {
170226
"messages": [
171227
{
172228
"role": "user",
@@ -184,17 +240,7 @@ outputs = {
184240
"messages": [
185241
{
186242
"role": "assistant",
187-
"content": "",
188-
"tool_calls": [
189-
{
190-
"id": "call_1",
191-
"type": "function",
192-
"function": {
193-
"name": "get_weather",
194-
"arguments": "{\"city\": \"San Francisco\"}"
195-
}
196-
}
197-
]
243+
"content": [{"type": "tool_call", "name": "get_weather", "args": {"city": "San Francisco"}, "id": "call_1"}],
198244
},
199245
{
200246
"role": "tool",
@@ -231,9 +277,7 @@ inputs = {
231277
},
232278
{
233279
"type": "image",
234-
"source_type": "url",
235280
"url": "https://fastly.picsum.photos/id/237/200/300.jpg?hmac=TmmQSbShHz9CdQm0NkEjx1Dyh_Y984R9LpNrpvH2D_U",
236-
"mime_type": "image/jpeg"
237281
}
238282
]
239283
}
@@ -254,6 +298,51 @@ outputs = {
254298
]
255299
}
256300
```
301+
302+
```python Server-side tool calls
303+
input = {
304+
"messages": [
305+
{
306+
"role": "user",
307+
"content": [
308+
{
309+
"type": "text",
310+
"text": "What is the price of AAPL?"
311+
}
312+
]
313+
}
314+
]
315+
}
316+
317+
output = {
318+
"messages": [
319+
{
320+
"role": "assistant",
321+
"content": [
322+
{
323+
"type": "server_tool_call",
324+
"name": "web_search",
325+
"args": {
326+
"query": "price of AAPL",
327+
"type": "search"
328+
},
329+
"id": "call_1"
330+
},
331+
{
332+
"type": "server_tool_result",
333+
"tool_call_id": "call_1",
334+
"status": "success"
335+
},
336+
{
337+
"type": "text",
338+
"text": "The price of AAPL is $150.00"
339+
}
340+
]
341+
}
342+
]
343+
}
344+
```
345+
257346
</CodeGroup>
258347

259348

0 commit comments

Comments
 (0)