feat(go/ai): per-tool strict schema control via WithStrict option#5255
feat(go/ai): per-tool strict schema control via WithStrict option#5255Anthony-Bible wants to merge 1 commit intogenkit-ai:mainfrom
Conversation
|
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. |
There was a problem hiding this comment.
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.
e1cb0c3 to
f6318d2
Compare
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.
f6318d2 to
4a1ac37
Compare
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 usestrictin 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