Skip to content

Commit 138072a

Browse files
fix(llmobs): prevent dots in evaluation metric labels
EVP interprets dots as nested objects (e.g., "field.1" becomes {field: {1: value}}), causing confusion for customers submitting custom evaluations with dots in label names. Add validation to reject labels containing dots and raise a clear error message directing users to use alternative naming conventions.
1 parent f7999ce commit 138072a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

ddtrace/llmobs/_llmobs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,10 @@ def submit_evaluation(
16851685
error = "invalid_metric_label"
16861686
raise ValueError("label must be the specified name of the evaluation metric.")
16871687

1688+
if "." in label:
1689+
error = "invalid_label_value"
1690+
raise ValueError("label value must not contain a '.'.")
1691+
16881692
metric_type = metric_type.lower()
16891693
if metric_type not in ("categorical", "score", "boolean"):
16901694
error = "invalid_metric_type"

tests/llmobs/test_llmobs_service.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,13 @@ def test_submit_evaluation_empty_label_raises_error(llmobs, mock_llmobs_logs):
16301630
)
16311631

16321632

1633+
def test_submit_evaluation_label_value_with_a_period_raises_error(llmobs, mock_llmobs_logs):
1634+
with pytest.raises(ValueError, match="label value must not contain a '.'."):
1635+
llmobs.submit_evaluation(
1636+
span={"span_id": "123", "trace_id": "456"}, label="toxicity.0", metric_type="categorical", value="high"
1637+
)
1638+
1639+
16331640
def test_submit_evaluation_incorrect_metric_type_raises_error(llmobs, mock_llmobs_logs):
16341641
with pytest.raises(ValueError, match="metric_type must be one of 'categorical', 'score', or 'boolean'."):
16351642
llmobs.submit_evaluation(

0 commit comments

Comments
 (0)