Skip to content

Commit 5b3c754

Browse files
committed
Make _normalize_data deal with model_dump() returning functions or classes
1 parent 5d68744 commit 5b3c754

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

sentry_sdk/ai/utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,21 @@
1111

1212
def _normalize_data(data, unpack=True):
1313
# type: (Any, bool) -> Any
14-
1514
# convert pydantic data (e.g. OpenAI v1+) to json compatible format
1615
if hasattr(data, "model_dump"):
1716
try:
18-
return data.model_dump()
17+
return _normalize_data(data.model_dump(), unpack=unpack)
1918
except Exception as e:
2019
logger.warning("Could not convert pydantic data to JSON: %s", e)
21-
return data
20+
return data if isinstance(data, (int, float, bool, str)) else str(data)
2221
if isinstance(data, list):
2322
if unpack and len(data) == 1:
2423
return _normalize_data(data[0], unpack=unpack) # remove empty dimensions
2524
return list(_normalize_data(x, unpack=unpack) for x in data)
2625
if isinstance(data, dict):
2726
return {k: _normalize_data(v, unpack=unpack) for (k, v) in data.items()}
2827

29-
return data
28+
return data if isinstance(data, (int, float, bool, str)) else str(data)
3029

3130

3231
def set_data_normalized(span, key, value, unpack=True):

0 commit comments

Comments
 (0)