{"record":{"id":"1097263e3e233bda","repo":"huggingface/smolagents","slug":"the-space-returned-this-message","errorCode":null,"errorMessage":"The space returned this message: ","messagePattern":"The space returned this message: ","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/smolagents/tools.py","lineNumber":721,"sourceCode":"                    (isinstance(arg, str) and os.path.isfile(arg))\n                    or (isinstance(arg, Path) and arg.exists() and arg.is_file())\n                    or is_http_url_like(arg)\n                ):\n                    arg = handle_file(arg)\n                return arg\n\n            def forward(self, *args, **kwargs):\n                # Preprocess args and kwargs:\n                args = list(args)\n                for i, arg in enumerate(args):\n                    args[i] = self.sanitize_argument_for_prediction(arg)\n                for arg_name, arg in kwargs.items():\n                    kwargs[arg_name] = self.sanitize_argument_for_prediction(arg)\n\n                output = self.client.predict(*args, api_name=self.api_name, **kwargs)\n                if isinstance(output, tuple) or isinstance(output, list):\n                    if isinstance(output[1], str):\n                        raise ValueError(\"The space returned this message: \" + output[1])\n                    output = output[\n                        0\n                    ]  # Sometime the space also returns the generation seed, in which case the result is at index 0\n                IMAGE_EXTENSIONS = [\".png\", \".jpg\", \".jpeg\", \".gif\", \".webp\"]\n                AUDIO_EXTENSIONS = [\".mp3\", \".wav\", \".ogg\", \".m4a\", \".flac\"]\n                if isinstance(output, str) and any([output.endswith(ext) for ext in IMAGE_EXTENSIONS]):\n                    output = AgentImage(output)\n                elif isinstance(output, str) and any([output.endswith(ext) for ext in AUDIO_EXTENSIONS]):\n                    output = AgentAudio(output)\n                return output\n\n        return SpaceToolWrapper(\n            space_id=space_id,\n            name=name,\n            description=description,\n            api_name=api_name,\n            token=token,\n        )","sourceCodeStart":703,"sourceCodeEnd":739,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/tools.py#L703-L739","documentation":"When a Gradio Space endpoint returns a tuple/list whose second element is a string, smolagents treats that string as an error/status message from the Space and raises ValueError with it. Some Spaces signal failures (NSFW filter, rate limit, internal error) in the second tuple slot rather than raising.","triggerScenarios":"Calling a SpaceToolWrapper created via Tool.from_space whose Space returns (result, \"error message\") tuples; queue full, GPU quota exceeded, safety filter triggered, or the Space returns (None, 'Error: ...').","commonSituations":"Using public Spaces that return status strings alongside results; ZeroGPU quota exhaustion; Space's endpoint signature changed so outputs are misaligned with the (result, status) expectation.","solutions":["Wrap the tool call in try/except ValueError and inspect the message; retry after fixing the underlying cause (quota, NSFW flag, Space health)","Open the Space in the browser or test with gradio_client directly to see the raw output and confirm the failure reason","If the Space is healthy and this is a false positive from an extra string output, pick a different api_name or Space revision whose output layout matches"],"exampleFix":"# before\nresult = tool(\"a cat\")\n# after\ntry:\n    result = tool(\"a cat\")\nexcept ValueError as e:\n    # e.g. 'The space returned this message: GPU quota exceeded'\n    logger.warning(\"Space error: %s\", e)\n    time.sleep(30)\n    result = tool(\"a cat\")","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"import time\nfrom smolagents import Tool\n\ndef call_space_tool(tool: Tool, *args, retries: int = 2, **kwargs):\n    for attempt in range(retries + 1):\n        try:\n            return tool(*args, sanitize_inputs_outputs=True, **kwargs)\n        except ValueError as e:\n            if attempt < retries and \"space returned this message\" in str(e).lower():\n                time.sleep(10 * (attempt + 1))\n                continue\n            raise","preventionTips":["Wrap Space-backed tool calls in try/except ValueError; the message carries the Space's own error text","Monitor Space health and ZeroGPU quota before long batch runs","Test the Space with gradio_client directly to distinguish Space failures from smolagents issues"],"tags":["smolagents","gradio","space","remote-error"],"backgroundTag":"remote-service-error","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}