diff --git a/ddtrace/llmobs/_llmobs.py b/ddtrace/llmobs/_llmobs.py index 75d1b15761a..94a5e421975 100644 --- a/ddtrace/llmobs/_llmobs.py +++ b/ddtrace/llmobs/_llmobs.py @@ -1713,6 +1713,10 @@ def submit_evaluation( error = "invalid_metric_label" raise ValueError("label must be the specified name of the evaluation metric.") + if "." in label: + error = "invalid_label_value" + raise ValueError("label value must not contain a '.'.") + metric_type = metric_type.lower() if metric_type not in ("categorical", "score", "boolean"): error = "invalid_metric_type" diff --git a/releasenotes/notes/fix-prevent-dots-in-evaluation-metric-labels-ab5caab19d52d3e1.yaml b/releasenotes/notes/fix-prevent-dots-in-evaluation-metric-labels-ab5caab19d52d3e1.yaml new file mode 100644 index 00000000000..aa05c28cc21 --- /dev/null +++ b/releasenotes/notes/fix-prevent-dots-in-evaluation-metric-labels-ab5caab19d52d3e1.yaml @@ -0,0 +1,4 @@ +fixes: + - | + LLM Observability: This fix resolves an issue where evaluation-metric labels containing dots could be interpreted as nested objects by adding validation that rejects such labels and provides a clear error message instructing users to use alternative naming conventions. + diff --git a/tests/llmobs/test_llmobs_service.py b/tests/llmobs/test_llmobs_service.py index ccd70167fb7..da6f419faf9 100644 --- a/tests/llmobs/test_llmobs_service.py +++ b/tests/llmobs/test_llmobs_service.py @@ -1630,6 +1630,13 @@ def test_submit_evaluation_empty_label_raises_error(llmobs, mock_llmobs_logs): ) +def test_submit_evaluation_label_value_with_a_period_raises_error(llmobs, mock_llmobs_logs): + with pytest.raises(ValueError, match="label value must not contain a '.'."): + llmobs.submit_evaluation( + span={"span_id": "123", "trace_id": "456"}, label="toxicity.0", metric_type="categorical", value="high" + ) + + def test_submit_evaluation_incorrect_metric_type_raises_error(llmobs, mock_llmobs_logs): with pytest.raises(ValueError, match="metric_type must be one of 'categorical', 'score', or 'boolean'."): llmobs.submit_evaluation(