Skip to content

Fix: Mock provider raises UnknownAttributeError when response_format is passed #342

Open
aoki-ryusei wants to merge 1 commit into
activeagents:mainfrom
aoki-ryusei:fix/mock-provider-response-format-unknown-attribute
Open

Fix: Mock provider raises UnknownAttributeError when response_format is passed #342
aoki-ryusei wants to merge 1 commit into
activeagents:mainfrom
aoki-ryusei:fix/mock-provider-response-format-unknown-attribute

Conversation

@aoki-ryusei

Copy link
Copy Markdown
Contributor

Summary

Fix ActiveModel::UnknownAttributeError raised when response_format is passed to the Mock provider.

Steps to Reproduce

class MockAgent < ApplicationAgent
  generate_with :mock

  # @return [ActiveAgent::Generation]
  def ask
    prompt(
      message: params[:message],
      response_format: :json_object
    )
  end
end

MockAgent.with(message: "What is ActiveAgent?").ask.generate_now

unknown attribute 'response_format' for ActiveAgent::Providers::Mock::Request. (ActiveModel::UnknownAttributeError)
      raise UnknownAttributeError.new(self, name)
      ^^^^^

Problem

The Mock provider documentation states that response_format is "accepted but not validated or enforced", but in practice passing it caused a crash.

The root cause was that Mock::Request had a hardcoded getter method but no attribute :response_format declaration.
When BaseProvider cast the context hash into the request object, ActiveModel tried to call response_format= as a
setter, which didn't exist, and raised the error.

# Before: hardcoded getter only, no setter
def response_format
  { type: "text" }
end

Fix

Add attribute :response_format to Mock::Request and remove the hardcoded getter. The attribute now accepts any value passed in, while mock behavior remains unchanged — no schema validation or structured output is enforced.

How to Verify

Run the reproduction steps above and confirm no error is raised.

… to Mock provider

Mock::Request had a hardcoded `response_format` method that always returned
`{ type: "text" }` but no attribute definition, causing ActiveModel to raise
UnknownAttributeError when the value was assigned during request casting.
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.

1 participant