Skip to content

Commit aae4ea4

Browse files
committed
fix(client): serialize non-string masked score comments
1 parent 041ce37 commit aae4ea4

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎langfuse/_client/client.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55

66
import asyncio
7+
import json
78
import logging
89
import os
910
import re
@@ -2032,6 +2033,9 @@ def create_score(
20322033
return
20332034

20342035
score_id = score_id or self._create_observation_id()
2036+
comment = self._apply_mask(comment)
2037+
if comment is not None and not isinstance(comment, str):
2038+
comment = json.dumps(comment)
20352039

20362040
try:
20372041
new_body = ScoreBody(
@@ -2043,7 +2047,7 @@ def create_score(
20432047
name=name,
20442048
value=value,
20452049
dataType=data_type, # type: ignore
2046-
comment=self._apply_mask(comment),
2050+
comment=comment,
20472051
configId=config_id,
20482052
environment=environment or self._environment,
20492053
metadata=metadata,

‎tests/unit/test_mask_api_payloads.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,12 @@ def test_create_score_masks_comment():
4242
assert (
4343
client._resources.add_score_task.call_args.args[0]["body"].comment == "masked"
4444
)
45+
46+
47+
def test_create_score_serializes_non_string_masked_comment():
48+
client = _client()
49+
client._tracing_enabled = True
50+
client._mask = lambda data: {"redacted": True}
51+
client.create_score(name="s", value=1, trace_id="t" * 32, comment="secret")
52+
body = client._resources.add_score_task.call_args.args[0]["body"]
53+
assert body.comment == '{"redacted": true}'

0 commit comments

Comments
 (0)