Repository: phidatahq/phidata
File: libs/agno/agno/utils/models/claude.py (Python)

Code before:
                "url": file.url,
            },
            "citations": {"enabled": True},
        }
    # Case 2: Document is a local file path
    elif file.filepath is not None:
        import base64
        from pathlib import Path

        path = Path(file.filepath) if isinstance(file.filepath, str) else file.filepath
        if path.exists() and path.is_file():
            raw_bytes = path.read_bytes()

            # Determine media type
            media_type = file.mime_type
            if media_type is None:
                import mimetypes

                media_type = mimetypes.guess_type(file.filepath)[0] or "application/pdf"

            source_type = mime_mapping.get(media_type, "base64")

            if source_type == "text":
                return {
                    "type": "document",
                    "source": {
                        "type": "text",
                        "media_type": "text/plain",
                        "data": raw_bytes.decode("utf-8", errors="replace"),
                    },
                    "citations": {"enabled": True},
                }
            else:
                return {
                    "type": "document",
                    "source": {
                        "type": "base64",
                        "media_type": media_type,
                        "data": base64.standard_b64encode(raw_bytes).decode("utf-8"),
                    },
                    "citations": {"enabled": True},
                }
        else:
            log_error(f"Document file not found: {file}")
            return None
    # Case 3: Document is bytes content
    elif file.content is not None:
        media_type = file.mime_type or "application/pdf"
        source_type = mime_mapping.get(media_type, "base64")

        if source_type == "text":

Review comment (suggestion):
The Anthropic SDK enforces `media_type: Literal["text/plain"]` for `PlainTextSourceParam` — we cannot pass the original MIME type like "text/csv" here even though the content is CSV. The SDK will reject it.

Code after:
        }
    # Case 2: Document is a local file path
    elif file.filepath is not None:
        import base64
        from pathlib import Path

        path = Path(file.filepath) if isinstance(file.filepath, str) else file.filepath
        if path.exists() and path.is_file():
            raw_bytes = path.read_bytes()

            # Determine media type
            media_type = file.mime_type
            if media_type is None:
                import mimetypes

                media_type = mimetypes.guess_type(file.filepath)[0] or "application/pdf"

            # Map media type to source type, default to "base64" if no mapping exists
            source_type = mime_mapping.get(media_type, "base64")

            if source_type == "text":
                return {
                    "type": "document",
                    "source": {
                        "type": "text",
                        "media_type": "text/plain",
                        "data": raw_bytes.decode("utf-8", errors="replace"),
                    },
                    "citations": {"enabled": True},
                }
            else:
                return {
                    "type": "document",
                    "source": {
                        "type": "base64",
                        "media_type": media_type,
                        "data": base64.standard_b64encode(raw_bytes).decode("utf-8"),
                    },
                    "citations": {"enabled": True},
                }
        else:
            log_error(f"Document file not found: {file}")
            return None
    # Case 3: Document is bytes content
    elif file.content is not None:
        media_type = file.mime_type or "application/pdf"
        # Map media type to source type, default to "base64" if no mapping exists
        source_type = mime_mapping.get(media_type, "base64")

        if source_type == "text":
            return {