Skip to content

Commit 7a9e93a

Browse files
committed
fix(client): apply mask to dataset and score payloads
1 parent f332185 commit 7a9e93a

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

‎langfuse/_client/client.py‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,20 @@ def create_score(
19491949
environment: Optional[str] = None,
19501950
) -> None: ...
19511951

1952+
def _apply_mask(self, data: Any) -> Any:
1953+
"""Apply the configured mask to data sent outside a span, matching span masking."""
1954+
if data is None or not self._mask:
1955+
return data
1956+
try:
1957+
return self._mask(data=data)
1958+
except Exception as e:
1959+
langfuse_logger.error(
1960+
"Masking error: Custom mask function threw exception when processing "
1961+
"data. Using fallback masking. Error: %s",
1962+
e,
1963+
)
1964+
return "<fully masked due to failed mask function>"
1965+
19521966
def create_score(
19531967
self,
19541968
*,
@@ -2029,7 +2043,7 @@ def create_score(
20292043
name=name,
20302044
value=value,
20312045
dataType=data_type, # type: ignore
2032-
comment=comment,
2046+
comment=self._apply_mask(comment),
20332047
configId=config_id,
20342048
environment=environment or self._environment,
20352049
metadata=metadata,
@@ -3550,7 +3564,7 @@ def create_dataset(
35503564
result = self.api.datasets.create(
35513565
name=name,
35523566
description=description,
3553-
metadata=metadata,
3567+
metadata=self._apply_mask(metadata),
35543568
input_schema=input_schema,
35553569
expected_output_schema=expected_output_schema,
35563570
)
@@ -3649,9 +3663,9 @@ def create_dataset_item(
36493663

36503664
result = self.api.dataset_items.create(
36513665
dataset_name=dataset_name,
3652-
input=input,
3653-
expected_output=expected_output,
3654-
metadata=metadata,
3666+
input=self._apply_mask(input),
3667+
expected_output=self._apply_mask(expected_output),
3668+
metadata=self._apply_mask(metadata),
36553669
source_trace_id=source_trace_id,
36563670
source_observation_id=source_observation_id,
36573671
status=status,

0 commit comments

Comments
 (0)