Skip to content

Commit bf15c90

Browse files
ncybulYun-Kim
andauthored
chore(llmobs): [MLOB-2093] remove deprecated parameters arg from annotate method (#12085)
Deprecates the `parameters` arg for the LLMObs annotation method in favor of `metadata`. I verified this change by running the following code: ``` @workflow def run(): LLMObs.annotate( input_data="hello", output_data="bye", parameters={"example": True}, ) return None run() ``` Which produced the following error as expected: `TypeError: LLMObs.annotate() got an unexpected keyword argument 'parameters'`. Replacing `parameters` with `metadata` resolves the issue: ![image](https://github.com/user-attachments/assets/c6858362-43d6-4647-99a9-db4356cab539) ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) --------- Co-authored-by: Yun Kim <[email protected]>
1 parent 03e8375 commit bf15c90

File tree

7 files changed

+14
-55
lines changed

7 files changed

+14
-55
lines changed

ddtrace/llmobs/_constants.py

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
INPUT_DOCUMENTS = "_ml_obs.meta.input.documents"
1414
INPUT_MESSAGES = "_ml_obs.meta.input.messages"
1515
INPUT_VALUE = "_ml_obs.meta.input.value"
16-
INPUT_PARAMETERS = "_ml_obs.meta.input.parameters"
1716
INPUT_PROMPT = "_ml_obs.meta.input.prompt"
1817

1918
OUTPUT_DOCUMENTS = "_ml_obs.meta.output.documents"

ddtrace/llmobs/_llmobs.py

+1-19
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from ddtrace.llmobs._constants import ANNOTATIONS_CONTEXT_ID
3636
from ddtrace.llmobs._constants import INPUT_DOCUMENTS
3737
from ddtrace.llmobs._constants import INPUT_MESSAGES
38-
from ddtrace.llmobs._constants import INPUT_PARAMETERS
3938
from ddtrace.llmobs._constants import INPUT_PROMPT
4039
from ddtrace.llmobs._constants import INPUT_VALUE
4140
from ddtrace.llmobs._constants import METADATA
@@ -148,8 +147,6 @@ def _llmobs_span_event(cls, span: Span) -> Dict[str, Any]:
148147
meta["model_name"] = span._get_ctx_item(MODEL_NAME)
149148
meta["model_provider"] = (span._get_ctx_item(MODEL_PROVIDER) or "custom").lower()
150149
meta["metadata"] = span._get_ctx_item(METADATA) or {}
151-
if span._get_ctx_item(INPUT_PARAMETERS):
152-
meta["input"]["parameters"] = span._get_ctx_item(INPUT_PARAMETERS)
153150
if span_kind == "llm" and span._get_ctx_item(INPUT_MESSAGES) is not None:
154151
meta["input"]["messages"] = span._get_ctx_item(INPUT_MESSAGES)
155152
if span._get_ctx_item(INPUT_VALUE) is not None:
@@ -710,7 +707,6 @@ def retrieval(
710707
def annotate(
711708
cls,
712709
span: Optional[Span] = None,
713-
parameters: Optional[Dict[str, Any]] = None,
714710
prompt: Optional[dict] = None,
715711
input_data: Optional[Any] = None,
716712
output_data: Optional[Any] = None,
@@ -720,7 +716,7 @@ def annotate(
720716
_name: Optional[str] = None,
721717
) -> None:
722718
"""
723-
Sets parameters, inputs, outputs, tags, and metrics as provided for a given LLMObs span.
719+
Sets metadata, inputs, outputs, tags, and metrics as provided for a given LLMObs span.
724720
Note that with the exception of tags, this method will override any existing values for the provided fields.
725721
726722
:param Span span: Span to annotate. If no span is provided, the current active span will be used.
@@ -747,7 +743,6 @@ def annotate(
747743
{"name": str, "id": str, "text": str, "score": float},
748744
or a list of dictionaries with the same signature.
749745
- other: any JSON serializable type.
750-
:param parameters: (DEPRECATED) Dictionary of JSON serializable key-value pairs to set as input parameters.
751746
:param metadata: Dictionary of JSON serializable key-value metadata pairs relevant to the input/output operation
752747
described by the LLMObs span.
753748
:param tags: Dictionary of JSON serializable key-value tag pairs to set or update on the LLMObs span
@@ -773,9 +768,6 @@ def annotate(
773768
if tags is not None:
774769
cls._tag_span_tags(span, tags)
775770
span_kind = span._get_ctx_item(SPAN_KIND)
776-
if parameters is not None:
777-
log.warning("Setting parameters is deprecated, please set parameters and other metadata as tags instead.")
778-
cls._tag_params(span, parameters)
779771
if _name is not None:
780772
span.name = _name
781773
if prompt is not None:
@@ -803,16 +795,6 @@ def _tag_prompt(span, prompt: dict) -> None:
803795
log.warning("Failed to validate prompt with error: ", exc_info=True)
804796
return
805797

806-
@staticmethod
807-
def _tag_params(span: Span, params: Dict[str, Any]) -> None:
808-
"""Tags input parameters for a given LLMObs span.
809-
Will be mapped to span's `meta.input.parameters` field.
810-
"""
811-
if not isinstance(params, dict):
812-
log.warning("parameters must be a dictionary of key-value pairs.")
813-
return
814-
span._set_ctx_item(INPUT_PARAMETERS, params)
815-
816798
@classmethod
817799
def _tag_llm_io(cls, span, input_messages=None, output_messages=None):
818800
"""Tags input/output messages for LLM-kind spans.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
upgrade:
3+
- |
4+
LLM Observability: Removes the deprecated ``parameters`` argument from ``LLMObs annotate()``. Use ``metadata`` instead.

tests/llmobs/_utils.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def _expected_llmobs_llm_span_event(
6262
input_documents=None,
6363
output_messages=None,
6464
output_value=None,
65-
parameters=None,
6665
metadata=None,
6766
token_metrics=None,
6867
model_name=None,
@@ -78,7 +77,6 @@ def _expected_llmobs_llm_span_event(
7877
span_kind: either "llm" or "agent" or "embedding"
7978
input_messages: list of input messages in format {"content": "...", "optional_role", "..."}
8079
output_messages: list of output messages in format {"content": "...", "optional_role", "..."}
81-
parameters: dict of input parameters
8280
metadata: dict of metadata key value pairs
8381
token_metrics: dict of token metrics (e.g. prompt_tokens, completion_tokens, total_tokens)
8482
model_name: name of the model
@@ -112,8 +110,6 @@ def _expected_llmobs_llm_span_event(
112110
if model_provider is not None:
113111
meta_dict.update({"model_provider": model_provider})
114112
meta_dict.update({"metadata": metadata or {}})
115-
if parameters is not None:
116-
meta_dict["input"].update({"parameters": parameters})
117113
span_event["meta"].update(meta_dict)
118114
if token_metrics is not None:
119115
span_event["metrics"].update(token_metrics)
@@ -126,7 +122,6 @@ def _expected_llmobs_non_llm_span_event(
126122
input_value=None,
127123
output_value=None,
128124
output_documents=None,
129-
parameters=None,
130125
metadata=None,
131126
token_metrics=None,
132127
tags=None,
@@ -140,7 +135,6 @@ def _expected_llmobs_non_llm_span_event(
140135
span_kind: one of "workflow", "task", "tool", "retrieval"
141136
input_value: input value string
142137
output_value: output value string
143-
parameters: dict of input parameters
144138
metadata: dict of metadata key value pairs
145139
token_metrics: dict of token metrics (e.g. prompt_tokens, completion_tokens, total_tokens)
146140
tags: dict of tags to add/override on span
@@ -160,8 +154,6 @@ def _expected_llmobs_non_llm_span_event(
160154
meta_dict["output"].update({"value": output_value})
161155
if input_value is not None:
162156
meta_dict["input"].update({"value": input_value})
163-
if parameters is not None:
164-
meta_dict["input"].update({"parameters": parameters})
165157
meta_dict.update({"metadata": metadata or {}})
166158
if output_value is not None:
167159
meta_dict["output"].update({"value": output_value})
@@ -275,7 +267,6 @@ def _completion_event():
275267
"model_provider": "openai",
276268
"input": {
277269
"messages": [{"content": "who broke enigma?"}],
278-
"parameters": {"temperature": 0, "max_tokens": 256},
279270
},
280271
"output": {
281272
"messages": [
@@ -284,6 +275,7 @@ def _completion_event():
284275
}
285276
]
286277
},
278+
"metadata": {"temperature": 0, "max_tokens": 256},
287279
},
288280
"metrics": {"input_tokens": 64, "output_tokens": 128, "total_tokens": 192},
289281
}
@@ -312,7 +304,6 @@ def _chat_completion_event():
312304
},
313305
{"role": "user", "content": "I am a hobbit looking to go to Mordor"},
314306
],
315-
"parameters": {"temperature": 0.9, "max_tokens": 256},
316307
},
317308
"output": {
318309
"messages": [
@@ -322,6 +313,7 @@ def _chat_completion_event():
322313
},
323314
]
324315
},
316+
"metadata": {"temperature": 0.9, "max_tokens": 256},
325317
},
326318
"metrics": {"input_tokens": 64, "output_tokens": 128, "total_tokens": 192},
327319
}

tests/llmobs/test_llmobs.py

-8
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,6 @@ def test_input_messages_are_set(tracer, llmobs_events):
114114
assert llmobs_events[0]["meta"]["input"]["messages"] == [{"content": "message", "role": "user"}]
115115

116116

117-
def test_input_parameters_are_set(tracer, llmobs_events):
118-
"""Test that input parameters are set on the span event if they are present on the span."""
119-
with tracer.trace("root_llm_span", span_type=SpanTypes.LLM) as llm_span:
120-
llm_span._set_ctx_item(const.SPAN_KIND, "llm")
121-
llm_span._set_ctx_item(const.INPUT_PARAMETERS, {"key": "value"})
122-
assert llmobs_events[0]["meta"]["input"]["parameters"] == {"key": "value"}
123-
124-
125117
def test_output_messages_are_set(tracer, llmobs_events):
126118
"""Test that output messages are set on the span event if they are present on the span."""
127119
with tracer.trace("root_llm_span", span_type=SpanTypes.LLM) as llm_span:

tests/llmobs/test_llmobs_decorators.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def test_llm_annotate(llmobs, llmobs_events):
271271
@llm(model_name="test_model", model_provider="test_provider", name="test_function", session_id="test_session_id")
272272
def f():
273273
llmobs.annotate(
274-
parameters={"temperature": 0.9, "max_tokens": 50},
274+
metadata={"temperature": 0.9, "max_tokens": 50},
275275
input_data=[{"content": "test_prompt"}],
276276
output_data=[{"content": "test_response"}],
277277
tags={"custom_tag": "tag_value"},
@@ -287,7 +287,7 @@ def f():
287287
model_provider="test_provider",
288288
input_messages=[{"content": "test_prompt"}],
289289
output_messages=[{"content": "test_response"}],
290-
parameters={"temperature": 0.9, "max_tokens": 50},
290+
metadata={"temperature": 0.9, "max_tokens": 50},
291291
token_metrics={"input_tokens": 10, "output_tokens": 20, "total_tokens": 30},
292292
tags={"custom_tag": "tag_value"},
293293
session_id="test_session_id",
@@ -298,7 +298,7 @@ def test_llm_annotate_raw_string_io(llmobs, llmobs_events):
298298
@llm(model_name="test_model", model_provider="test_provider", name="test_function", session_id="test_session_id")
299299
def f():
300300
llmobs.annotate(
301-
parameters={"temperature": 0.9, "max_tokens": 50},
301+
metadata={"temperature": 0.9, "max_tokens": 50},
302302
input_data="test_prompt",
303303
output_data="test_response",
304304
tags={"custom_tag": "tag_value"},
@@ -314,7 +314,7 @@ def f():
314314
model_provider="test_provider",
315315
input_messages=[{"content": "test_prompt"}],
316316
output_messages=[{"content": "test_response"}],
317-
parameters={"temperature": 0.9, "max_tokens": 50},
317+
metadata={"temperature": 0.9, "max_tokens": 50},
318318
token_metrics={"input_tokens": 10, "output_tokens": 20, "total_tokens": 30},
319319
tags={"custom_tag": "tag_value"},
320320
session_id="test_session_id",

tests/llmobs/test_llmobs_service.py

+3-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from ddtrace.llmobs import LLMObs as llmobs_service
1414
from ddtrace.llmobs._constants import INPUT_DOCUMENTS
1515
from ddtrace.llmobs._constants import INPUT_MESSAGES
16-
from ddtrace.llmobs._constants import INPUT_PARAMETERS
1716
from ddtrace.llmobs._constants import INPUT_PROMPT
1817
from ddtrace.llmobs._constants import INPUT_VALUE
1918
from ddtrace.llmobs._constants import IS_EVALUATION_SPAN
@@ -356,33 +355,24 @@ def test_embedding_span(llmobs, llmobs_events):
356355

357356

358357
def test_annotate_no_active_span_logs_warning(llmobs, mock_llmobs_logs):
359-
llmobs.annotate(parameters={"test": "test"})
358+
llmobs.annotate(metadata={"test": "test"})
360359
mock_llmobs_logs.warning.assert_called_once_with("No span provided and no active LLMObs-generated span found.")
361360

362361

363362
def test_annotate_non_llm_span_logs_warning(llmobs, mock_llmobs_logs):
364363
dummy_tracer = DummyTracer()
365364
with dummy_tracer.trace("root") as non_llmobs_span:
366-
llmobs.annotate(span=non_llmobs_span, parameters={"test": "test"})
365+
llmobs.annotate(span=non_llmobs_span, metadata={"test": "test"})
367366
mock_llmobs_logs.warning.assert_called_once_with("Span must be an LLMObs-generated span.")
368367

369368

370369
def test_annotate_finished_span_does_nothing(llmobs, mock_llmobs_logs):
371370
with llmobs.llm(model_name="test_model", name="test_llm_call", model_provider="test_provider") as span:
372371
pass
373-
llmobs.annotate(span=span, parameters={"test": "test"})
372+
llmobs.annotate(span=span, metadata={"test": "test"})
374373
mock_llmobs_logs.warning.assert_called_once_with("Cannot annotate a finished span.")
375374

376375

377-
def test_annotate_parameters(llmobs, mock_llmobs_logs):
378-
with llmobs.llm(model_name="test_model", name="test_llm_call", model_provider="test_provider") as span:
379-
llmobs.annotate(span=span, parameters={"temperature": 0.9, "max_tokens": 50})
380-
assert span._get_ctx_item(INPUT_PARAMETERS) == {"temperature": 0.9, "max_tokens": 50}
381-
mock_llmobs_logs.warning.assert_called_once_with(
382-
"Setting parameters is deprecated, please set parameters and other metadata as tags instead."
383-
)
384-
385-
386376
def test_annotate_metadata(llmobs):
387377
with llmobs.llm(model_name="test_model", name="test_llm_call", model_provider="test_provider") as span:
388378
llmobs.annotate(span=span, metadata={"temperature": 0.5, "max_tokens": 20, "top_k": 10, "n": 3})

0 commit comments

Comments
 (0)