diff --git a/ddtrace/llmobs/_llmobs.py b/ddtrace/llmobs/_llmobs.py index 82e19f1b844..927acd3b651 100644 --- a/ddtrace/llmobs/_llmobs.py +++ b/ddtrace/llmobs/_llmobs.py @@ -491,7 +491,7 @@ def annotate( if parameters is not None: log.warning("Setting parameters is deprecated, please set parameters and other metadata as tags instead.") cls._tag_params(span, parameters) - if input_data or output_data: + if input_data is not None or output_data is not None: if span_kind == "llm": cls._tag_llm_io(span, input_messages=input_data, output_messages=output_data) elif span_kind == "embedding": diff --git a/releasenotes/notes/fix-numeric-annotations-7cf06b5ceb615282.yaml b/releasenotes/notes/fix-numeric-annotations-7cf06b5ceb615282.yaml new file mode 100644 index 00000000000..05ed3ddb964 --- /dev/null +++ b/releasenotes/notes/fix-numeric-annotations-7cf06b5ceb615282.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + LLM Observability: This fix resolves an issue where input and output values equal to zero were not being annotated + on workflow, task, agent and tool spans when using `LLMObs.annotate`. diff --git a/tests/llmobs/test_llmobs_service.py b/tests/llmobs/test_llmobs_service.py index 44b1a75f5d6..477dec45623 100644 --- a/tests/llmobs/test_llmobs_service.py +++ b/tests/llmobs/test_llmobs_service.py @@ -388,6 +388,17 @@ def test_annotate_input_string(LLMObs): assert retrieval_span.get_tag(INPUT_VALUE) == "test_input" +def test_annotate_numeric_io(LLMObs): + with LLMObs.task() as task_span: + LLMObs.annotate(span=task_span, input_data=0, output_data=0) + assert task_span.get_tag(INPUT_VALUE) == "0" + assert task_span.get_tag(OUTPUT_VALUE) == "0" + with LLMObs.task() as task_span: + LLMObs.annotate(span=task_span, input_data=1.23, output_data=1.23) + assert task_span.get_tag(INPUT_VALUE) == "1.23" + assert task_span.get_tag(OUTPUT_VALUE) == "1.23" + + def test_annotate_input_serializable_value(LLMObs): with LLMObs.task() as task_span: LLMObs.annotate(span=task_span, input_data=["test_input"])