Repository navigation
fix(models): skip location-source documents in OpenAIResponsesModel message formatting - #4706
Merged
Merged
Conversation
…essage formatting OpenAIResponsesModel read document source bytes unconditionally, so a document with a location source raised KeyError instead of being skipped with a warning as the other providers do since strands-agents#1572. Gate the message path with the shared _has_location_source check. The tool result path is tracked separately in strands-agents#4018. Fixes strands-agents#4016
liramon2
approved these changes
Sep 29, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Sep 30, 2026
8 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
OpenAIResponsesModelreadsdocument["source"]["bytes"]unconditionally in_format_request_message_content, so a document whose source is a location (for example an S3 URI) raisesKeyError: 'bytes'instead of being skipped with a warning. Every other provider has gated this case since #1572 with the shared_has_location_sourcehelper; the Responses provider never got the gate.This change adds the same check to
_format_request_messages: content blocks with a location source are skipped with the warning "Location sources are not supported by OpenAI Responses | skipping content block", matching the behavior of the other eight providers.Scope note: this PR covers the message path only, as reported in #4016. The tool-result path (
_format_request_tool_message) has the same unguarded read but is tracked separately in #4018 and is not changed here. #3582 widensDocumentSourcefurther (text/content variants), which makes this gate more relevant; it does not overlap with this change.Thanks to @strandly-the-agent for the report.
Related Issues
Fixes #4016
Related: #1572, #4018, #3582
Documentation PR
No documentation changes needed. This brings the provider in line with the behavior the other providers already have.
Type of Change
Bug fix
Testing
Reproduced the issue's script on current main:
KeyError: 'bytes'. With the fix, the location-source document is skipped with a warning and the request formats normally; a document-only message drops out of the input instead of crashing.Added
test_format_request_filters_location_source_documentintests/strands/models/test_openai_responses.py, mirroring the standard test the other providers carry: text content is kept, the location document is filtered, and the warning is logged. The test links the issue.pytest tests/strands/models/test_openai_responses.py: 161 passed.ruff format and ruff check are clean on the changed files. I ran these tools directly (the environment had no hatch); they are the same checks
hatch run preparewraps.I ran
hatch run prepare(ran its equivalent directly: ruff formatter, ruff linter, pytest - see above)Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.