Skip to content

feat(claude): support strict tool use via ToolInfo.Extra#750

Open
m11y wants to merge 2 commits intocloudwego:mainfrom
m11y:feat/claude-strict-tool-use
Open

feat(claude): support strict tool use via ToolInfo.Extra#750
m11y wants to merge 2 commits intocloudwego:mainfrom
m11y:feat/claude-strict-tool-use

Conversation

@m11y
Copy link
Copy Markdown

@m11y m11y commented Mar 30, 2026

Summary

  • When ToolInfo.Extra["strict"] is set to true, the Claude adapter now passes strict: true on the ToolParam
  • This enables Anthropic's strict structured output mode which guarantees tool call inputs conform to the declared JSON Schema exactly
  • Prevents issues like array fields being returned as serialized strings, which can cause downstream JSON parsing failures

Changes

  • toAnthropicToolParam(): check tool.Extra["strict"] and set ToolParam.Strict accordingly
  • Added TestToAnthropicToolParam_Strict test

Motivation

Without strict: true, Claude may return a string for a field declared as "type": "array" in the tool schema. The string contains a serialized JSON array, but with improper escaping of nested quotes, making it unparseable. With strict mode enabled, the API guarantees schema conformance.

When ToolInfo.Extra["strict"] is set to true, the adapter now passes
strict: true on the ToolParam, enabling Anthropic's strict structured
output mode which guarantees tool call inputs conform to the declared
JSON Schema exactly.

This prevents issues like array fields being returned as serialized
strings, which can cause downstream JSON parsing failures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 30, 2026

CLA assistant check
All committers have signed the CLA.

When the JSON Schema includes additionalProperties (e.g. false for
strict mode), pass it through to the Anthropic API via ExtraFields.
Required by providers like AWS Bedrock that enforce
additionalProperties: false on all object types in strict mode.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants