braintrust 0.3.10__py3-none-any.whl → 0.3.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,6 @@ from pathlib import Path
4
4
  from typing import Any
5
5
 
6
6
  import pytest
7
-
8
7
  from braintrust.framework import _evals
9
8
  from braintrust.test_helpers import has_devserver_installed
10
9
 
@@ -28,9 +27,8 @@ def client():
28
27
  pytest.skip("Devserver dependencies not installed (requires .[cli])")
29
28
 
30
29
  # Import CLI dependencies inside the fixture
31
- from starlette.testclient import TestClient
32
-
33
30
  from braintrust.devserver.server import create_app
31
+ from starlette.testclient import TestClient
34
32
 
35
33
  # Use the real simple_eval.py example
36
34
  eval_file = Path(__file__).parent.parent.parent.parent / "examples" / "evals" / "simple_eval.py"
@@ -39,8 +37,8 @@ def client():
39
37
  _evals.clear()
40
38
 
41
39
  # Load the eval file to register evaluators (but don't run them)
42
- spec = __import__('importlib.util').util.spec_from_file_location("simple_eval", str(eval_file))
43
- module = __import__('importlib.util').util.module_from_spec(spec)
40
+ spec = __import__("importlib.util").util.spec_from_file_location("simple_eval", str(eval_file))
41
+ module = __import__("importlib.util").util.module_from_spec(spec)
44
42
 
45
43
  # Get evaluators from the module without executing Eval()
46
44
  # We need to parse the file and extract the Evaluator definition
@@ -134,6 +132,7 @@ def parse_sse_events(response_text: str) -> list[dict[str, Any]]:
134
132
  return events
135
133
 
136
134
 
135
+ @pytest.mark.skip
137
136
  @pytest.mark.vcr
138
137
  def test_eval_sse_streaming(client, api_key, org_name):
