crewAIInc/crewAI · error · ValueError

Bedrock requires file_uri for FileReference (S3 URI)

Error message

Bedrock requires file_uri for FileReference (S3 URI)

What it means

The Bedrock formatter (crewai_files.formatting.bedrock) converts resolved files into Converse API content blocks. When the resolved file is a FileReference, Bedrock can only reference files already stored in S3, so the formatter requires a populated file_uri (an s3:// URI) and raises ValueError if it is empty. A FileReference with no file_uri is unusable for Bedrock.

Source

Thrown at lib/crewai-files/src/crewai_files/formatting/bedrock.py:72

        file: FileInput,
        resolved: ResolvedFileType,
        name: str | None = None,
    ) -> dict[str, Any] | None:
        """Format a resolved file into a Bedrock content block.

        Args:
            file: Original file input with metadata.
            resolved: Resolved file.
            name: File name (required for document blocks).

        Returns:
            Content block dict or None if not supported.
        """
        content_type = file.content_type

        if isinstance(resolved, FileReference):
            if not resolved.file_uri:
                raise ValueError("Bedrock requires file_uri for FileReference (S3 URI)")
            return self._format_s3_block(content_type, resolved.file_uri, name)

        if isinstance(resolved, InlineBytes):
            return self._format_bytes_block(content_type, resolved.data, name)

        if isinstance(resolved, InlineBase64):
            file_bytes = base64.b64decode(resolved.data)
            return self._format_bytes_block(content_type, file_bytes, name)

        if isinstance(resolved, UrlReference):
            raise ValueError(
                "Bedrock does not support URL references - resolve to bytes first"
            )

        raise TypeError(f"Unexpected resolved type: {type(resolved).__name__}")

    def _format_s3_block(
        self,

View on GitHub (pinned to 754d7323be)

Solutions

  1. Upload the file to S3 first and use the resulting s3:// URI: FileReference(file_uri="s3://bucket/key", content_type=...).
  2. Use a Bedrock-compatible uploader so resolution produces a FileReference with file_uri populated.
  3. If the file is local/in-memory, resolve it to InlineBytes instead and let the formatter build the bytes block (Bedrock supports inline documents).
  4. If you only have a file_id from another provider, download/re-read the bytes and pass them inline.

Example fix

# before
ref = FileReference(file_id="file-abc123", content_type="application/pdf")  # no file_uri
block = bedrock_formatter.format_block(ref)

# after
ref = FileReference(file_uri="s3://my-bucket/docs/report.pdf", content_type="application/pdf")
block = bedrock_formatter.format_block(ref)
Defensive patterns

Strategy: type-guard

Validate before calling

if isinstance(resolved, FileReference) and not resolved.file_uri:
    raise ValueError(
        f"FileReference for '{file.filename}' has no S3 URI; "
        "upload to S3 before using Bedrock"
    )

Type guard

def is_bedrock_ready(ref: FileReference) -> TypeGuard[FileReference]:
    return bool(ref.file_uri and ref.file_uri.startswith("s3://"))

Try / catch

try:
    block = bedrock_formatter.format_block(resolved)
except ValueError as e:
    if "file_uri" in str(e):
        resolved = upload_to_s3(resolved)  # then retry format
    else:
        raise

Prevention

When it happens

Trigger: Passing a FileReference whose file_uri is None or "" to BedrockFormatter.format_block()/format_content_block(). This happens when the file was uploaded to a non-S3 destination (e.g. the OpenAI files API) or when a FileReference was constructed manually without setting file_uri, then routed to a Bedrock-backed agent.

Common situations: Mixing providers: file uploaded via an OpenAI-style uploader (yields file_id, not file_uri) but the crew runs on a Bedrock model; manually constructing FileReference(file_id=...) without file_uri; cached FileReference from a previous session that never had an S3 URI.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/958beeee038ec3c8. Report an issue: GitHub.