langfuse-python icon indicating copy to clipboard operation
langfuse-python copied to clipboard

Fix Error: TypeError: Object of type object is not JSON serializable

Open Huarong opened this issue 1 year ago • 2 comments

Make json dump more robust. Support object type. Fix the error like this, which occur in using langraph.

  File "/Users/huohuarong/.pyenv/versions/3.11.2/lib/python3.11/json/encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           │           └ {'id': 'd4b690a2-78b9-4bc3-bda0-98e5e6c62366', 'type': 'span-update', 'body': {'output': <object object at 0x120809540>, 'id'...
           └ <_json.Encoder object at 0x1253fa080>
  File "/Users/huohuarong/llm/doctorgpt/.venv/lib/python3.11/site-packages/langfuse/serializer.py", line 55, in default
    return JSONEncoder.default(self, obj)
           │           │       │     └ <object object at 0x120809540>
           │           │       └ <langfuse.serializer.EventSerializer object at 0x1253b3050>
           │           └ <function JSONEncoder.default at 0x101e6d580>
           └ <class 'json.encoder.JSONEncoder'>
  File "/Users/huohuarong/.pyenv/versions/3.11.2/lib/python3.11/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '

TypeError: Object of type object is not JSON serializable

Huarong avatar Mar 07 '24 03:03 Huarong

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Mar 07 '24 03:03 CLAassistant

@Huarong thanks for the change. Unfortunately, the string representation of an object would not really be helpful, as our users would see the object name and the memory address in the UI. Do you know which type of object langraph is trying to send here? Do you mind sharing your graph with us?

maxdeichmann avatar Mar 18 '24 13:03 maxdeichmann

Thanks for your contribution, this should be already fixed on main by now 🙏🏾

hassiebp avatar Oct 10 '24 16:10 hassiebp