You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When max_retries is set as a Tenacity Retrying object, Type Error: Object of type Retrying is not JSON serializable is raised by _wrapper.py (line 160)
To Reproduce
Assign max_retries as a Retrying object as seen here in the Instructor docs.
Expected behavior
Retrying object to be excluded from SpanAttributes.LLM_INVOCATION_PARAMETERS so the Type Error is not raised.
Desktop (please complete the following information):
OS: MacOS
Version 15.1.1
Python: 3.13
Additional context
Example code:
import instructor
from openai import OpenAI
from pydantic import BaseModel
from tenacity import Retrying, stop_after_attempt, wait_fixed
client = instructor.from_openai(OpenAI())
class UserInfo(BaseModel):
name: str
age: int
response = client.chat.completions.create(
model="gpt-4o-mini",
response_model=UserInfo,
messages=[
{"role": "user", "content": "John Doe is 30 years old."},
],
max_retries=Retrying(
stop=stop_after_attempt(2),
wait=wait_fixed(1),
)
)
The text was updated successfully, but these errors were encountered:
Hello @peterhollis! I'm Dosu, your friendly bot here to help you tackle bugs, answer questions, and support your journey to becoming a contributor. I'll be around while you wait for a human maintainer. How can I assist you today?
The issue you're encountering is due to the Retrying object from Tenacity not being JSON serializable, which causes a TypeError when it's included in SpanAttributes.LLM_INVOCATION_PARAMETERS. The _wrapper.py file currently does not have a mechanism to exclude specific types like Retrying from serialization [1].
To resolve this, you could modify the serialization logic to exclude or handle the Retrying object specifically. One approach is to update the safe_json_dumps function or the SafeJSONEncoder class to check for instances of Retrying and handle them accordingly, such as by converting them to a string representation or excluding them from the serialization process. This would prevent the TypeError from being raised.
Describe the bug
When
max_retries
is set as a TenacityRetrying
object,Type Error: Object of type Retrying is not JSON serializable
is raised by _wrapper.py (line 160)To Reproduce
Assign
max_retries
as aRetrying
object as seen here in the Instructor docs.Expected behavior
Retrying object to be excluded from
SpanAttributes.LLM_INVOCATION_PARAMETERS
so the Type Error is not raised.Desktop (please complete the following information):
Additional context
Example code:
The text was updated successfully, but these errors were encountered: