Skip to content

fix(agent): guard against None url in Bedrock image_url conversion - #55699

Open
AlexFucuson9 wants to merge 2 commits into
NousResearch:mainfrom
AlexFucuson9:fix/bedrock-image-url-none
Open

fix(agent): guard against None url in Bedrock image_url conversion#55699
AlexFucuson9 wants to merge 2 commits into
NousResearch:mainfrom
AlexFucuson9:fix/bedrock-image-url-none

Conversation

@AlexFucuson9

Copy link
Copy Markdown
Contributor

Summary

Guard against None url in Bedrock Converse image_url conversion.

Problem (P2 #55686)

When an image_url part has "url": null (Python None), image_url.get("url", "") returns None (not ""), because .get() only uses the default when the key is absent, not when the value is None. This causes url.startswith("data:") to crash with AttributeError: 'NoneType' object has no attribute 'startswith'.

Fix

Use (image_url.get("url") or "") which coalesces None to "".

Changes

  • agent/bedrock_adapter.py: 1 line changed

Fixes #55686

When an image_url part has 'url': null (None), .get('url', '') returns
None (not ''), causing url.startswith('data:') to crash with
AttributeError: 'NoneType' object has no attribute 'startswith'.

Fix: use (x.get('url') or '') which coalesces None to ''.

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

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the focused Bedrock null-handling fix. The current-main premise is valid: agent/bedrock_adapter.py:522-523 can pass a present None URL to startswith.

Problems

  • agent/bedrock_adapter.py:522 coalesces only falsey values. A truthy non-string URL such as 123 still reaches url.startswith(...) at line 523 and raises AttributeError. Linked issue #55686 explicitly covers non-string URLs.
  • No regression tests are included. Existing image conversion coverage at tests/agent/test_bedrock_adapter.py:332-348 covers a valid data URL only.
  • The additional lifecycle hunk at agent/bedrock_adapter.py:1148 still fails if modelLifecycle itself is None, because lifecycle.get(...) is invoked before any container normalization.

Suggested changes

  • Type-check the resolved image URL before calling startswith, and add null and truthy non-string regression cases.
  • If retaining the lifecycle guard, normalize modelLifecycle itself and cover that shape with a model-discovery test.

Automated hermes-sweeper review.

Comment thread agent/bedrock_adapter.py
elif part_type == "image_url":
image_url = part.get("image_url", {})
url = image_url.get("url", "") if isinstance(image_url, dict) else ""
url = (image_url.get("url") or "") if isinstance(image_url, dict) else ""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This coalesces None, but truthy non-string values remain unchanged: {"url": 123} still reaches url.startswith(...) below and raises AttributeError. #55686 explicitly includes non-string URLs; normalize by type before the prefix check and add that regression case.

Comment thread agent/bedrock_adapter.py
# Only include active, streaming-capable, text-output models
lifecycle = summary.get("modelLifecycle", {})
if lifecycle.get("status", "").upper() != "ACTIVE":
if (lifecycle.get("status") or "").upper() != "ACTIVE":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This protects a null status, but not a present modelLifecycle=None: the assignment above leaves lifecycle as None and .get(...) still raises. If this extra hardening remains, normalize the containing lifecycle value as well and add a regression test.

@teknium1 teknium1 added the sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform label Jul 15, 2026
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