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",
...
}
}
}
Description
When using an Anthropic model (e.g.,
anthropic/claude-sonnet-4-5) as the default model foract(), the response is wrapped in a$PARAMETER_NAMEkey, causing Zod validation to fail withAI_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_NAMEkey:{"$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
Environment
Root cause
Claude's
tool_useresponse 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", ... } } }