BerriAI/litellm · error · ValueError

contents of file are None

Error message

contents of file are None

What it means

BedrockJsonlFilesTransformation.transform_openai_file_content_to_bedrock_file_content requires the OpenAI file content; passing None (the parameter default) raises immediately. This helper converts an OpenAI batch JSONL payload into Bedrock's recordId/modelInput JSONL before upload, so a None payload is always a caller bug upstream.

Solutions

  1. Make your loader raise (or return a sentinel you check) instead of silently yielding None
  2. Guard the call: if content is None, fail with your own actionable error naming the missing file
  3. Pass the opened file/tuple from the same code that verified it exists

Example fix

# before
content = load_jsonl(path)  # returns None if file missing
bedrock_str, name = transform.transform_openai_file_content_to_bedrock_file_content(content)

# after
content = load_jsonl(path)
if content is None:
    raise FileNotFoundError(path)
bedrock_str, name = transform.transform_openai_file_content_to_bedrock_file_content(content)
Defensive patterns

Strategy: validation

Validate before calling

def load_jsonl_or_raise(path: str):
    try:
        return open(path, "rb")
    except OSError as e:
        raise FileNotFoundError(f"batch file unavailable: {path}") from e

Type guard

def has_content(payload: object) -> bool:
    return payload is not None

Try / catch

try:
    bedrock_str, object_name = transform.transform_openai_file_content_to_bedrock_file_content(content)
except ValueError as e:
    if str(e) == "contents of file are None":
        raise FileNotFoundError("batch payload never loaded") from e
    raise

Prevention

When it happens

Trigger: Calling the transformation helper with its default argument — e.g. a wrapper that loads file content, swallows the load error, and passes the resulting None; or code paths that call it unconditionally with an optional variable.

Common situations: Loader functions returning None on missing files instead of raising; optional file arguments threaded through to the transform; test scaffolding invoking the helper without arguments.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at litellm/llms/bedrock/files/transformation.py:1329

                headers=raw_response.headers,
            )
        return HttpxBinaryResponseContent(response=raw_response)


class BedrockJsonlFilesTransformation:
    """
    Transforms OpenAI /v1/files/* requests to Bedrock S3 file uploads for batch processing
    """

    def transform_openai_file_content_to_bedrock_file_content(
        self, openai_file_content: FileTypes | None = None
    ) -> tuple[str, str]:
        """
        Transforms OpenAI FileContentRequest to Bedrock S3 file format
        """

        if openai_file_content is None:
            raise ValueError("contents of file are None")
        # Read the content of the file
        file_content: Final = self._get_content_from_openai_file(openai_file_content)

        # Split into lines and parse each line as JSON
        openai_jsonl_content: Final = [json.loads(line) for line in file_content.splitlines() if line.strip()]
        bedrock_jsonl_content = self._transform_openai_jsonl_content_to_bedrock_jsonl_content(openai_jsonl_content)
        bedrock_jsonl_string: Final = "\n".join(json.dumps(item) for item in bedrock_jsonl_content)
        object_name: Final = self._get_s3_object_name(openai_jsonl_content=openai_jsonl_content)
        return bedrock_jsonl_string, object_name

    def _transform_openai_jsonl_content_to_bedrock_jsonl_content(
        self, openai_jsonl_content: Sequence[_OpenAIBatchRecord]
    ):
        """
        Delegate to the main BedrockFilesConfig transformation method
        """
        config: Final = BedrockFilesConfig()
        return config._transform_openai_jsonl_content_to_bedrock_jsonl_content(openai_jsonl_content)

View on GitHub (pinned to 77b7c6c40c)