Skip to content

fix: make speaker and confidence optional in TranscriptUtterance#12

Open
Odrec wants to merge 2 commits intonamastexlabs:mainfrom
Odrec:fix/optional-confidence-speaker
Open

fix: make speaker and confidence optional in TranscriptUtterance#12
Odrec wants to merge 2 commits intonamastexlabs:mainfrom
Odrec:fix/optional-confidence-speaker

Conversation

@Odrec
Copy link
Copy Markdown
Contributor

@Odrec Odrec commented Feb 11, 2026

fix: make speaker and confidence optional in TranscriptUtterance

Problem

Two runtime errors occur when transcribing without speaker diarization or when word-level timestamps are unavailable:

  1. KeyError: 'confidence' in server.py:190result["confidence"] crashes because format_result() only includes the confidence key when word-level data is available (line 534 in transcriber.py)

  2. ResponseValidationError from Pydantic — TranscriptUtterance declares speaker: str and confidence: float as required fields, but format_result() only adds them conditionally:

    • speaker is only included when diarization is enabled and a speaker is detected (lines 503-504)
    • confidence is only included when word-level data exists (lines 507-510)

Root Cause

The Pydantic model schema doesn't match the actual data produced by the transcription pipeline. When diarization is disabled, segments have no speaker field. When word_timestamps=false, segments have no word-level confidence scores.

Fix

server.py: Use result.get("confidence") instead of result["confidence"] to safely handle missing confidence data.

models.py: Make both fields optional in TranscriptUtterance:

  • speaker: strspeaker: str | None = None
  • confidence: floatconfidence: float | None = None

test_models.py: Added 3 test cases:

  • test_utterance_without_speaker — no diarization
  • test_utterance_without_confidence — no word-level data
  • test_utterance_without_speaker_and_confidence — minimal fields only

Testing

These fixes have been validated end-to-end on a GPU server with both diarization-enabled and diarization-disabled transcription requests.

- server.py: use result.get('confidence') instead of result['confidence']
  to prevent KeyError when word-level data is unavailable
- models.py: make TranscriptUtterance.speaker and .confidence optional
  since format_result() only includes them conditionally (speaker requires
  diarization, confidence requires word-level data)
- test_models.py: add tests for utterances without speaker/confidence
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @Odrec, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses runtime errors caused by a mismatch between the TranscriptUtterance Pydantic model and the data generated by the transcription process. Specifically, it resolves KeyError and ResponseValidationError that occurred when speaker or confidence fields were absent due to disabled diarization or lack of word-level timestamps. The fix involves making these fields optional in the model and safely accessing the confidence field in the server logic, ensuring robust handling of varying transcription outputs.

Highlights

  • Model Schema Update: Updated the TranscriptUtterance Pydantic model to make speaker and confidence fields optional, aligning the schema with the actual data produced by the transcription pipeline.
  • Safe Confidence Access: Modified server.py to use result.get('confidence') for accessing the confidence score, preventing KeyError when word-level data is unavailable.
  • New Test Cases: Added three new test cases in test_models.py to validate TranscriptUtterance behavior when speaker and confidence fields are missing, covering scenarios without diarization or word-level data.
Changelog
  • src/murmurai_server/models.py
    • Made speaker field optional in TranscriptUtterance.
    • Made confidence field optional in TranscriptUtterance.
  • src/murmurai_server/server.py
    • Replaced direct dictionary access result['confidence'] with result.get('confidence') to handle missing keys gracefully.
  • tests/test_models.py
    • Added test_utterance_without_speaker to verify TranscriptUtterance behavior when no speaker information is present.
    • Added test_utterance_without_confidence to verify TranscriptUtterance behavior when no confidence information is present.
    • Added test_utterance_without_speaker_and_confidence to verify TranscriptUtterance behavior with only minimal required fields.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@Odrec Odrec mentioned this pull request Feb 11, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses two runtime errors by making the speaker and confidence fields optional in the TranscriptUtterance model and safely accessing the confidence value. The changes are logical and include corresponding test cases. I've suggested a minor improvement to one of the new tests to make the test suite more robust and clear by ensuring test cases are orthogonal.

Comment thread tests/test_models.py Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

1 participant