Skip to content

Commit c178cb9

Browse files
committed
Merge branch 'richard/fix-braintrust-tracing-data-mask' into richard/simple-agent
2 parents ad1bcfa + 09381a4 commit c178cb9

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

backend/onyx/evals/tracing.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@
77
from onyx.configs.app_configs import BRAINTRUST_API_KEY
88
from onyx.configs.app_configs import BRAINTRUST_PROJECT
99

10+
MASKING_LENGTH = 20000
1011

11-
def _truncate_str(s: str, head: int = 800, tail: int = 200) -> str:
12-
if len(s) <= head + tail:
13-
return s
14-
return f"{s[:head]}{s[-tail:]}[TRUNCATED {len(s)} chars to 10,000]"
12+
13+
def _truncate_str(s: str) -> str:
14+
tail = MASKING_LENGTH // 5
15+
head = MASKING_LENGTH - tail
16+
return f"{s[:head]}{s[-tail:]}[TRUNCATED {len(s)} chars to {MASKING_LENGTH}]"
17+
18+
19+
def _should_mask(data: Any) -> bool:
20+
return len(str(data)) > MASKING_LENGTH
1521

1622

1723
def _mask(data: Any) -> Any:
18-
data_str = str(data)
19-
if len(data_str) > 10_000:
20-
return _truncate_str(data_str)
21-
return data
24+
"""Mask data if it exceeds the maximum length threshold."""
25+
if not _should_mask(data):
26+
return data
27+
return _truncate_str(str(data))
2228

2329

2430
def setup_braintrust() -> None:

0 commit comments

Comments
 (0)