Skip to content

skills-guide file download example: type mismatch breaks file_id extraction #205

Description

@raihanM99

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

  1. 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" }]
)
  1. Run the doc's extract_file_ids exactly as written.
  2. 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:

  1. .type should be consistently a Symbol (or consistently a String) on both the outer and inner result objects, and/or
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions