Skip to content

Commit c20b728

Browse files
authored
feat(gen_ai): Add details to gen_ai.request.messages (#122)
Update the description and example of `gen_ai.request.messages` to be more strict. The `role` of a message must be one of `"user"`, `"assistant"`, `"tool"`, or `"system"`. Added missing information about `tool` messages and more details regarding the object structure of message content.
1 parent d56e042 commit c20b728

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

generated/attributes/gen_ai.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,14 @@ The maximum number of tokens to generate in the response.
199199

200200
### gen_ai.request.messages
201201

202-
The messages passed to the model. It has to be a stringified version of an array of objects. The "content" can be a string or an array of objects.
202+
The messages passed to the model. It has to be a stringified version of an array of objects. The `role` attribute of each object must be `"user"`, `"assistant"`, `"tool"`, or `"system"`. For messages of the role `"tool"`, the `content` can be a string or an arbitrary object with information about the tool call. For other messages the `content` can be either a string or a list of objects in the format `{type: "text", text:"..."}`.
203203

204204
| Property | Value |
205205
| --- | --- |
206206
| Type | `string` |
207207
| Has PII | maybe |
208208
| Exists in OpenTelemetry | No |
209-
| Example | `[{"role": "system", "content": "Generate a random number."}, {"role": "user", "content": [{"text": "Generate a random number between 0 and 10.", "type": "text"}]}]` |
209+
| Example | `[{"role": "system", "content": "Generate a random number."}, {"role": "user", "content": [{"text": "Generate a random number between 0 and 10.", "type": "text"}]}, {"role": "tool", "content": {"toolCallId": "1", "toolName": "Weather", "output": "rainy"}}]` |
210210
| Aliases | `ai.input_messages` |
211211

212212
### gen_ai.request.model

javascript/sentry-conventions/src/attributes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,7 +2289,7 @@ export type GEN_AI_REQUEST_MAX_TOKENS_TYPE = number;
22892289
// Path: model/attributes/gen_ai/gen_ai__request__messages.json
22902290

22912291
/**
2292-
* The messages passed to the model. It has to be a stringified version of an array of objects. The "content" can be a string or an array of objects. `gen_ai.request.messages`
2292+
* The messages passed to the model. It has to be a stringified version of an array of objects. The `role` attribute of each object must be `"user"`, `"assistant"`, `"tool"`, or `"system"`. For messages of the role `"tool"`, the `content` can be a string or an arbitrary object with information about the tool call. For other messages the `content` can be either a string or a list of objects in the format `{type: "text", text:"..."}`. `gen_ai.request.messages`
22932293
*
22942294
* Attribute Value Type: `string` {@link GEN_AI_REQUEST_MESSAGES_TYPE}
22952295
*
@@ -2299,7 +2299,7 @@ export type GEN_AI_REQUEST_MAX_TOKENS_TYPE = number;
22992299
*
23002300
* Aliases: {@link AI_INPUT_MESSAGES} `ai.input_messages`
23012301
*
2302-
* @example "[{\"role\": \"system\", \"content\": \"Generate a random number.\"}, {\"role\": \"user\", \"content\": [{\"text\": \"Generate a random number between 0 and 10.\", \"type\": \"text\"}]}]"
2302+
* @example "[{\"role\": \"system\", \"content\": \"Generate a random number.\"}, {\"role\": \"user\", \"content\": [{\"text\": \"Generate a random number between 0 and 10.\", \"type\": \"text\"}]}, {\"role\": \"tool\", \"content\": {\"toolCallId\": \"1\", \"toolName\": \"Weather\", \"output\": \"rainy\"}}]"
23032303
*/
23042304
export const GEN_AI_REQUEST_MESSAGES = 'gen_ai.request.messages';
23052305

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"key": "gen_ai.request.messages",
3-
"brief": "The messages passed to the model. It has to be a stringified version of an array of objects. The \"content\" can be a string or an array of objects.",
3+
"brief": "The messages passed to the model. It has to be a stringified version of an array of objects. The `role` attribute of each object must be `\"user\"`, `\"assistant\"`, `\"tool\"`, or `\"system\"`. For messages of the role `\"tool\"`, the `content` can be a string or an arbitrary object with information about the tool call. For other messages the `content` can be either a string or a list of objects in the format `{type: \"text\", text:\"...\"}`.",
44
"type": "string",
55
"pii": {
66
"key": "maybe"
77
},
88
"is_in_otel": false,
9-
"example": "[{\"role\": \"system\", \"content\": \"Generate a random number.\"}, {\"role\": \"user\", \"content\": [{\"text\": \"Generate a random number between 0 and 10.\", \"type\": \"text\"}]}]",
9+
"example": "[{\"role\": \"system\", \"content\": \"Generate a random number.\"}, {\"role\": \"user\", \"content\": [{\"text\": \"Generate a random number between 0 and 10.\", \"type\": \"text\"}]}, {\"role\": \"tool\", \"content\": {\"toolCallId\": \"1\", \"toolName\": \"Weather\", \"output\": \"rainy\"}}]",
1010
"alias": ["ai.input_messages"]
1111
}

0 commit comments

Comments
 (0)