{"record":{"id":"958beeee038ec3c8","repo":"crewAIInc/crewAI","slug":"bedrock-requires-file-uri-for-filereference-s3-ur","errorCode":null,"errorMessage":"Bedrock requires file_uri for FileReference (S3 URI)","messagePattern":"Bedrock requires file_uri for FileReference \\(S3 URI\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-files/src/crewai_files/formatting/bedrock.py","lineNumber":72,"sourceCode":"        file: FileInput,\n        resolved: ResolvedFileType,\n        name: str | None = None,\n    ) -> dict[str, Any] | None:\n        \"\"\"Format a resolved file into a Bedrock content block.\n\n        Args:\n            file: Original file input with metadata.\n            resolved: Resolved file.\n            name: File name (required for document blocks).\n\n        Returns:\n            Content block dict or None if not supported.\n        \"\"\"\n        content_type = file.content_type\n\n        if isinstance(resolved, FileReference):\n            if not resolved.file_uri:\n                raise ValueError(\"Bedrock requires file_uri for FileReference (S3 URI)\")\n            return self._format_s3_block(content_type, resolved.file_uri, name)\n\n        if isinstance(resolved, InlineBytes):\n            return self._format_bytes_block(content_type, resolved.data, name)\n\n        if isinstance(resolved, InlineBase64):\n            file_bytes = base64.b64decode(resolved.data)\n            return self._format_bytes_block(content_type, file_bytes, name)\n\n        if isinstance(resolved, UrlReference):\n            raise ValueError(\n                \"Bedrock does not support URL references - resolve to bytes first\"\n            )\n\n        raise TypeError(f\"Unexpected resolved type: {type(resolved).__name__}\")\n\n    def _format_s3_block(\n        self,","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-files/src/crewai_files/formatting/bedrock.py#L54-L90","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nref = FileReference(file_id=\"file-abc123\", content_type=\"application/pdf\")  # no file_uri\nblock = bedrock_formatter.format_block(ref)\n\n# after\nref = FileReference(file_uri=\"s3://my-bucket/docs/report.pdf\", content_type=\"application/pdf\")\nblock = bedrock_formatter.format_block(ref)","handlingStrategy":"type-guard","validationCode":"if isinstance(resolved, FileReference) and not resolved.file_uri:\n    raise ValueError(\n        f\"FileReference for '{file.filename}' has no S3 URI; \"\n        \"upload to S3 before using Bedrock\"\n    )","typeGuard":"def is_bedrock_ready(ref: FileReference) -> TypeGuard[FileReference]:\n    return bool(ref.file_uri and ref.file_uri.startswith(\"s3://\"))","tryCatchPattern":"try:\n    block = bedrock_formatter.format_block(resolved)\nexcept ValueError as e:\n    if \"file_uri\" in str(e):\n        resolved = upload_to_s3(resolved)  # then retry format\n    else:\n        raise","preventionTips":["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."],"tags":["bedrock","aws","s3","filereference","formatter"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}