Skip to content

Python SDK: response objects serialize to {} unless you use to_dict() #47

Description

@karamouche

Problem

PreRecordedV2Response (and other SDK response types) are frozen slotted dataclasses. They expose to_dict() / to_json(), not Pydantic’s model_dump().

If you serialize them the usual way (model_dump, .dict(), or json.dumps(..., default=lambda o: o.__dict__)), you get {} even when the job succeeded and utterances are present on the object.

That fails silently: result.id / result.status look fine, but any saved JSON is empty.

Repro (gladiaio-sdk==1.0.5)

import json
from gladiaio_sdk import GladiaClient

result = GladiaClient(api_key="...").prerecorded().transcribe("audio.flac", {
    "diarization": True,
    "language_config": {"languages": ["en"]},
})

assert result.status == "done"
assert result.result.transcription.utterances  # real data

# Broken — common dump pattern
payload = json.loads(
    json.dumps(result, default=lambda o: getattr(o, "__dict__", str(o)))
)
print(payload)  # {}

# Works
print(result.to_dict().keys())  # id, status, result, ...

Root cause: with slots=True, __dict__ is empty ({}), so the JSON fallback writes an empty object.

Expected

Either:

  1. Document clearly that callers must use to_dict() / to_json(), or
  2. Add a model_dump() (and optionally dict()) alias on BaseDataClass that delegates to to_dict(), so Pydantic-style code doesn’t fail silently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions