Skip to content

BUG: EventSerializer serializes float('-inf') as "Infinity" instead of "-Infinity" #1682

@devteamaegis

Description

@devteamaegis

What breaks

EventSerializer._default_inner() in langfuse/_utils/serializer.py silently converts float('-inf') to the string "Infinity" instead of "-Infinity". Any LLM output, metric, or metadata field containing negative infinity is sent to the Langfuse server with the wrong sign, causing silent data corruption.

How to trigger

import json
from langfuse._utils.serializer import EventSerializer

s = EventSerializer()
print(s.encode(float('inf')))   # "Infinity"   ✓
print(s.encode(float('-inf')))  # "Infinity"   ✗ — should be "-Infinity"

Root cause

The guard if isinstance(obj, float) and math.isinf(obj): return "Infinity" does not check the sign of the infinite value. math.isinf() returns True for both float('inf') and float('-inf'), so both are mapped to the same positive string.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions