-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix: recurse into object properties in _update_type_string for Anthropic adapter #4469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: recurse into object properties in _update_type_string for Anthropic adapter #4469
Conversation
…pic adapter `_update_type_string` lowercases Gemini-style type strings (e.g. "STRING" -> "string") for Anthropic API compatibility. It already recursed into `items` (arrays) and `items.properties` (arrays of objects), but not into top-level `properties` of object types. This caused tool schemas with nested object parameters (e.g. Pydantic models) to produce invalid JSON Schema with uppercase type strings, resulting in Anthropic API 400 errors. Recurse into `properties` at every level, which also subsumes the existing `items.properties` handling.
|
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. |
Summary of ChangesHello @encounter, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where tool schemas with deeply nested object parameters, particularly when using Pydantic models, caused Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this 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 effectively addresses a bug in the Anthropic adapter where nested object parameters in tool schemas were not being processed correctly. The fix in _update_type_string correctly implements recursion for properties at all levels, which not only solves the issue but also simplifies and generalizes the existing logic. The addition of the function_with_nested_object_parameter test case is excellent, as it thoroughly validates the fix for deeply nested schemas. The changes are clean, correct, and improve the overall robustness of the integration. Great work!
Summary
_update_type_stringlowercases Gemini-style type strings (e.g.STRING→string) for Anthropic API compatibility. It already recursed intoitems(arrays) anditems.properties(arrays of objects), but not into top-levelpropertiesof object types. This caused tool schemas with nested object parameters (e.g. PydanticBaseModelsubclasses used directly as function parameters) to produce invalid JSON Schema with uppercase type strings, resulting in Anthropic API 400 errors:The fix recurses into
propertiesat every level, which also subsumes the existingitems.propertieshandling.Reproduction
Use a Pydantic model with nested objects as a
FunctionToolparameter with theClaudemodel class:Before this fix,
address.cityandaddress.stateretain"STRING"(uppercase) in the schema sent to Anthropic, which rejects it.Test plan
function_with_nested_object_parametertest case totest_function_declaration_to_tool_param— verifies a 3-level deep object schema (parameter → profile → address → city/state) is fully lowercasedtest_anthropic_llm.pycontinue to pass