BerriAI/litellm · error · ValueError

Error parsing file delete response

Error message

Error parsing file delete response: {e}

What it means

Catch-all wrapper in GoogleAIStudioFilesHandler.transform_delete_file_response. Any exception raised while parsing the delete response — including the 'Failed to delete file: ...' ValueError for non-2xx statuses — is caught, logged with a traceback via verbose_logger.exception, and re-raised as this generic parse error. The original cause is in the '{e}' suffix and the verbose log, not the prefix.

Solutions

  1. Enable verbose logging (litellm.set_verbose=True) — verbose_logger.exception prints the full traceback of the original error before the re-raise
  2. Check str(e) suffix: 'Failed to delete file: ...' means an upstream HTTP error, not a local parse bug
  3. Fix mocks in tests to provide .text, .status_code, and .request.url attributes
  4. If the suffix shows a 404/not-found body, handle it as an idempotent success (see the delete-file error)

Example fix

# before
litellm.delete_file(file_id=fid, custom_llm_provider='gemini', api_key=KEY)
# ValueError: Error parsing file delete response: Failed to delete file: {"error": ...404...}

# after - match the inner cause and treat not-found as deleted
try:
    litellm.delete_file(file_id=fid, custom_llm_provider='gemini', api_key=KEY)
except ValueError as e:
    msg = str(e).lower()
    if 'not found' in msg or '404' in msg:
        pass
    else:
        raise
Defensive patterns

Strategy: try-catch

Try / catch

try:
    litellm.delete_file(file_id=fid, custom_llm_provider='gemini', api_key=KEY)
except ValueError as e:
    inner = str(e)
    # outer wrapper: real cause lives in the suffix after 'Error parsing file delete response: '
    cause = inner.split('Error parsing file delete response: ', 1)[-1]
    handle_delete_failure(cause)

Prevention

When it happens

Trigger: Any non-2xx delete response (the inner ValueError is re-wrapped here); attributes missing on the raw httpx response in mocked/test environments; AttributeError/KeyError while reading raw_response.request.url in the success branch.

Common situations: Test suites passing mock responses that lack .text or .request; production deletes of expired files where the 404 body error gets double-wrapped; debugging confusion because the outer message hides the real status.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/ac67a1a980bda272. Report an issue: GitHub.

Appendix: source

Thrown at litellm/llms/gemini/files/transformation.py:364

        try:
            # Google AI Studio returns {} on successful deletion
            if raw_response.status_code == 200:
                # Extract file ID from the request URL if possible
                file_id = "deleted"
                if hasattr(raw_response, "request") and raw_response.request:
                    url: Final = str(raw_response.request.url)
                    if "/files/" in url:
                        file_id = url.split("/files/")[-1].split("?")[0]
                        # Add the files/ prefix if not present
                        if not file_id.startswith("files/"):
                            file_id = f"files/{file_id}"

                return FileDeleted(id=file_id, deleted=True, object="file")
            else:
                raise ValueError(f"Failed to delete file: {raw_response.text}")
        except Exception as e:
            verbose_logger.exception("Error parsing file delete response: %s", e)
            raise ValueError(f"Error parsing file delete response: {e}")

    def transform_list_files_request(
        self,
        purpose: str | None,
        optional_params: dict,
        litellm_params: dict,
    ) -> tuple[str, dict]:
        raise NotImplementedError("GoogleAIStudioFilesHandler does not support file listing")

    def transform_list_files_response(
        self,
        raw_response: httpx.Response,
        logging_obj: LiteLLMLoggingObj,
        litellm_params: dict,
    ) -> list[OpenAIFileObject]:
        raise NotImplementedError("GoogleAIStudioFilesHandler does not support file listing")

    def transform_file_content_request(

View on GitHub (pinned to 77b7c6c40c)