sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[BUG] harness `read` returns an image the model rejects as too large, breaking every later turn

Open strandly-the-agent opened this issue 3 weeks ago • 2 comments

Human Overview

Checks

  • [x] I have updated to the lastest minor and patch version of Strands
  • [x] I have checked the documentation and this is not expected behavior
  • [x] I have searched ./issues and there are no duplicates of my issue

SDK Language

Python and TypeScript (harness read tool in both harness-py and harness-ts)

Strands Version

main plus #5825 (read media validation), both harness packages.

Language Runtime Version

Python 3.13 / Node 22

Operating System

Linux

Installation Method

pip

Steps to Reproduce

  1. Save a valid PNG wider than 8000 px (for example 9000x40), or a valid image over 3.75 MiB, as /tmp/wide.png.
  2. Run create_harness(model="bedrock/global.anthropic.claude-sonnet-4-6") with Use the read tool on /tmp/wide.png and tell me what you see.
  3. Send any follow-up turn, for example Reply with just the word: alive.

Expected Behavior

read does not send an image the model will reject. It returns an error tool result that says why, and the session continues.

Actual Behavior

read returns the image as a success image block. Bedrock rejects the request with ValidationException (At least one of the image dimensions exceed max allowed size, or image exceeds 5 MB maximum). The block stays in agent.messages, so every later turn fails the same way. This is the same history wedge as #5820, for a file that is valid but too large. Reproduced live 5/5 on Sonnet 4.6 and Opus 5.

Possible Solution

Check the image against the model's known limits before returning it, and fail the call when it is over. The limits belong to Claude, not to Bedrock. They were measured live with boundary probes, with the image inside a toolResult:

Model Max raw bytes Max side
Claude on Bedrock (Haiku 4.5, Sonnet 4.6, Opus 5) 3,932,160 (5 MiB base64) 8000 px
Claude on the Anthropic API (Haiku 4.5) 7,864,320 (10 MiB base64) 8000 px
Nova 2 Lite, Llama 4 Maverick (Bedrock) accept 3,932,161 bytes and 8001 px

#5825 rejected a fixed cap because other providers accept larger media, so the limits have to depend on the model. A fix PR will follow.

Additional Context

Follow-up to #5820 / #5825, which list this case as not covered.

Related Issues

#5820, #5825

strandly-the-agent avatar Nov 05 '26 21:11 strandly-the-agent

@strandly-the-agent what does wedging a turn mean

opieter-aws avatar Nov 12 '26 21:11 opieter-aws

@opieter-aws It means the session gets stuck: once one bad turn happens, every turn after it fails too, and retrying doesn't help.

Here, read returns the oversized image as a normal success result, so the image block is saved in agent.messages. Each new turn sends the whole history back to the model, including that block, so Bedrock rejects every request with the same ValidationException. Step 3 of the repro shows it: even Reply with just the word: alive fails. The only ways out are removing that message from the history or starting a new session. That's why the fix needs to stop the image before it gets into the history.

"Wedge" is jargon, so I'll change the title to "…breaking every later turn".

strandly-the-agent avatar Nov 12 '26 21:11 strandly-the-agent