fix(audio): return str for response_format="text" instead of a content-dependent type - #288
Open
Kayvan-Zahiri wants to merge 1 commit into
Open
fix(audio): return str for response_format="text" instead of a content-dependent type#288Kayvan-Zahiri wants to merge 1 commit into
Kayvan-Zahiri wants to merge 1 commit into
Conversation
transcriptions.create and translations.create hardcoded cast_to to their response models regardless of response_format. Groq serves response_format="text" as text/plain, so the parser fell back to json.loads() and returned whatever type the transcript happened to parse as: "42" -> int, "true" -> bool, "null" -> None, "[1, 2]" -> list. With _strict_response_validation=True a plain English transcript raised APIResponseValidationError instead. Pick cast_to from response_format, matching openai-python, and widen the declared return to `Transcription | str` / `Translation | str`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DQughgr95y4B9H1jfaQH8o
Kayvan-Zahiri
requested review from
andrewtlw,
cwilmott-groq and
pmichalina-groq
as code owners
September 2, 2026 19:42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
audio.transcriptions.createandaudio.translations.createhardcodecast_to=Transcription/cast_to=Translationregardless ofresponse_format. Groq servesresponse_format="text"astext/plain, so_response.pyfalls back toresponse.json()and returns whatever type the transcript happens to parse as. The return type therefore varies with what the speaker said:With
_strict_response_validation=Truea plain English transcript raisesAPIResponseValidationErrorinstead of returning.The fix picks
cast_tofromresponse_format, the way openai-python does with_get_response_format_type, and widens the declared return toTranscription | str/Translation | str._parseshort-circuits oncast_to == str, so text now returns the exact body in both strict and loose mode.json/verbose_json/ default are unchanged.Added
tests/test_audio_response_format.py: 28 of its 30 cases fail before the patch, all 30 pass after.tests/api_resources/audio/stays at 16 passed / 44 skipped. ruff, mypy and pyright are clean on the changed files.Overloads keyed on
response_formatwould give exact per-format types, but that belongs in the Stainless config rather than a hand patch to generated files.🤖 Generated with Claude Code