![]() |
VOOZH | about |
In Agent Observability, the Prompt Tracking feature links prompt templates and versions to LLM calls. Prompt Tracking works alongside Agent Observability’s traces, spans, and Playground.
Prompt Tracking enables you to:
To use Prompt Tracking, you can submit structured prompt metadata (ID, optional version, template, variables).
If you are using the Agent Observability Python SDK (dd-trace v3.16.0+), attach prompt metadata to the LLM span using the prompt argument or helper. See the Agent Observability Python SDK documentation.
If you are using the Agent Observability Node.js SDK (dd-trace v5.83.0+), attach prompt metadata to the LLM span using the prompt option. See the Agent Observability Node.js SDK documentation.
If you are using the Agent Observability API intake, submit prompt metadata to the Spans API endpoint. See the Agent Observability HTTP API reference documentation.
If you are using OpenTelemetry instrumentation, you can attach prompt metadata to your LLM spans by setting the _dd.ml_obs.prompt_tracking attribute with a JSON string containing your prompt information.
Set the attribute on any LLM span:
import json
span.set_attribute("_dd.ml_obs.prompt_tracking", json.dumps({
"name": "greeting-prompt",
"version": "v1",
"template": "Hello {{name}}, tell me about {{topic}}",
"variables": {"name": "Alice", "topic": "weather"}
}))
span.setAttribute("_dd.ml_obs.prompt_tracking", JSON.stringify({
name: "greeting-prompt",
version: "v1",
template: "Hello {{name}}, tell me about {{topic}}",
variables: { name: "Alice", topic: "weather" }
}));
span.SetAttributes(attribute.String("_dd.ml_obs.prompt_tracking",`{"name":"greeting-prompt","version":"v1","template":"Hello {{name}}, tell me about {{topic}}","variables":{"name":"Alice","topic":"weather"}}`,))The following fields are supported in the prompt tracking JSON:
| Field | Type | Required | Description |
|---|---|---|---|
template | string | Yes (or chat_template) | Template string for single-message prompts |
chat_template | array | Yes (or template) | List of {"role": "...", "content": "..."} message templates |
id | string | No | Unique identifier for the prompt. Defaults to {ml_app}_unnamed-prompt if omitted |
name | string | No | Prompt name. Used as a fallback for id if id is omitted |
version | string | No | User-supplied version tag |
variables | object | No | Template variable substitutions |
rag_context_variables | array of strings | No | Names of variables in variables that contain RAG context (ground truth). Used by RAG evaluators |
rag_query_variables | array of strings | No | Names of variables in variables that contain the user query. Used by RAG evaluators |
If you are using LangChain prompt templates, Datadog automatically captures prompt metadata without code changes. IDs are derived from module or template names. To override these IDs, see Agent Observability Auto-instrumentation: LangChain.
View your app in Agent Observability and select Prompts on the left. The Prompts view features the following information:
Click on a prompt to open a detailed side-panel view that features information about version activity and various metrics. You can also see a diff view of two versions, open Trace Explorer pre-filtered to spans that use a selected version, or start a Playground session pre-populated with the selected version’s template and variables.
You can use the Agent Observability Trace Explorer to locate requests by prompt usage. You can use a prompt’s name, ID, and version as facets for both trace-level and span-level search. Click any LLM span to see the prompt that generated it.
Additional helpful documentation, links, and articles:
| |