Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

fix(llm): preserve ModelProviderError status code in Groq ainvoke

VenkateswarluNaginenia223ff289eda
diff --git a/browser_use/llm/groq/chat.py b/browser_use/llm/groq/chat.py
index 84672f410..01858bf86 100644
--- a/browser_use/llm/groq/chat.py
+++ b/browser_use/llm/groq/chat.py
@@ -145,6 +145,10 @@ class ChatGroq(BaseChatModel):
except APIError as e:
raise ModelProviderError(message=e.message, model=self.name) from e
+ except ModelProviderError:
+ # errors we raised ourselves (e.g. from structured-output parsing) already carry the right
+ # status code and message, so let them through instead of re-wrapping with the default status
+ raise
except Exception as e:
raise ModelProviderError(message=str(e), model=self.name) from e
diff --git a/tests/ci/models/test_llm_groq.py b/tests/ci/models/test_llm_groq.py
index 867cc1d0e..2785cb15c 100644
--- a/tests/ci/models/test_llm_groq.py
+++ b/tests/ci/models/test_llm_groq.py
@@ -66,9 +66,13 @@ async def test_tool_calling_model_without_tool_calls_raises():
llm = ChatGroq(model=TOOL_CALLING_MODEL, api_key=TEST_API_KEY)
response = _completion(TOOL_CALLING_MODEL, content=None, tool_arguments=None)
- with pytest.raises(ModelProviderError, match='No tool calls in response'):
+ with pytest.raises(ModelProviderError, match='No tool calls in response') as exc_info:
await _ainvoke(llm, response)
+ # the status code we set must survive `ainvoke`'s outer error handling rather than being
+ # re-wrapped with the default provider status
+ assert exc_info.value.status_code == 500
+
async def test_json_schema_model_parses_content():
"""Models outside ToolCallingModels still read the payload from message content."""