diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 6b69a7f748..664f19c0d9 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -1956,7 +1956,7 @@ async def generate_messages( try: openai_payload = convert_anthropic_to_openai_payload(form_data) - except Exception as e: + except (ValueError, NotImplementedError, TypeError, KeyError, AttributeError) as e: log.debug('Anthropic payload conversion failed: %s', e) raise HTTPException(status_code=400, detail=str(e)) diff --git a/backend/open_webui/utils/anthropic.py b/backend/open_webui/utils/anthropic.py index cc5cb32532..e62638fc46 100644 --- a/backend/open_webui/utils/anthropic.py +++ b/backend/open_webui/utils/anthropic.py @@ -99,10 +99,15 @@ def _convert_anthropic_image_source(source: dict) -> str: source_type = source.get('type') if source_type == 'base64': media_type = source.get('media_type', 'image/png') - data = source.get('data', '') + data = source.get('data') + if not data: + raise ValueError('Image source type "base64" is missing required "data" field') return f'data:{media_type};base64,{data}' elif source_type == 'url': - return source.get('url', '') + url = source.get('url') + if not url: + raise ValueError('Image source type "url" is missing required "url" field') + return url raise ValueError(f'Unsupported image source type: {source_type!r}')