Skip to content

fix(instrumentation): serialize pydantic model attributes in json mode#2813

Merged
axiomofjoy merged 3 commits intoArize-ai:mainfrom
raphaeldiasmonteiro:fix/pydantic-models-json-dict-keys
Apr 23, 2026
Merged

fix(instrumentation): serialize pydantic model attributes in json mode#2813
axiomofjoy merged 3 commits intoArize-ai:mainfrom
raphaeldiasmonteiro:fix/pydantic-models-json-dict-keys

Conversation

@raphaeldiasmonteiro
Copy link
Copy Markdown
Contributor

@raphaeldiasmonteiro raphaeldiasmonteiro commented Feb 27, 2026

Pydantic models with non-JSON dict keys (for example Enum / UUID) can fail in _json_serialize with:

TypeError: keys must be str, int, float, bool or None, not ...

Switch Pydantic serialization in _attributes.py from model_dump() to model_dump(mode="json") so output is JSON-compatible before json.dumps.


Note

Medium Risk
Changes how Pydantic models are converted before json.dumps, which can slightly alter emitted attribute payloads and affect downstream consumers expecting the previous representation.

Overview
Fixes _json_serialize for Pydantic BaseModel inputs by using model_dump(mode="json") so non-JSON dict keys (e.g., Enum, UUID) are coerced into JSON-compatible keys before encoding.

Adds a unit test covering serialization of a Pydantic model with mixed key types to prevent regressions.

Written by Cursor Bugbot for commit 65d5dae. This will update automatically on new commits. Configure here.

@raphaeldiasmonteiro raphaeldiasmonteiro requested a review from a team as a code owner February 27, 2026 10:29
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Feb 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 27, 2026

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@raphaeldiasmonteiro
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Feb 27, 2026
@caroger caroger requested review from axiomofjoy and caroger March 11, 2026 06:44
raphaeldiasmonteiro and others added 3 commits March 26, 2026 15:44
Replace test_attributes.py (which tested the private _json_serialize
helper) with a test in test_manual_instrumentation.py that exercises
get_output_attributes, the public-facing function.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@axiomofjoy axiomofjoy force-pushed the fix/pydantic-models-json-dict-keys branch from ac040fa to f63aee2 Compare March 26, 2026 19:44
@axiomofjoy axiomofjoy merged commit ee13799 into Arize-ai:main Apr 23, 2026
135 checks passed
@mikeldking mikeldking mentioned this pull request Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants