Skip to content

Commit eba9350

Browse files
committed
fix(llm/clients): do not append 0.21 hint when stream_options guidance fires
1 parent c4e6ab8 commit eba9350

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

nemoguardrails/llm/clients/_errors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ def _classify_bad_request(status_code: int, error_message: str, kwargs: Dict[str
173173
f"{error_message} (set include_usage_in_stream=False on the model "
174174
"or in config.yml parameters to remove this field from streaming requests)"
175175
)
176-
error_message = _maybe_append_migration_hint(error_message)
176+
else:
177+
error_message = _maybe_append_migration_hint(error_message)
177178
return LLMUnsupportedParamsError(status_code, error_message, **kwargs)
178179
return LLMBadRequestError(status_code, error_message, **kwargs)
179180

tests/llm/clients/test_openai_compatible_400_enrichment.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,20 @@ async def test_unrecognized_auth_scheme_no_hint(self):
165165
assert _HINT_FRAGMENT not in exc_info.value.error_message
166166

167167

168+
class TestStreamOptionsRejection:
169+
@pytest.mark.asyncio
170+
async def test_stream_options_rejection_uses_specific_guidance_only(self):
171+
client = make_client()
172+
mock_httpx_post(
173+
client,
174+
[(400, {"error": {"message": "Unrecognized request argument supplied: stream_options"}}, {})],
175+
)
176+
with pytest.raises(LLMUnsupportedParamsError) as exc_info:
177+
await client.chat_completion("gpt-4o", [])
178+
assert "include_usage_in_stream=False" in exc_info.value.error_message
179+
assert _HINT_FRAGMENT not in exc_info.value.error_message
180+
181+
168182
class TestMigrationHintNotAppendedOnUnrelated400:
169183
@pytest.mark.asyncio
170184
async def test_generic_400_no_hint(self):

0 commit comments

Comments
 (0)