fix: fix Chinese character escaping issue #1330
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add the ensure_ascii=False parameter to all json.dumps calls to ensure non-ASCII characters (such as Chinese) are not escaped into \uXXXX format.
Files to modify:
langfuse/_client/attributes.py: Core serialization functions
langfuse/_utils/request.py: API request data serialization
langfuse/_client/utils.py: Debug output formatting
langfuse/_task_manager/score_ingestion_consumer.py: Score processing serialization
Before Fix & After Fix:

Important
Add
ensure_ascii=False
tojson.dumps
calls to prevent non-ASCII character escaping in multiple files.ensure_ascii=False
tojson.dumps
inattributes.py
for core serialization functions.ensure_ascii=False
tojson.dumps
inrequest.py
for API request data serialization.ensure_ascii=False
tojson.dumps
inutils.py
for debug output formatting.ensure_ascii=False
tojson.dumps
inscore_ingestion_consumer.py
for score processing serialization.This description was created by
for 843ed96. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Summary
Updated On: 2025-09-09 06:09:40 UTC
This PR addresses a localization issue where non-ASCII characters (specifically Chinese characters) were being escaped to \uXXXX format in JSON serialization throughout the Langfuse Python SDK. The fix adds the
ensure_ascii=False
parameter to alljson.dumps()
calls across four key files to preserve Unicode characters in their original readable form.The changes affect multiple serialization touchpoints:
All modified files use the existing
EventSerializer
class but now explicitly disable ASCII-only encoding. This ensures that when users trace LLM applications containing Chinese text (or other Unicode content), the data remains human-readable in the Langfuse UI, logs, and debug output. The change maintains JSON validity while improving the user experience for international developers.Confidence score: 5/5
ensure_ascii=False
parameter