Skip to content

act() fails with Anthropic models: response wrapped in $PARAMETER_NAME key #1986

@caug-rodriguez

Description

@caug-rodriguez

Description

When using an Anthropic model (e.g., anthropic/claude-sonnet-4-5) as the default model for act(), the response is wrapped in a $PARAMETER_NAME key, causing Zod validation to fail with AI_NoObjectGeneratedError.

Expected behavior

act() should return the response at the top level:

{"elementId": "11-811", "description": "Create Invoice link button", "method": "click", "arguments": [], "twoStep": false}

Actual behavior

Claude wraps the response in a $PARAMETER_NAME key:

{"$PARAMETER_NAME": {"elementId": "11-811", "description": "Create Invoice link button", "method": "click", "arguments": [], "twoStep": false}}

This causes the Zod schema validation to fail because all required fields (elementId, description, method, arguments, twoStep) are undefined at the top level.

Reproduction

const stagehand = new Stagehand({
  env: "BROWSERBASE",
  model: "anthropic/claude-sonnet-4-5",
  modelClientOptions: { apiKey: process.env.ANTHROPIC_API_KEY },
});
await stagehand.init();
// Navigate to any page
await stagehand.act("Click the submit button", { page });
// → throws AI_NoObjectGeneratedError

Environment

  • Stagehand version: 3.2.1
  • AI SDK version: 5.x
  • Anthropic model: claude-sonnet-4-5-20250929
  • The issue does NOT occur with OpenAI models (gpt-4o, gpt-4.1-mini)

Root cause

Claude's tool_use response wraps the output in the tool's parameter name. The AI SDK or Stagehand's response parsing doesn't unwrap this wrapper when using Anthropic models.

From the raw response:

{
  "type": "tool_use",
  "name": "json",
  "input": {
    "$PARAMETER_NAME": {
      "elementId": "11-811",
      ...
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions