replace inefficient use of to_jsonable_python (#545)

This commit is contained in:
Samuel Colvin 2025-04-26 11:41:19 -07:00 • committed by GitHub
commit 697b6e8e05
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,7 +3,6 @@
from __future__ import annotations as _annotations
import inspect
import json
import re
from collections.abc import AsyncIterator, Callable, Iterable, Sequence
from contextlib import (
@ -551,10 +550,7 @@ def _convert_to_content(
return list(chain.from_iterable(_convert_to_content(item) for item in result)) # type: ignore[reportUnknownVariableType]
if not isinstance(result, str):
try:
result = json.dumps(pydantic_core.to_jsonable_python(result))
except Exception:
result = str(result)
result = pydantic_core.to_json(result, fallback=str, indent=2).decode()
return [TextContent(type="text", text=result)]