Skip to content

fix(types): tolerate null end in sentiment analysis results - #269

Draft
mez171 wants to merge 1 commit into
masterfrom
fix/sentiment-null-end
Draft

mez171 wants to merge 1 commit into
masterfrom
fix/sentiment-null-end

Conversation

@mez171

@mez171 mez171 commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

The API can return a sentiment_analysis_results item with "end": null (seen on a Universal-3.5 Pro transcript with speaker labels; same root cause as CSAT-447, where a word got 0/0 timestamps). Sentiment.end is typed int, so Transcript.get_by_id fails to parse the entire transcript:

sentiment_analysis_results.0.end
  Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType]

The SDK already works around the same problem for start (CSAT-250) with a before validator on Word that converts null to 0. This PR extends that validator to end, for both pydantic v1 and v2. Field types are unchanged (end stays int), so this is non-breaking for callers.

A matching API-side fix (stop returning null end) is being done separately in the API repo.

Changes

  • assemblyai/types.py: Word's null-to-0 validator now covers start and end.
  • tests/unit/test_sentiment_analysis.py: add test_sentiment_analysis_null_end, mirroring the existing test_sentiment_analysis_null_start.

Testing

  • pytest tests/unit: 739 passed (the new test fails without the fix).
  • ruff format --check / ruff check with ruff.toml clean on assemblyai/types.py.

🤖 Generated with Claude Code

https://claude.ai/code/session_013m8gQdRBqzz5kme9fBgo63


Generated by Claude Code

The API can return a sentiment item with `"end": null` (e.g. when a word
gets 0/0 timestamps), which makes `Transcript.get_by_id` fail to parse the
whole transcript. Extend the existing `start` null workaround on `Word` to
`end`, converting null to 0.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013m8gQdRBqzz5kme9fBgo63
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants