Skip to content

fix(models): skip location-source documents in OpenAIResponsesModel message formatting - #4706

Merged
liramon2 merged 1 commit into
strands-agents:mainfrom
charan-rathore:agent-tasks/4016
Sep 29, 2026
Merged

liramon2 merged 1 commit into
strands-agents:mainfrom
charan-rathore:agent-tasks/4016

Conversation

@charan-rathore

Copy link
Copy Markdown
Contributor

Description

OpenAIResponsesModel reads document["source"]["bytes"] unconditionally in _format_request_message_content, so a document whose source is a location (for example an S3 URI) raises KeyError: 'bytes' instead of being skipped with a warning. Every other provider has gated this case since #1572 with the shared _has_location_source helper; 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 widens DocumentSource further (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_document in tests/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 prepare wraps.

  • I ran hatch run prepare (ran its equivalent directly: ruff formatter, ruff linter, pytest - see above)

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…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
@charan-rathore
charan-rathore requested a review from a team as a code owner September 29, 2026 17:53
@github-actions github-actions Bot added bug Something isn't working area-model Related to models or model providers python Pull requests that update python code labels Sep 29, 2026
@github-actions github-actions Bot added complexity/high A touched function exceeds cognitive complexity 25; may be worth splitting size/xs labels Sep 29, 2026
@codecov

codecov Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@liramon2
liramon2 merged commit ec2d410 into strands-agents:main Sep 29, 2026
40 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-model Related to models or model providers bug Something isn't working complexity/high A touched function exceeds cognitive complexity 25; may be worth splitting python Pull requests that update python code size/xs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] OpenAIResponsesModel raises bare KeyError: 'bytes' on location-source documents — the one provider that never got #1572's gate

2 participants