Skip to content

feat(go/ai): per-tool strict schema control via WithStrict option#5255

Open
Anthony-Bible wants to merge 1 commit intogenkit-ai:mainfrom
Anthony-Bible:feat/per-tool-strict
Open

feat(go/ai): per-tool strict schema control via WithStrict option#5255
Anthony-Bible wants to merge 1 commit intogenkit-ai:mainfrom
Anthony-Bible:feat/per-tool-strict

Conversation

@Anthony-Bible
Copy link
Copy Markdown

@Anthony-Bible Anthony-Bible commented May 7, 2026

Closes #5230

This is backwards compatible so users who don't define strict will be automatically marked as strict (previous behavior). Right now we define a strict parameter in go/ai/gen.go, but it's only used for the anthropic plugin however I believe it sets the foundation to use strict in other providers (I noticed there was a todo for the openai plugin). I've tested locally and it properly sets tools as strict that are marked as strict, tools that are marked as not strict are not strict and tools with no strict field set are still strict

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 7, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added the go label May 7, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a Strict option for tool definitions, allowing users to explicitly control strict schema validation. The implementation includes updates to the ToolDefinition and ToolDef structs, a new WithStrict option, and logic in the Anthropic provider to respect this setting. Feedback from the review suggests refactoring the metadata update logic into a shared helper function to reduce duplication and ensure that the strict flag is correctly persisted in the metadata for dynamic tools created via NewTool and NewMultipartTool.

Comment thread go/ai/tools.go Outdated
Comment thread go/ai/tools.go
Comment thread go/ai/tools.go
@Anthony-Bible Anthony-Bible force-pushed the feat/per-tool-strict branch from e1cb0c3 to f6318d2 Compare May 7, 2026 00:55
Add WithStrict(bool) ToolOption so callers can opt individual tools in
or out of strict schema validation rather than accepting the provider
default. The flag is threaded through DefineTool, NewTool,
DefineMultipartTool, and NewMultipartTool, surfaced on ToolDefinition,
and persisted in action metadata so LookupTool recovers it after a
round-trip through the registry.

In the Anthropic plugin, gate enforceStrictSchema and the
additionalProperties:false injection on the per-tool flag, and only set
ToolParam.Strict when strict is true. Sending strict:false still runs
Anthropic's supported-keywords validator (rejecting e.g.
maxItems/minItems), so omitting the field entirely is what actually
disables validation. Default behavior is unchanged: strict=true for
Anthropic, omitted for vertexai.
@Anthony-Bible Anthony-Bible force-pushed the feat/per-tool-strict branch from f6318d2 to 4a1ac37 Compare May 7, 2026 01:15
@MichaelDoyle MichaelDoyle requested a review from apascal07 May 7, 2026 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow optional strict tool use for anthropic sdk

1 participant