139
138
  """
braintrust/oai.py CHANGED
@@ -845,7 +845,7 @@ def _parse_metrics_from_usage(usage: Any) -> Dict[str, Any]:
845
845
 
846
846
 
847
847
  def _is_numeric(v):
848
- return isinstance(v, (int, float, complex))
848
+ return isinstance(v, (int, float, complex)) and not isinstance(v, bool)
849
849
 
850
850
 
851
851
  def prettify_params(params: Dict[str, Any]) -> Dict[str, Any]:
braintrust/version.py CHANGED
@@ -1,4 +1,4 @@
1
- VERSION = "0.3.10"
1
+ VERSION = "0.3.11"
2
2
 
3
3
  # this will be templated during the build
4
- GIT_COMMIT = "160c352d87c121ef1ea43e49831453b9e8d4d0f8"
4
+ GIT_COMMIT = "7cffe54f8b960931055ae20f5983b4ea34515eff"
@@ -1690,3 +1690,35 @@ def test_braintrust_tracing_processor_trace_metadata_logging(memory_logger):
1690
1690
  spans = memory_logger.pop()
1691
1691
  root_span = spans[0]
1692
1692
  assert root_span["metadata"]["conversation_id"] == "test-12345", "Should log trace metadata"
1693
+
1694
+
1695
+ def test_parse_metrics_excludes_booleans():
1696
+ """Test that boolean fields in usage objects are excluded from metrics.
1697
+
1698
+ Reproduces issue where OpenRouter returns is_byok (a boolean) in the usage
1699
+ object, which caused API validation errors: "Expected number, received boolean".
1700
+
1701
+ In Python, bool is a subclass of int, so isinstance(True, int) returns True.
1702
+ The fix ensures _is_numeric explicitly excludes booleans.
1703
+ """
1704
+ from braintrust.oai import _parse_metrics_from_usage
1705
+
1706
+ # Simulate OpenRouter's usage object with boolean field
1707
+ usage = {
1708
+ "completion_tokens": 11,
1709
+ "prompt_tokens": 8,
1710
+ "total_tokens": 19,
1711
+ "cost": 0.000104,
1712
+ "is_byok": False, # This boolean should be filtered out
1713
+ }
1714
+
1715
+ metrics = _parse_metrics_from_usage(usage)
1716
+
1717
+ # Numeric fields should be included
1718
+ assert metrics["completion_tokens"] == 11
1719
+ assert metrics["prompt_tokens"] == 8
1720
+ assert metrics["tokens"] == 19 # total_tokens gets renamed
1721
+ assert metrics["cost"] == 0.000104
1722
+
1723
+ # Boolean field should NOT be in metrics (this was the bug)
1724
+ assert "is_byok" not in metrics
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: braintrust
3
- Version: 0.3.10
3
+ Version: 0.3.11
4
4
  Summary: SDK for integrating Braintrust
5
5
  Home-page: https://www.braintrust.dev
6
6
  Author: Braintrust
@@ -16,7 +16,7 @@ braintrust/http_headers.py,sha256=9ZsDcsAKG04SGowsgchZktD6rG_oSTKWa8QyGUPA4xE,15
16
16
  braintrust/id_gen.py,sha256=PVkz-pS-9AzgmnAgpV-jgOFFo4hfl6e3IP9dVt6FouQ,1595
17
17
  braintrust/logger.py,sha256=qIElwbRqzT_3mrQ1XiS7razFxADjL6775eukwkiIhA0,209333
18
18
  braintrust/merge_row_batch.py,sha256=NX4jRE9uuFB3Z7btrarQp_di84_NGTjvzpJhksn82W8,9882
19
- braintrust/oai.py,sha256=8gUtISG8oIwgMRcFtlfDndzaF_md1Po_4_DFZcH_PkQ,33159
19
+ braintrust/oai.py,sha256=DW_i6bXXDprwZ_uwcdIE25MUxx5y5DDdqr0ucdIWP9I,33187
20
20
  braintrust/object.py,sha256=vYLyYWncsqLD00zffZUJwGTSkcJF9IIXmgIzrx3Np5c,632
21
21
  braintrust/parameters.py,sha256=E1NJGJZ4Qjhp2h4Rghrh4qdE0FiaXLGPapS_iAk8es8,5946
22
22
  braintrust/prompt.py,sha256=c7UR-UeJ8Hf-DGyFRyUxSgXEOkZFhVd9-IhvyPhy1xI,1938
@@ -42,7 +42,7 @@ braintrust/test_span_components.py,sha256=UnF6ZL4k41XZ-CnfbjuqLeK4MZLtHTMdID3CMh
42
42
  braintrust/test_util.py,sha256=gyqe2JspRP7oXlp6ENztZe2fdRTOEMZMKpQi00y1DSc,4538
43
43
  braintrust/test_version.py,sha256=hk5JKjEFbNJ_ONc1VEkqHquflzre34RpFhCEYLTK8iA,1051
44
44
  braintrust/util.py,sha256=Ec6sRkQw5BckGrFjdA4YTyu_2BaKmHh4tWDwAi_ysOw,7227
45
- braintrust/version.py,sha256=SJg7EMz9LRoqG1nnPiMC44laB2sXCOxz83gnpK4Ee5g,118
45
+ braintrust/version.py,sha256=vQReyh_dMfpWVANMPnGfk8BBp3hMUza8lWOySpnsHEg,118
46
46
  braintrust/xact_ids.py,sha256=bdyp88HjlyIkglgLSqYlCYscdSH6EWVyE14sR90Xl1s,658
47
47
  braintrust/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
48
  braintrust/cli/__main__.py,sha256=wCBKHGVmn3IT_yMXk5qfDwyI2SV2gf1tLr0NTxm9T8k,1519
@@ -67,7 +67,7 @@ braintrust/devserver/schemas.py,sha256=q9_I1DoaF5clLmMCkQvpB1DvFhy2GE1dZCumAc0S7
67
67
  braintrust/devserver/server.py,sha256=8lU0WNweoGM9sK8IiKQj4RtnNupKVlNEBZpbcXP07fc,12455
68
68
  braintrust/devserver/test_cached_login.py,sha256=8RxzS3UuBeGx2L5j4mzXSQnJzF7pL0d4AhS3MNzyqi8,3741
69
69
  braintrust/devserver/test_lru_cache.py,sha256=5YYJ5uFj7k4Z4PQQ-UOV7bLP5zBYVo-5jV5_hpthtgM,4164
70
- braintrust/devserver/test_server_integration.py,sha256=Nq6OyEd5UT4VH4XHMRB8cJ2KUXzzHtDeWGGwr4WLsYA,6695
70
+ braintrust/devserver/test_server_integration.py,sha256=ygIYDsTCSqwa_rzQDtdX0mjkXQVy7qyJjntdoCgtjKM,6711
71
71
  braintrust/functions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
72
72
  braintrust/functions/constants.py,sha256=g_EDiSrfCltHr5QaQMQzJ3qy3D29X-11LanDqlicqB0,23
73
73
  braintrust/functions/invoke.py,sha256=IGs_Zz3UbuKJqpg7O1sVcVIOGTD7QfcTXN2Ep83CqUY,8651
@@ -95,7 +95,7 @@ braintrust/wrappers/test_anthropic.py,sha256=tSHAnroaLK1QYhLhhPFAxSDEJUybzffp2o4
95
95
  braintrust/wrappers/test_dspy.py,sha256=x5vXu-NoFFjWGIcvFvXICVsDasQEQzPuSlxgzbHJcwo,1953
96
96
  braintrust/wrappers/test_google_genai.py,sha256=20e4DqLUZmcpVGircj7vN0IxsS5FVjvveqOu0JNZ5jo,17596
97
97
  braintrust/wrappers/test_litellm.py,sha256=sNId6qnbQibT66aB_lsxX_HlaPF6GoMFaawgnF1A2a4,21428
98
- braintrust/wrappers/test_openai.py,sha256=UqKtoIlZlqiLC6x7Rbv9zROgDdE5zvXZObbFMKpmifw,60237
98
+ braintrust/wrappers/test_openai.py,sha256=Wu9iemfl86Bp29apgNBBBxTR3ukWbstpf2o6P_bDKAE,61374
99
99
  braintrust/wrappers/test_pydantic_ai.py,sha256=uqWbk1D8iX3q9qh_Q8PkopNUfPQCBCvOSa4KkpuIqqE,5057
100
100
  braintrust/wrappers/test_utils.py,sha256=Qz7LYG5V0DK2KuTJ_YLGpO_Zr_LJFfJgZX_Ps8tlM_c,505
101
101
  braintrust/wrappers/agno/__init__.py,sha256=V0dnEhu2U0FabyEmwDbWv5x6rP1rdI8z9JLAB_8XuXk,2416
@@ -108,8 +108,8 @@ braintrust/wrappers/claude_agent_sdk/__init__.py,sha256=CSXJWy-z2fHF7h4VJjLSnXJv
108
108
  braintrust/wrappers/claude_agent_sdk/_wrapper.py,sha256=uzElIOwwPmF_Y5fbWcKWEPC8HnSzW7byzpiuVKK0TXE,15613
109
109
  braintrust/wrappers/claude_agent_sdk/test_wrapper.py,sha256=0NmohdECudFvWtc-5PbANtTXzexkkwIJhGbujydDrT8,6826
110
110
  braintrust/wrappers/google_genai/__init__.py,sha256=PGFMuR3c4Gc3SUt24eP7z5AzdS2Dc1uF1d3QPCnLnuo,16018
111
- braintrust-0.3.10.dist-info/METADATA,sha256=hJlOuBcUfgMXQhHh3nPhixLRZjZpcpcu8VX7YCFXNBE,3131
112
- braintrust-0.3.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
113
- braintrust-0.3.10.dist-info/entry_points.txt,sha256=Zpc0_09g5xm8as5jHqqFq7fhwO0xHSNct_TrEMONS7Q,60
114
- braintrust-0.3.10.dist-info/top_level.txt,sha256=hw1-y-UFMf60RzAr8x_eM7SThbIuWfQsQIbVvqSF83A,11
115
- braintrust-0.3.10.dist-info/RECORD,,
111
+ braintrust-0.3.11.dist-info/METADATA,sha256=1oszinC18YZo77yRQKmnesXudHOcX2jGmjAyxpGDEMM,3131
112
+ braintrust-0.3.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
113
+ braintrust-0.3.11.dist-info/entry_points.txt,sha256=Zpc0_09g5xm8as5jHqqFq7fhwO0xHSNct_TrEMONS7Q,60
114
+ braintrust-0.3.11.dist-info/top_level.txt,sha256=hw1-y-UFMf60RzAr8x_eM7SThbIuWfQsQIbVvqSF83A,11
115
+ braintrust-0.3.11.dist-info/RECORD,,