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
- Upload the file to S3 first and use the resulting s3:// URI: FileReference(file_uri="s3://bucket/key", content_type=...).
- Use a Bedrock-compatible uploader so resolution produces a FileReference with file_uri populated.
- If the file is local/in-memory, resolve it to InlineBytes instead and let the formatter build the bytes block (Bedrock supports inline documents).
- 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
- Use a Bedrock-aware uploader so resolution always yields s3:// URIs.
- When mixing providers, check resolved.file_uri before routing to Bedrock.
- Prefer InlineBytes for Bedrock when the file is already local.
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
- Bedrock does not support URL references - resolve to bytes f
- Gemini requires file_uri for FileReference
- S3 bucket name not configured. Set CREWAI_BEDROCK_S3_BUCKET
- boto3 is required for Bedrock S3 file uploads. Install with:
- aioboto3 is required for async Bedrock S3 file uploads. Inst
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/958beeee038ec3c8.
Report an issue: GitHub.