Skip to content

fix(bedrock): tolerate null/non-string image_url in Converse content conversion - #55685

Open
MaxFreedomPollard wants to merge 1 commit into
NousResearch:mainfrom
MaxFreedomPollard:fix/bedrock-null-image-url
Open

fix(bedrock): tolerate null/non-string image_url in Converse content conversion#55685
MaxFreedomPollard wants to merge 1 commit into
NousResearch:mainfrom
MaxFreedomPollard:fix/bedrock-null-image-url

Conversation

@MaxFreedomPollard

@MaxFreedomPollard MaxFreedomPollard commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

_convert_content_to_converse (agent/bedrock_adapter.py) reads an image part's url with:

url = image_url.get("url", "") if isinstance(image_url, dict) else ""
if url.startswith("data:"):

The "" default only applies when the url key is missing. When the key is present but its value is None (or any non-string), url becomes that value and url.startswith("data:") raises AttributeError: 'NoneType' object has no attribute 'startswith'. The exception propagates out of convert_messages_to_converse, so the whole user message fails to convert and the turn errors out instead of degrading gracefully.

Reproduction

from agent.bedrock_adapter import _convert_content_to_converse

_convert_content_to_converse([
    {"type": "text", "text": "look"},
    {"type": "image_url", "image_url": {"url": None}},
])
# AttributeError: 'NoneType' object has no attribute 'startswith'

Consistency

The sibling converters already tolerate this. Gemini's _extract_multimodal_parts uses ((item.get("image_url") or {}).get("url") or ""), and Codex's _chat_content_to_responses_parts does if not isinstance(url, str) or not url: continue. Bedrock is the one converter that crashes.

Fix

Resolve the url for both the dict ({"url": ...}) and bare-string forms, then coerce a null/non-string url to an empty string before the data: check. As a side benefit, a bare-string data: url now converts to an image block instead of being silently dropped (the previous else "" discarded it).

Tests

Adds regression tests for the null-url crash, the non-string-url crash, and bare-string data: url conversion. The first two fail with AttributeError before the change and pass after.

Fixes #55686

@MaxFreedomPollard

Copy link
Copy Markdown
Contributor Author

Issue with reproduction: #55686

@alt-glitch alt-glitch added type/bug Something isn't working provider/bedrock AWS Bedrock (boto3, IAM) comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists labels Jun 30, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused Bedrock regression fix. The premise remains valid on current main: agent/bedrock_adapter.py:522-523 can retain None from image_url["url"] and immediately call startswith on it. User content reaches that helper through convert_messages_to_converse at agent/bedrock_adapter.py:641-642.

The proposed isinstance(url, str) guard prevents that failure while retaining the existing data-URL and remote-reference behavior. The added null, non-string, and bare-string data-URL tests exercise the changed branches. The PR is currently reported mergeable by GitHub.

Automated hermes-sweeper review.

@teknium1 teknium1 added the sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform label Jul 15, 2026
@MaxFreedomPollard
MaxFreedomPollard force-pushed the fix/bedrock-null-image-url branch 2 times, most recently from 02a5e93 to 3a90ea9 Compare July 31, 2026 03:57
_convert_content_to_converse read the image url with
image_url.get("url", ""), whose default only applies when the key is
missing. An image_url part whose url is explicitly null (or any
non-string) left url as that value and then called url.startswith(...),
raising AttributeError and aborting conversion of the entire message.

Resolve the url for both the dict ({"url": ...}) and bare-string forms,
then coerce a null/non-string url to an empty string before the data:
check. This mirrors the Gemini and Codex converters, which already
tolerate these shapes, and also lets a bare-string data: url convert to
an image block instead of being dropped.

Adds regression tests for the null url, non-string url, and bare-string
data url cases.
@MaxFreedomPollard
MaxFreedomPollard force-pushed the fix/bedrock-null-image-url branch from 3a90ea9 to 9ff5b8b Compare July 31, 2026 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists provider/bedrock AWS Bedrock (boto3, IAM) sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bedrock Converse conversion crashes (AttributeError) on an image_url part with a null url

3 participants