Skip to content

fix(generate_image): use requested output_format for saved filename extension#501

Open
kimnamu wants to merge 1 commit into
strands-agents:mainfrom
kimnamu:fix/generate-image-output-format-extension
Open

fix(generate_image): use requested output_format for saved filename extension#501
kimnamu wants to merge 1 commit into
strands-agents:mainfrom
kimnamu:fix/generate-image-output-format-extension

Conversation

@kimnamu

@kimnamu kimnamu commented Jun 13, 2026

Copy link
Copy Markdown

Thanks to the maintainers for this tool. Small, low-risk fix.

Fixes #500

Problem

generate_image threads output_format (default "jpeg") into the Bedrock request and the returned ToolResult format, but the saved filename is hardcoded .png. A default run writes JPEG bytes into a .png file and reports a .png path that disagrees with "format": "jpeg".

Fix

Derive the saved extension from the existing output_format variable — filling the one place an already-established pattern was missing. No new helper, no behavior change beyond the correct extension.

Before / After

Item Before After
Default run (output_format="jpeg") saved file output/a_cute_robot.png output/a_cute_robot.jpeg
ToolResult format jpeg jpeg (unchanged)
On-disk ext vs reported format ❌ diverge (.png vs jpeg) ✅ match
output_format="png" run .png .png (unchanged)
Public API / parameters / defaults / request body Unchanged
Duplicate-filename increment logic Preserved (correct ext)

Tests

Added 2 cases to tests/test_generate_image.py (reusing existing mocks). Reverting the source makes the jpeg case fail (file saved as .png); restoring makes all 7 pass. ruff format/ruff check clean on changed files.


This contribution was prepared with the help of an AI agent (Claude Code); I reviewed every line, the rationale, and the test results before submitting.

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

…xtension

The saved file extension was hardcoded to .png while the output_format
(default "jpeg") is threaded through both the Bedrock request and the
ToolResult image format. A default run therefore wrote JPEG bytes into a
.png file and reported a .png path that disagreed with the returned
"format": "jpeg". Derive the extension from output_format so the on-disk
filename matches the requested/returned format.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] generate_image saves files with a hardcoded .png extension regardless of output_format

1 participant