WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@ussef083
Copy link

@ussef083 ussef083 commented Dec 2, 2025

Background

Anthropic recently introduced new advanced built-in tools and capabilities:
https://www.anthropic.com/engineering/advanced-tool-use

Summary

Manual Verification

Tasks

  • changeset
  • docs
  • review tool regex
  • review tool bm25
  • examples
  • review tool options

Future Work

Related Issues

…ool_search_tool_regex, tool_search_tool_bm25) + new tool parameters (defer_loading, input_examples, allowed_callers)
@ussef083
Copy link
Author

ussef083 commented Dec 2, 2025

@lgrammel I'd really appreciate it if you could review this PR.

ussef083 and others added 2 commits December 3, 2025 11:49
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
canCache: true,
});

const advancedToolFeatures =
Copy link
Contributor

Choose a reason for hiding this comment

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

The strict property from function tools is no longer being passed through to the Anthropic tool definition. This breaks the structured output feature when strict is set on a tool.

View Details
📝 Patch Details
diff --git a/packages/anthropic/src/anthropic-prepare-tools.ts b/packages/anthropic/src/anthropic-prepare-tools.ts
index ddf852bef..d5c8a47f4 100644
--- a/packages/anthropic/src/anthropic-prepare-tools.ts
+++ b/packages/anthropic/src/anthropic-prepare-tools.ts
@@ -68,6 +68,9 @@ export async function prepareTools({
           input_schema: tool.inputSchema,
           cache_control: cacheControl,
           ...advancedToolFeatures,
+          ...(supportsStructuredOutput === true && tool.strict != null
+            ? { strict: tool.strict }
+            : {}),
         });
         break;
       }

Analysis

Missing strict property passthrough in Anthropic tool preparation

What fails: The prepareTools() function in packages/anthropic/src/anthropic-prepare-tools.ts does not pass through the strict property from function tools to the Anthropic tool definition, breaking structured output feature when strict is set.

How to reproduce:

cd packages/anthropic
pnpm test:node -- src/anthropic-prepare-tools.test.ts

The test "should include strict when supportsStructuredOutput is true and strict is true" would fail with:

- Expected: "strict": true
+ Received: (property missing)

What was happening: When refactoring to use getAnthropicAdvancedToolUseFeaturesSupport(), the handling of the strict property was removed. The function only extracted defer_loading, allowed_callers, and input_examples from advancedToolFeatures, but never checked tool.strict.

What should happen: When supportsStructuredOutput is true AND tool.strict is defined, the strict property should be included in the output tool definition, matching the pattern used by other providers (Deepseek, Mistral, OpenAI).

Fix applied: Added conditional spread to include strict property:

...(supportsStructuredOutput === true && tool.strict != null
  ? { strict: tool.strict }
  : {}),

This matches the established pattern across the codebase and ensures structured output mode works correctly with Anthropic models.

Verification: All 177 tests in the anthropic package now pass, including the 3 strict mode tests in anthropic-prepare-tools.test.ts.

@lgrammel
Copy link
Collaborator

lgrammel commented Dec 4, 2025

@ussef083 thanks. i will see if i can get this shipped today. please do not make any more changes to this branch

@lgrammel lgrammel changed the title Feat/anthropic: implement support for advanced tool use features feat(anthropic): advanced tool use Dec 4, 2025
@lgrammel
Copy link
Collaborator

lgrammel commented Dec 4, 2025

I prefer to add individual features (tool example, one search tool, the other search tool, etc) as individual pull requests to more thoroughly test and document them.

@ussef083
Copy link
Author

ussef083 commented Dec 4, 2025

thank you very much , if there is an task i can do, I'm here.

...(supportsStructuredOutput === true && tool.strict != null
? { strict: tool.strict }
: {}),
...advancedToolFeatures,
Copy link
Contributor

@AVtheking AVtheking Dec 4, 2025

Choose a reason for hiding this comment

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

wouldn't this make all tool follow same defer_loading property ? if we gonna go this way then how could we have mix of tools with some being defered and some (could be most used or critical ones) not defered ?

Copy link
Author

Choose a reason for hiding this comment

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

no since advancedToolFeatures returns only the properties specified by the user , as example if defer_loading is not specified, so it won't be there.

Copy link
Contributor

Choose a reason for hiding this comment

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

This would still be specified in provider options right, and that make it applied to all tools then. I mean how could you have mix of tools with some having defer_loading set to true and some with false

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops sorry, providerMetadata is tool property, I missed that, this works then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants