Skip to content

fix(vertex): throw warning when strict: true for vertexAnthropic#13353

Merged
aayush-kapoor merged 5 commits intomainfrom
aayush/strict-tool-vertex
Mar 16, 2026
Merged

fix(vertex): throw warning when strict: true for vertexAnthropic#13353
aayush-kapoor merged 5 commits intomainfrom
aayush/strict-tool-vertex

Conversation

@aayush-kapoor
Copy link
Copy Markdown
Collaborator

@aayush-kapoor aayush-kapoor commented Mar 12, 2026

Background

#13167

When setting strict: true for tools and calling anthropic providers via the google vertex provider, the vertex provider doesn't accept the property strict and if passed - will throw an error that looks like this {"type":"invalid_request_error","message":"tools.0.custom.strict: Extra inputs are not permitted"}

this behaviour needed to be documented via a warning so that users know the difference.

Summary

  • introduced a supportsStrictTools property in both anthropic and the google-vertex provider
  • anthropic sets that value to true by default; google vertex is false
  • theconditional logic for setting strict: true for tools in anthropic provider now no longer depends on the supportsStructuredOutput flag

Manual Verification

repro (run it before and after to observe warning)
import { vertexAnthropic } from '@ai-sdk/google-vertex/anthropic';
import { generateText, tool } from 'ai';
import { z } from 'zod';
import { run } from '../../lib/run';

const conditions = [
  { name: 'sunny', minTemperature: -5, maxTemperature: 35 },
  { name: 'snowy', minTemperature: -10, maxTemperature: 0 },
  { name: 'rainy', minTemperature: 0, maxTemperature: 15 },
  { name: 'cloudy', minTemperature: 5, maxTemperature: 25 },
];

run(async () => {
  const result = await generateText({
    model: vertexAnthropic('claude-sonnet-4-6'),
    maxOutputTokens: 512,
    tools: {
      weather: tool({
        description: 'Get weather by city and unit',
        inputSchema: z.object({
          city: z.string(),
          unit: z.enum(['celsius', 'fahrenheit']),
          daysFromNow: z.number().min(1).default(1),
        }),
        execute: async ({ city }) => {
          const condition =
            conditions[Math.floor(Math.random() * conditions.length)];
          return {
            city,
            condition: condition.name,
            temperature:
              Math.floor(
                Math.random() *
                  (condition.maxTemperature - condition.minTemperature + 1),
              ) + condition.minTemperature,
          };
        },
        strict: true,
      }),
      cityAttractions: tool({
        inputSchema: z.object({ city: z.string() }),
      }),
    },
    prompt:
      'What is the weather in San Francisco and what attractions should I visit?',
  });

  for (const toolCall of result.toolCalls) {
    if (toolCall.dynamic) {
      continue;
    }

    switch (toolCall.toolName) {
      case 'cityAttractions': {
        toolCall.input.city;
        break;
      }

      case 'weather': {
        toolCall.input.city;
        break;
      }
    }
  }

  for (const toolResult of result.toolResults) {
    if (toolResult.dynamic) {
      continue;
    }

    switch (toolResult.toolName) {

      case 'weather': {
        toolResult.input.city; 
        toolResult.output.city; 
        toolResult.output.temperature;
        break;
      }
    }
  }

  console.log(JSON.stringify(result, null, 2));
});

the same code will throw an error if L183 in packages/google-vertex/src/anthropic/google-vertex-anthropic-provider.ts‎ is changed to true (hence the warning)

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

fixes #13167

@tigent tigent bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented maintenance CI, internal documentation, automations, etc provider/anthropic Issues related to the @ai-sdk/anthropic provider provider/google-vertex Issues related to the @ai-sdk/google-vertex provider labels Mar 12, 2026
@aayush-kapoor aayush-kapoor added the backport Admins only: add this label to a pull request in order to backport it to the prior version label Mar 12, 2026
Copy link
Copy Markdown
Collaborator

@lgrammel lgrammel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do any provider docs need to be updated (e.g. add info boxes)?

@aayush-kapoor
Copy link
Copy Markdown
Collaborator Author

aayush-kapoor commented Mar 16, 2026

Do any provider docs need to be updated (e.g. add info boxes)?

just added a small note to the providers that don't support it yet. couldn't find a better place than them other than the tools section within the provider pages

@aayush-kapoor aayush-kapoor enabled auto-merge (squash) March 16, 2026 18:38
@aayush-kapoor aayush-kapoor merged commit f05a40d into main Mar 16, 2026
20 checks passed
@aayush-kapoor aayush-kapoor deleted the aayush/strict-tool-vertex branch March 16, 2026 18:40
vercel-ai-sdk bot pushed a commit that referenced this pull request Mar 16, 2026
)

## Background

#13167 

When setting `strict: true` for tools and calling anthropic providers
via the google vertex provider, the vertex provider doesn't accept the
property `strict` and if passed - will throw an error that looks like
this `{"type":"invalid_request_error","message":"tools.0.custom.strict:
Extra inputs are not permitted"}`

this behaviour needed to be documented via a warning so that users know
the difference.

## Summary

- introduced a `supportsStrictTools` property in both anthropic and the
google-vertex provider
- anthropic sets that value to true by default; google vertex is false
- theconditional logic for setting strict: true for tools in anthropic
provider now no longer depends on the `supportsStructuredOutput` flag

## Manual Verification

<details>
<summary>repro (run it before and after to observe warning)
</summary>

```ts
import { vertexAnthropic } from '@ai-sdk/google-vertex/anthropic';
import { generateText, tool } from 'ai';
import { z } from 'zod';
import { run } from '../../lib/run';

const conditions = [
  { name: 'sunny', minTemperature: -5, maxTemperature: 35 },
  { name: 'snowy', minTemperature: -10, maxTemperature: 0 },
  { name: 'rainy', minTemperature: 0, maxTemperature: 15 },
  { name: 'cloudy', minTemperature: 5, maxTemperature: 25 },
];

run(async () => {
  const result = await generateText({
    model: vertexAnthropic('claude-sonnet-4-6'),
    maxOutputTokens: 512,
    tools: {
      weather: tool({
        description: 'Get weather by city and unit',
        inputSchema: z.object({
          city: z.string(),
          unit: z.enum(['celsius', 'fahrenheit']),
          daysFromNow: z.number().min(1).default(1),
        }),
        execute: async ({ city }) => {
          const condition =
            conditions[Math.floor(Math.random() * conditions.length)];
          return {
            city,
            condition: condition.name,
            temperature:
              Math.floor(
                Math.random() *
                  (condition.maxTemperature - condition.minTemperature + 1),
              ) + condition.minTemperature,
          };
        },
        strict: true,
      }),
      cityAttractions: tool({
        inputSchema: z.object({ city: z.string() }),
      }),
    },
    prompt:
      'What is the weather in San Francisco and what attractions should I visit?',
  });

  for (const toolCall of result.toolCalls) {
    if (toolCall.dynamic) {
      continue;
    }

    switch (toolCall.toolName) {
      case 'cityAttractions': {
        toolCall.input.city;
        break;
      }

      case 'weather': {
        toolCall.input.city;
        break;
      }
    }
  }

  for (const toolResult of result.toolResults) {
    if (toolResult.dynamic) {
      continue;
    }

    switch (toolResult.toolName) {

      case 'weather': {
        toolResult.input.city; 
        toolResult.output.city; 
        toolResult.output.temperature;
        break;
      }
    }
  }

  console.log(JSON.stringify(result, null, 2));
});
```
</details>

the same code will throw an error if L183 in
`packages/google-vertex/src/anthropic/google-vertex-anthropic-provider.ts‎`
is changed to true (hence the warning)

## Checklist

- [x] Tests have been added / updated (for bug fixes / features)
- [ ] Documentation has been added / updated (for bug fixes / features)
- [x] A _patch_ changeset for relevant packages has been added (for bug
fixes / features - run `pnpm changeset` in the project root)
- [x] I have reviewed this pull request (self-review)

## Related Issues

fixes #13167
@vercel-ai-sdk vercel-ai-sdk bot removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label Mar 16, 2026
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Mar 16, 2026

✅ Backport PR created: #13492

vercel-ai-sdk bot added a commit that referenced this pull request Mar 16, 2026
…ropic (#13492)

This is an automated backport of #13353 to the release-v6.0 branch. FYI
@aayush-kapoor

Co-authored-by: Aayush Kapoor <83492835+aayush-kapoor@users.noreply.github.com>
nlaz added a commit to FlatFilers/ai that referenced this pull request Mar 30, 2026
Vertex Anthropic's rawPredict endpoint rejects cache_control on message
content blocks with 400: "cache_control: Extra inputs are not permitted".

Add a supportsCacheControl config flag (mirroring the existing
supportsStrictTools pattern from PR vercel#13353) so the shared Anthropic code
conditionally omits cache_control and emits a warning instead.

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented maintenance CI, internal documentation, automations, etc provider/anthropic Issues related to the @ai-sdk/anthropic provider provider/google-vertex Issues related to the @ai-sdk/google-vertex provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@ai-sdk/google-vertex/anthropic: Ignores strict: true on tools

2 participants