Skip to content

Commit 26a6db5

Browse files
authored
fix(llmobs): improve serialization defaults for pydantic models [backport 3.2] (#12767)
Backport cf86284 from #12635 to 3.2. [MLOB-2314] Cherry-pick from @helmus' fix in #12617, only additions are tests and release note. Thanks @helmus for the contribution! This PR improves our serialization defaults for non-JSON serializable objects, primarily pydantic models and enum/sentinel classes. - pydantic models are not JSON serializable directly, but have a `model_dump()` method which converts the object into a json serializable representation. We'll account for this in our serialization logic, although there is a small risk that a non-pydantic object also implements `model_dump()` without being json-serializable. However this should still be caught in our non-serializable default code. - enum/sentinel classes (like OpenAI's `NOT_GIVEN` [class](https://github.com/openai/openai-python/blob/main/src/openai/_types.py#L133)) are not JSON serializable but usually have a str/repr implementation. We'll try converting the object to a string first before defaulting to our placeholder (`[Unserializable object: <repr(obj)>]`). Note: this PR does not introduce a library dependency, only adds a testing dependency on `Pydantic`. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) [MLOB-2314]: https://datadoghq.atlassian.net/browse/MLOB-2314?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent f44f52e commit 26a6db5

File tree

11 files changed

+314
-245
lines changed

11 files changed

+314
-245
lines changed

.riot/requirements/12c5529.txt

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,85 +2,85 @@
22
# This file is autogenerated by pip-compile with Python 3.10
33
# by the following command:
44
#
5-
# pip-compile --no-annotate .riot/requirements/12c5529.in
5+
# pip-compile --allow-unsafe --no-annotate .riot/requirements/12c5529.in
66
#
7-
aiohappyeyeballs==2.4.3
8-
aiohttp==3.10.10
9-
aiosignal==1.3.1
7+
aiohappyeyeballs==2.4.8
8+
aiohttp==3.11.13
9+
aiosignal==1.3.2
1010
annotated-types==0.7.0
11-
anyio==4.6.2.post1
11+
anyio==4.8.0
1212
appdirs==1.4.4
1313
async-timeout==4.0.3
14-
attrs==24.2.0
15-
certifi==2024.8.30
16-
charset-normalizer==3.4.0
17-
coverage[toml]==7.6.3
14+
attrs==25.1.0
15+
certifi==2025.1.31
16+
charset-normalizer==3.4.1
17+
coverage[toml]==7.6.12
1818
dataclasses-json==0.6.7
19-
datasets==3.0.1
19+
datasets==3.3.2
2020
dill==0.3.8
2121
distro==1.9.0
2222
exceptiongroup==1.2.2
23-
filelock==3.16.1
24-
frozenlist==1.4.1
25-
fsspec[http]==2024.6.1
23+
filelock==3.17.0
24+
frozenlist==1.5.0
25+
fsspec[http]==2024.12.0
2626
h11==0.14.0
27-
httpcore==1.0.6
28-
httpx==0.27.2
29-
huggingface-hub==0.26.0
27+
httpcore==1.0.7
28+
httpx==0.28.1
29+
huggingface-hub==0.29.2
3030
hypothesis==6.45.0
3131
idna==3.10
3232
iniconfig==2.0.0
33-
jiter==0.6.1
33+
jiter==0.8.2
3434
jsonpatch==1.33
3535
jsonpointer==3.0.0
36-
langchain==0.2.16
37-
langchain-community==0.2.17
38-
langchain-core==0.2.41
36+
langchain==0.2.17
37+
langchain-community==0.2.19
38+
langchain-core==0.2.43
3939
langchain-openai==0.1.25
4040
langchain-text-splitters==0.2.4
41-
langsmith==0.1.136
42-
marshmallow==3.23.0
43-
mock==5.1.0
41+
langsmith==0.1.147
42+
marshmallow==3.26.1
43+
mock==5.2.0
4444
multidict==6.1.0
4545
multiprocess==0.70.16
4646
mypy-extensions==1.0.0
4747
nest-asyncio==1.6.0
4848
numpy==1.26.4
49-
openai==1.52.0
49+
openai==1.65.3
5050
opentracing==2.4.0
51-
orjson==3.10.7
52-
packaging==24.1
51+
orjson==3.10.15
52+
packaging==24.2
5353
pandas==2.2.3
5454
pluggy==1.5.0
55-
propcache==0.2.0
56-
pyarrow==17.0.0
57-
pydantic==2.9.2
58-
pydantic-core==2.23.4
55+
propcache==0.3.0
56+
pyarrow==19.0.1
57+
pydantic==2.10.6
58+
pydantic-core==2.27.2
5959
pysbd==0.3.4
60-
pytest==8.3.3
60+
pytest==8.3.5
6161
pytest-asyncio==0.21.1
62-
pytest-cov==5.0.0
62+
pytest-cov==6.0.0
6363
pytest-mock==3.14.0
6464
python-dateutil==2.9.0.post0
65-
pytz==2024.2
65+
pytz==2025.1
6666
pyyaml==6.0.2
6767
ragas==0.1.21
68-
regex==2024.9.11
68+
regex==2024.11.6
6969
requests==2.32.3
7070
requests-toolbelt==1.0.0
71-
six==1.16.0
71+
six==1.17.0
7272
sniffio==1.3.1
7373
sortedcontainers==2.4.0
74-
sqlalchemy==2.0.36
74+
sqlalchemy==2.0.38
7575
tenacity==8.5.0
76-
tiktoken==0.8.0
77-
tomli==2.0.2
78-
tqdm==4.66.5
76+
tiktoken==0.9.0
77+
tomli==2.2.1
78+
tqdm==4.67.1
7979
typing-extensions==4.12.2
8080
typing-inspect==0.9.0
81-
tzdata==2024.2
82-
urllib3==2.2.3
83-
vcrpy==6.0.2
84-
wrapt==1.16.0
81+
tzdata==2025.1
82+
urllib3==2.3.0
83+
vcrpy==7.0.0
84+
wrapt==1.17.2
8585
xxhash==3.5.0
86-
yarl==1.15.5
86+
yarl==1.18.3

.riot/requirements/146f2d8.txt

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,85 +2,85 @@
22
# This file is autogenerated by pip-compile with Python 3.8
33
# by the following command:
44
#
5-
# pip-compile --no-annotate .riot/requirements/146f2d8.in
5+
# pip-compile --allow-unsafe --no-annotate --resolver=backtracking .riot/requirements/146f2d8.in
66
#
7-
aiohappyeyeballs==2.4.3
8-
aiohttp==3.10.10
7+
aiohappyeyeballs==2.4.4
8+
aiohttp==3.10.11
99
aiosignal==1.3.1
1010
annotated-types==0.7.0
1111
anyio==4.5.2
1212
appdirs==1.4.4
1313
async-timeout==4.0.3
14-
attrs==24.2.0
15-
certifi==2024.8.30
16-
charset-normalizer==3.4.0
14+
attrs==25.1.0
15+
certifi==2025.1.31
16+
charset-normalizer==3.4.1
1717
coverage[toml]==7.6.1
1818
dataclasses-json==0.6.7
19-
datasets==3.0.1
19+
datasets==3.1.0
2020
dill==0.3.8
2121
distro==1.9.0
2222
exceptiongroup==1.2.2
2323
filelock==3.16.1
24-
frozenlist==1.4.1
25-
fsspec[http]==2024.6.1
24+
frozenlist==1.5.0
25+
fsspec[http]==2024.9.0
2626
h11==0.14.0
27-
httpcore==1.0.6
28-
httpx==0.27.2
29-
huggingface-hub==0.26.0
27+
httpcore==1.0.7
28+
httpx==0.28.1
29+
huggingface-hub==0.29.2
3030
hypothesis==6.45.0
3131
idna==3.10
3232
iniconfig==2.0.0
33-
jiter==0.6.1
33+
jiter==0.8.2
3434
jsonpatch==1.33
3535
jsonpointer==3.0.0
36-
langchain==0.2.16
37-
langchain-community==0.2.17
38-
langchain-core==0.2.41
36+
langchain==0.2.17
37+
langchain-community==0.2.19
38+
langchain-core==0.2.43
3939
langchain-openai==0.1.25
4040
langchain-text-splitters==0.2.4
41-
langsmith==0.1.136
41+
langsmith==0.1.147
4242
marshmallow==3.22.0
43-
mock==5.1.0
43+
mock==5.2.0
4444
multidict==6.1.0
4545
multiprocess==0.70.16
4646
mypy-extensions==1.0.0
4747
nest-asyncio==1.6.0
4848
numpy==1.24.4
49-
openai==1.52.0
49+
openai==1.65.3
5050
opentracing==2.4.0
51-
orjson==3.10.7
52-
packaging==24.1
51+
orjson==3.10.15
52+
packaging==24.2
5353
pandas==2.0.3
5454
pluggy==1.5.0
5555
propcache==0.2.0
5656
pyarrow==17.0.0
57-
pydantic==2.9.2
58-
pydantic-core==2.23.4
57+
pydantic==2.10.6
58+
pydantic-core==2.27.2
5959
pysbd==0.3.4
60-
pytest==8.3.3
60+
pytest==8.3.5
6161
pytest-asyncio==0.21.1
6262
pytest-cov==5.0.0
6363
pytest-mock==3.14.0
6464
python-dateutil==2.9.0.post0
65-
pytz==2024.2
65+
pytz==2025.1
6666
pyyaml==6.0.2
6767
ragas==0.1.21
68-
regex==2024.9.11
68+
regex==2024.11.6
6969
requests==2.32.3
7070
requests-toolbelt==1.0.0
71-
six==1.16.0
71+
six==1.17.0
7272
sniffio==1.3.1
7373
sortedcontainers==2.4.0
74-
sqlalchemy==2.0.36
74+
sqlalchemy==2.0.38
7575
tenacity==8.5.0
7676
tiktoken==0.7.0
77-
tomli==2.0.2
78-
tqdm==4.66.5
77+
tomli==2.2.1
78+
tqdm==4.67.1
7979
typing-extensions==4.12.2
8080
typing-inspect==0.9.0
81-
tzdata==2024.2
81+
tzdata==2025.1
8282
urllib3==1.26.20
8383
vcrpy==6.0.2
84-
wrapt==1.16.0
84+
wrapt==1.17.2
8585
xxhash==3.5.0
8686
yarl==1.15.2

.riot/requirements/1687eab.txt

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,82 +2,82 @@
22
# This file is autogenerated by pip-compile with Python 3.11
33
# by the following command:
44
#
5-
# pip-compile --no-annotate .riot/requirements/1687eab.in
5+
# pip-compile --allow-unsafe --no-annotate --resolver=backtracking .riot/requirements/1687eab.in
66
#
7-
aiohappyeyeballs==2.4.3
8-
aiohttp==3.10.10
9-
aiosignal==1.3.1
7+
aiohappyeyeballs==2.4.8
8+
aiohttp==3.11.13
9+
aiosignal==1.3.2
1010
annotated-types==0.7.0
11-
anyio==4.6.2.post1
11+
anyio==4.8.0
1212
appdirs==1.4.4
13-
attrs==24.2.0
14-
certifi==2024.8.30
15-
charset-normalizer==3.4.0
16-
coverage[toml]==7.6.3
13+
attrs==25.1.0
14+
certifi==2025.1.31
15+
charset-normalizer==3.4.1
16+
coverage[toml]==7.6.12
1717
dataclasses-json==0.6.7
18-
datasets==3.0.1
18+
datasets==3.3.2
1919
dill==0.3.8
2020
distro==1.9.0
21-
filelock==3.16.1
22-
frozenlist==1.4.1
23-
fsspec[http]==2024.6.1
21+
filelock==3.17.0
22+
frozenlist==1.5.0
23+
fsspec[http]==2024.12.0
2424
h11==0.14.0
25-
httpcore==1.0.6
26-
httpx==0.27.2
27-
huggingface-hub==0.26.0
25+
httpcore==1.0.7
26+
httpx==0.28.1
27+
huggingface-hub==0.29.2
2828
hypothesis==6.45.0
2929
idna==3.10
3030
iniconfig==2.0.0
31-
jiter==0.6.1
31+
jiter==0.8.2
3232
jsonpatch==1.33
3333
jsonpointer==3.0.0
34-
langchain==0.2.16
35-
langchain-community==0.2.17
36-
langchain-core==0.2.41
34+
langchain==0.2.17
35+
langchain-community==0.2.19
36+
langchain-core==0.2.43
3737
langchain-openai==0.1.25
3838
langchain-text-splitters==0.2.4
39-
langsmith==0.1.136
40-
marshmallow==3.23.0
41-
mock==5.1.0
39+
langsmith==0.1.147
40+
marshmallow==3.26.1
41+
mock==5.2.0
4242
multidict==6.1.0
4343
multiprocess==0.70.16
4444
mypy-extensions==1.0.0
4545
nest-asyncio==1.6.0
4646
numpy==1.26.4
47-
openai==1.52.0
47+
openai==1.65.3
4848
opentracing==2.4.0
49-
orjson==3.10.7
50-
packaging==24.1
49+
orjson==3.10.15
50+
packaging==24.2
5151
pandas==2.2.3
5252
pluggy==1.5.0
53-
propcache==0.2.0
54-
pyarrow==17.0.0
55-
pydantic==2.9.2
56-
pydantic-core==2.23.4
53+
propcache==0.3.0
54+
pyarrow==19.0.1
55+
pydantic==2.10.6
56+
pydantic-core==2.27.2
5757
pysbd==0.3.4
58-
pytest==8.3.3
58+
pytest==8.3.5
5959
pytest-asyncio==0.21.1
60-
pytest-cov==5.0.0
60+
pytest-cov==6.0.0
6161
pytest-mock==3.14.0
6262
python-dateutil==2.9.0.post0
63-
pytz==2024.2
63+
pytz==2025.1
6464
pyyaml==6.0.2
6565
ragas==0.1.21
66-
regex==2024.9.11
66+
regex==2024.11.6
6767
requests==2.32.3
6868
requests-toolbelt==1.0.0
69-
six==1.16.0
69+
six==1.17.0
7070
sniffio==1.3.1
7171
sortedcontainers==2.4.0
72-
sqlalchemy==2.0.36
72+
sqlalchemy==2.0.38
7373
tenacity==8.5.0
74-
tiktoken==0.8.0
75-
tqdm==4.66.5
74+
tiktoken==0.9.0
75+
tqdm==4.67.1
7676
typing-extensions==4.12.2
7777
typing-inspect==0.9.0
78-
tzdata==2024.2
79-
urllib3==2.2.3
80-
vcrpy==6.0.2
81-
wrapt==1.16.0
78+
tzdata==2025.1
79+
urllib3==2.3.0
80+
vcrpy==7.0.0
81+
wrapt==1.17.2
8282
xxhash==3.5.0
83-
yarl==1.15.5
83+
yarl==1.18.3

0 commit comments

Comments
 (0)