The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
add safe_dumps
Ishaan Jaffereec76cbe4905
diff --git a/litellm/litellm_core_utils/safe_json_dumps.py b/litellm/litellm_core_utils/safe_json_dumps.pyindex bd3bcc97974..8b50e41a795 100644--- a/litellm/litellm_core_utils/safe_json_dumps.py+++ b/litellm/litellm_core_utils/safe_json_dumps.py@@ -42,28 +42,11 @@ def safe_dumps(data: Any, max_depth: int = DEFAULT_MAX_RECURSE_DEPTH) -> str:seen.remove(id(obj))return resultelse:- # Check if object is a Pydantic model and convert to dict- if hasattr(obj, "model_dump"):- # Pydantic v2- try:- seen.remove(id(obj))- return _serialize(obj.model_dump(), seen, depth)- except Exception:- pass- elif hasattr(obj, "dict"):- # Pydantic v1- try:- seen.remove(id(obj))- return _serialize(obj.dict(), seen, depth)- except Exception:- pass-# Fall back to string conversion for non-serializable objects.try:- seen.remove(id(obj))return str(obj)except Exception:return "Unserializable Object"safe_data = _serialize(data, set(), 0)- return json.dumps(safe_data, default=str)+ return json.dumps(safe_data, default=str)\ No newline at end of file