fix(soniox): keep bracket-prefixed free-form context and move types under llms

Free-form context such as "[inaudible] consultation" is valid Soniox
input, so a string that fails JSON parsing is now forwarded unchanged
instead of returning a 400. The Soniox request types live next to the
provider code.
This commit is contained in:
Dan Lemon 2026-09-10 21:53:51 +02:00
parent fe6d6d9b7e
commit cf33d3f47c
No known key found for this signature in database
GPG key ID: 63D20454AD4DAA0A
3 changed files with 5 additions and 9 deletions

View file

@ -81,10 +81,8 @@ def _decode_form_value(key: str, value: object) -> object:
if key in SONIOX_JSON_PARAMS and value.lstrip()[:1] in ("{", "["):
try:
return _JSON_CONTAINER.validate_json(value)
except ValidationError as exc:
raise SonioxException(
message=f"`{key}` is not valid JSON: {exc.errors()[0]['msg']}", status_code=400, headers=None
)
except ValidationError:
return value
if key == "language_hints":
return tuple(hint.strip() for hint in value.split(",") if hint.strip())
return value

View file

@ -707,11 +707,9 @@ class TestDecodeSonioxFormParams:
assert result["enable_speaker_diarization"] is True
assert result["language_hints"] == ["en", "es"]
def test_should_raise_400_on_malformed_json_context(self):
with pytest.raises(SonioxException) as exc_info:
decode_soniox_form_params({"context": '{"terms": ["Celebrex"'})
assert exc_info.value.status_code == 400
assert "context" in str(exc_info.value)
@pytest.mark.parametrize("raw", ["[inaudible] consultation", "{unbalanced", '{"terms": ["Celebrex"'])
def test_should_keep_bracket_prefixed_free_form_context_as_string(self, raw: str):
assert decode_soniox_form_params({"context": raw})["context"] == raw
def test_should_decode_json_string_translation(self):
result = decode_soniox_form_params({"translation": '{"type": "one_way", "target_language": "es"}'})