Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
raise exception when non dict response (#4057)
LawyZheng6358b8b1d726
diff --git a/skyvern/forge/sdk/api/llm/exceptions.py b/skyvern/forge/sdk/api/llm/exceptions.pyindex 7cb6a9e99..3210172a0 100644--- a/skyvern/forge/sdk/api/llm/exceptions.py+++ b/skyvern/forge/sdk/api/llm/exceptions.py@@ -24,6 +24,11 @@ class InvalidLLMResponseFormat(BaseLLMError):super().__init__(f"LLM response content is not a valid JSON: {response}")+class InvalidLLMResponseType(BaseLLMError):+ def __init__(self, response_type: str) -> None:+ super().__init__(f"LLM response content is expected to be a dict, but got {response_type}")++class DuplicateCustomLLMProviderError(BaseLLMError):def __init__(self, llm_key: str) -> None:super().__init__(f"Custom LLMProvider {llm_key} is already registered")diff --git a/skyvern/forge/sdk/api/llm/utils.py b/skyvern/forge/sdk/api/llm/utils.pyindex df293db70..62b9b8489 100644--- a/skyvern/forge/sdk/api/llm/utils.py+++ b/skyvern/forge/sdk/api/llm/utils.py@@ -10,7 +10,7 @@ import structlogfrom skyvern.constants import MAX_IMAGE_MESSAGESfrom skyvern.forge.sdk.api.llm import commentjson-from skyvern.forge.sdk.api.llm.exceptions import EmptyLLMResponseError, InvalidLLMResponseFormat+from skyvern.forge.sdk.api.llm.exceptions import EmptyLLMResponseError, InvalidLLMResponseFormat, InvalidLLMResponseTypeLOG = structlog.get_logger()@@ -155,13 +155,14 @@ def _coerce_response_to_dict(response: Any) -> dict[str, Any]:return first_dictLOG.warning("List response contained no dict entries; returning empty dict")- return {}+ raise InvalidLLMResponseType("list")LOG.warning("Parsed LLM response is not a dict; returning empty dict",response_type=type(response).__name__,)- return {}++ raise InvalidLLMResponseType(type(response).__name__)def parse_api_response(response: litellm.ModelResponse, add_assistant_prefix: bool = False) -> dict[str, Any]: