Description
The Ruby example in the "Downloading generated files" section of the Skills guide does not work as written. extract_file_ids(response) always returns [], even when the API response clearly contains a generated file.
Docs link: https://platform.claude.com/docs/en/build-with-claude/skills-guide#downloading-generated-files
Steps to reproduce
- Run the documented call:
client = Anthropic::Client.new
response = client.beta.messages.create(
model: "claude-opus-4-8",
max_tokens: 4096,
betas: ["code-execution-2025-08-25", "skills-2025-10-02"],
container: {
skills: [{ type: "anthropic", skill_id: "xlsx", version: "latest" }]
},
messages: [
{ role: "user", content: "Create an Excel file with a simple budget spreadsheet" }
],
tools: [{ type: "code_execution_20250825", name: "code_execution" }]
)
- Run the doc's
extract_file_ids exactly as written.
- Result:
[], even though response.content does contain a bash_code_execution_tool_result block with a file_id inside it.
What I found while debugging
- Top-level filtering works:
item.type == :bash_code_execution_tool_result correctly matches, so item.type is a Symbol here.
- The nested type is different:
content_item.type (i.e. item.content.type) returns the String "bash_code_execution_result", not a Symbol. So the doc's check:
if content_item.type == :bash_code_execution_result
is always false (String vs Symbol), and the .content.each block is never reached, this alone fully explains why extract_file_ids always returns [].
- Separately, even if that comparison is fixed, calling
.content directly on content_item raises NoMethodError. The object's actual class is Anthropic::Models::Beta::BetaBashCodeExecutionToolResultError, which does not expose stdout, return_code, or content methods, despite .to_h showing the underlying hash is a successful result (return_code: 0, populated stdout, and a content array containing the actual file_id).
- The only way I could reliably extract the file_id was converting to a Hash first:
content_item.to_h[:content].pluck(:file_id)
Repro session (irb/pry)
[7] pry(main)> response.content.filter {_1.type == :bash_code_execution_tool_result}
=> [#<Anthropic::Models::Beta::BetaBashCodeExecutionToolResultBlock ...>, #<...>]
[10] pry(main)> response.content.filter {_1.type == :bash_code_execution_tool_result}.last.content
=> #<Anthropic::Models::Beta::BetaBashCodeExecutionToolResultError:0x28d8
{type: "bash_code_execution_result", stdout: "Exported\n", stderr: "",
return_code: 0, content: [{type: "bash_code_execution_output", file_id: "file_011Cc9ujyCbYWSEJrb72Z1Jv"}]}>
[17] pry(main)> ...content.stdout
NoMethodError: undefined method 'stdout' for an instance of Anthropic::Models::Beta::BetaBashCodeExecutionToolResultError
[19] pry(main)> ...content.to_h
=> {type: "bash_code_execution_result", stdout: "Exported\n", stderr: "", return_code: 0,
content: [{type: "bash_code_execution_output", file_id: "file_011Cc9ujyCbYWSEJrb72Z1Jv"}]}
[21] pry(main)> ...content.to_h[:content].pluck(:file_id)
=> ["file_011Cc9ujyCbYWSEJrb72Z1Jv"]
Expected behavior
The documented example should work as-is. Either:
.type should be consistently a Symbol (or consistently a String) on both the outer and inner result objects, and/or
- when the execution actually succeeds, the nested result should deserialize into the correct success variant (exposing
stdout / return_code / content directly), not into BetaBashCodeExecutionToolResultError.
Actual behavior
extract_file_ids always returns [] due to the Symbol/String mismatch.
- Even after fixing the comparison, accessing
.content on the nested object raises NoMethodError; .to_h is required as a workaround.
Environment
- anthropic-sdk-ruby gem version: 1.48.2
- Ruby version: 4.0.3
Description
The Ruby example in the "Downloading generated files" section of the Skills guide does not work as written.
extract_file_ids(response)always returns[], even when the API response clearly contains a generated file.Docs link: https://platform.claude.com/docs/en/build-with-claude/skills-guide#downloading-generated-files
Steps to reproduce
extract_file_idsexactly as written.[], even thoughresponse.contentdoes contain abash_code_execution_tool_resultblock with afile_idinside it.What I found while debugging
item.type == :bash_code_execution_tool_resultcorrectly matches, soitem.typeis a Symbol here.content_item.type(i.e.item.content.type) returns the String"bash_code_execution_result", not a Symbol. So the doc's check:is always
false(String vs Symbol), and the.content.eachblock is never reached, this alone fully explains whyextract_file_idsalways returns[]..contentdirectly oncontent_itemraisesNoMethodError. The object's actual class isAnthropic::Models::Beta::BetaBashCodeExecutionToolResultError, which does not exposestdout,return_code, orcontentmethods, despite.to_hshowing the underlying hash is a successful result (return_code: 0, populatedstdout, and acontentarray containing the actualfile_id).Repro session (irb/pry)
Expected behavior
The documented example should work as-is. Either:
.typeshould be consistently a Symbol (or consistently a String) on both the outer and inner result objects, and/orstdout/return_code/contentdirectly), not intoBetaBashCodeExecutionToolResultError.Actual behavior
extract_file_idsalways returns[]due to the Symbol/String mismatch..contenton the nested object raisesNoMethodError;.to_his required as a workaround.Environment